Skip to content

Commit 923be43

Browse files
Sample implementation of an interactive modification
1 parent 536f29f commit 923be43

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* ModifiableVariable - A Variable Concept for Runtime Modifications
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.modifiablevariable.biginteger;
10+
11+
import de.rub.nds.modifiablevariable.VariableModification;
12+
import java.math.BigInteger;
13+
import javax.xml.bind.annotation.XmlRootElement;
14+
import javax.xml.bind.annotation.XmlType;
15+
16+
/**
17+
* @author Janis Fliegenschmidt - janis.fliegenschmidt@rub.de
18+
*/
19+
@XmlRootElement
20+
@XmlType(propOrder = {"interactive", "modificationFilter", "postModification"})
21+
public class BigIntegerInteractiveModification extends VariableModification<BigInteger> {
22+
23+
private InteractiveBigIntegerModification modification;
24+
25+
public BigIntegerInteractiveModification() {
26+
this(new InteractiveBigIntegerModification() {
27+
@Override
28+
public BigInteger modify(BigInteger oldVal) {
29+
// Fail fast
30+
throw new UnsupportedOperationException("No interactive modifi"
31+
+ "cation specified.");
32+
}
33+
});
34+
}
35+
36+
protected BigIntegerInteractiveModification(InteractiveBigIntegerModification modification) {
37+
this.modification = modification;
38+
}
39+
40+
@Override
41+
protected BigInteger modifyImplementationHook(final BigInteger input) {
42+
return this.modification.modify(input);
43+
}
44+
45+
public interface InteractiveBigIntegerModification {
46+
47+
BigInteger modify(BigInteger oldVal);
48+
}
49+
}

src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ public static VariableModification<BigInteger> explicitValueFromFile(int value)
8888
return modifications.get(pos);
8989
}
9090

91+
public static VariableModification<BigInteger> interactive() {
92+
return new BigIntegerInteractiveModification(
93+
new BigIntegerInteractiveModification.InteractiveBigIntegerModification() {
94+
@Override
95+
public BigInteger modify(BigInteger oldVal) {
96+
BigInteger result = null;
97+
98+
System.out.println("Enter new value for BigInt (Old value is "
99+
+ oldVal.toString() + "): ");
100+
String input = System.console().readLine().trim();
101+
102+
result = new BigInteger(input);
103+
104+
return result;
105+
}
106+
});
107+
}
108+
91109
public static synchronized List<VariableModification<BigInteger>> modificationsFromFile() {
92110
try {
93111
if (modificationsFromFile == null) {

0 commit comments

Comments
 (0)