@@ -10,35 +10,89 @@ The best way to present the functionality of this concept is by means of a simpl
1010``` java
1111ModifiableInteger i = new ModifiableInteger ();
1212i. setOriginalValue(30 );
13- i. setModification(new AddModification (20 ));
13+ VariableModification<Integer > modifier = IntegerModificationFactory . add(20 );
14+ i. setModification(modifier);
1415System . out. println(i. getValue()); // 50
1516```
1617
1718In this example, we defined a new ModifiableInteger and set its value to 30. Next, we defined a new modification AddModification which simply returns a sum of two integers. We set its value to 20. If we execute the above program, the result 50 is printed.
1819
1920You can use further modifications to an integer value, for example subtract, xor or shift.
2021
21- # Modifiable variables in Java
22- If you use a modifiable variable in your Java code, use the modification factories, for example:
22+ In byte arrays you can use further modifications like shuffling or inserting bytes:
23+
24+ ``` java
25+ ModifiableByteArray ba = new ModifiableByteArray ();
26+ VariableModification<byte[]> modifier = ByteArrayModificationFactory . insert(new byte [] {2 , 3 }, 1 );
27+ ba. setOriginalValue(new byte []{1 , 4 });
28+ ba. setModification(modifier);
29+ System . out. println(ArrayConverter . bytesToHexString(ba)); // 01 02 03 04
30+ ```
31+
32+ # Supported data types
33+ The following modifiable variables are provided in this package with their modifications:
34+ * ModifiableBigInteger: add, explicitValue, shiftLeft, shiftRight, subtract, xor
35+ * ModifiableBoolean: explicitValue, toogle
36+ * ModifiableByteArray: delete, duplicate, explicitValue, insert, suffle, xor
37+ * ModifiableInteger: add, explicitValue, shiftLeft, shiftRight, subtract, xor
38+ * ModifiableLong: add, explicitValue, subtract, xor
39+ * ModifiableByte: add, explicitValue, subtract, xor
40+ * ModifiableString: explicitValue
41+
42+ # Creating modifications
43+ If you use a modifiable variables in your Java code, use the modification factories, for example:
2344``` java
2445VariableModification<Integer > modifier = IntegerModificationFactory . explicitValue(7 );
2546VariableModification<BigInteger > modifier = BigIntegerModificationFactory . add(BigInteger . ONE );
26- VariableModification<byte[]> modifier = ByteArrayModificationFactory . xor(modification, 0 );
27- VariableModification<byte[]> modifier = ByteArrayModificationFactory . insert(modification, 0 );
47+ VariableModification<byte[]> modifier = ByteArrayModificationFactory . xor(new byte [] {2 , 3 }, 0 );
2848```
2949
3050# Modifiable variables in XML
31- Modifiable variables are serializable with JAXB into XML.
51+ Modifiable variables are serializable with JAXB into XML. You can use the following code to do that:
52+
53+ ``` java
54+ ModifiableByteArray mba = new ModifiableByteArray ();
55+ mba. setOriginalValue(new byte []{1 , 2 , 3 });
56+ StringWriter writer = new StringWriter ();
57+
58+ // we have to create a jaxb context a put there all the classes we are going to use for serialization
59+ JAXBContext context = JAXBContext . newInstance(ModifiableByteArray . class, ByteArrayDeleteModification . class,
60+ ByteArrayExplicitValueModification . class, ByteArrayInsertModification . class,
61+ ByteArrayXorModification . class);
62+ Marshaller m = context. createMarshaller();
63+ m. setProperty(Marshaller . JAXB_FORMATTED_OUTPUT , true );
64+
65+ // we marshall the array into xml
66+ m. marshal(mba, writer);
67+ String xmlString = writer. toString();
68+ System . out. println(xmlString);
69+
70+ // we can use the xml to create a modifiable byte array variable again
71+ Unmarshaller um = context. createUnmarshaller();
72+ ModifiableByteArray test = (ModifiableByteArray ) um. unmarshal(new StringReader (xmlString));
73+ System . out. println(ArrayConverter . bytesToHexString(test));
74+ ```
75+
76+ The result of the serialized modifiable byte array looks as follows:
77+
3278``` xml
33- <SomeVariable >
34- <integerAddModification >
35- <summand >2000</summand >
36- </integerAddModification >
37- </SomeVariable >
38-
79+ <modifiableByteArray >
80+ <originalValue >01 02 03</originalValue >
81+ </modifiableByteArray >
3982```
4083
41- The following examples should give you a useful list of modifiable variables:
84+ If you would use modification from the previous example, the result would look as follows:
85+ ``` xml
86+ <modifiableByteArray >
87+ <originalValue >01 02 03</originalValue >
88+ <byteArrayInsertModification >
89+ <bytesToInsert >02 03</bytesToInsert >
90+ <startPosition >1</startPosition >
91+ </byteArrayInsertModification >
92+ </modifiableByteArray >
93+ ```
94+
95+ The following examples should give you a useful list of modifications in modifiable variables:
4296
4397## Integer
4498- Explicit value:
@@ -69,6 +123,13 @@ The following examples should give you a useful list of modifiable variables:
69123 </integerShiftRightModification >
70124```
71125
126+ - Left shift:
127+ ``` xml
128+ <integerShiftLeftModification >
129+ <shift >13</shift >
130+ </integerShiftLeftModification >
131+ ```
132+
72133- XOR:
73134``` xml
74135 <integerXorModification >
@@ -82,15 +143,14 @@ You can use the same operations for BigInteger data types, for example:
82143 <summand >1</summand >
83144 </bigIntegerAddModification >
84145```
146+ ModifiableLong and ModifiableBytes support the following operations: add, explicitValue, subtract, xor
85147
86- ## Byte Arrays
148+ ## Byte Array
87149- Explicit value:
88150``` xml
89151 <byteArrayExplicitValueModification >
90152 <explicitValue >
91- 4F 3F 8C FC 17 8E 66 0A 53 DF 4D 4E E9 0B D0 B3
92- 02 79 74 1F 8B 8A F6 D0 1E AC 59 53 7B 87 DE 89
93- C4 13 28 69 3C 18 F8 3A C7 3E 30 44 C9 61 D4
153+ 4F 3F 8C FC 17 8E 66 0A 53 DF 4D 4E E9 0B D0
94154 </explicitValue >
95155 </byteArrayExplicitValueModification >
96156```
@@ -102,7 +162,6 @@ You can use the same operations for BigInteger data types, for example:
102162 <startPosition >1</startPosition >
103163 </byteArrayXorModification >
104164```
105- Here, we XOR the original value with the xor value, starting with the startPosition:
106165
107166- Insert:
108167``` xml
@@ -121,3 +180,31 @@ Here, we XOR the original value with the xor value, starting with the startPosit
121180 <startPosition >0</startPosition >
122181 </byteArrayDeleteModification >
123182```
183+
184+ - Shuffle:
185+ ``` xml
186+ <byteArrayShuffleModification >
187+ <shuffle >02 03</shuffle >
188+ </byteArrayShuffleModification >
189+ ```
190+
191+ # Boolean
192+ - Explicit value:
193+ ``` xml
194+ <booleanExplicitValueModification >
195+ <explicitValue >true</explicitValue >
196+ </booleanExplicitValueModification >
197+ ```
198+
199+ - Toogle:
200+ ``` xml
201+ <booleanToogleModification />
202+ ```
203+
204+ # String
205+ - Explicit value:
206+ ``` xml
207+ <stringExplicitValueModification >
208+ <explicitValue >abc</explicitValue >
209+ </stringExplicitValueModification >
210+ ```
0 commit comments