Skip to content

Commit 516e9a8

Browse files
committed
Added readme
1 parent 8c1f3ca commit 516e9a8

File tree

1 file changed

+118
-2
lines changed

1 file changed

+118
-2
lines changed

README.md

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,118 @@
1-
# ModifiableVariable
2-
A Modifiable Variable concept which allows easy runtime modifications on variables
1+
Modifiable variable allows one to set modifications to basic types after or before their values are actually determined. When their actual values are determined and one tries to access the value via getters the original value will be returned in a modified form accordingly.
2+
3+
The best way to present the functionality of this concept is by means of a simple example:
4+
5+
```java
6+
ModifiableInteger i = new ModifiableInteger();
7+
i.setOriginalValue(30);
8+
i.setModification(new AddModification(20));
9+
System.out.println(i.getValue()); // 50
10+
```
11+
12+
In 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.
13+
14+
You can use further modifications to an integer value, for example subtract, xor or shift.
15+
16+
# Modifiable variables in Java
17+
If you use a modifiable variable in your Java code, use the modification factories, e.g.:
18+
```java
19+
VariableModification<Integer> modifier = IntegerModificationFactory.explicitValue(7);
20+
VariableModification<BigInteger> modifier = BigIntegerModificationFactory.add(BigInteger.ONE);
21+
VariableModification<byte[]> modifier = ByteArrayModificationFactory.xor(modification1, 0);
22+
VariableModification<byte[]> modifier = ByteArrayModificationFactory.insert(modification1, 0);
23+
```
24+
25+
# Modifiable variables in XML
26+
Modifiable variables are serializable with JAXB into XML.
27+
```xml
28+
<SomeVariable>
29+
<integerAddModification>
30+
<summand>2000</summand>
31+
</integerAddModification>
32+
</SomeVariable>
33+
34+
```
35+
36+
The following examples should give you a useful list of modifiable variables:
37+
38+
## Integer
39+
- Explicit value:
40+
```xml
41+
<integerExplicitValueModification>
42+
<explicitValue>25872</explicitValue>
43+
</integerExplicitValueModification>
44+
```
45+
46+
- Subtract:
47+
```xml
48+
<integerSubtractModification>
49+
<subtrahend>30959</subtrahend>
50+
</integerSubtractModification>
51+
```
52+
53+
- Add:
54+
```xml
55+
<integerAddModification>
56+
<summand>960</summand>
57+
</integerAddModification>
58+
```
59+
60+
- Right shift:
61+
```xml
62+
<integerShiftRightModification>
63+
<shift>13</shift>
64+
</integerShiftRightModification>
65+
```
66+
67+
- XOR:
68+
```xml
69+
<integerXorModification>
70+
<xor>22061</xor>
71+
</integerXorModification>
72+
```
73+
74+
You can use the same operations for BigInteger data types, for example:
75+
```xml
76+
<bigIntegerAddModification>
77+
<summand>1</summand>
78+
</bigIntegerAddModification>
79+
```
80+
81+
## Byte Arrays
82+
- Explicit value:
83+
```xml
84+
<byteArrayExplicitValueModification>
85+
<explicitValue>
86+
4F 3F 8C FC 17 8E 66 0A 53 DF 4D 4E E9 0B D0 B3
87+
02 79 74 1F 8B 8A F6 D0 1E AC 59 53 7B 87 DE 89
88+
C4 13 28 69 3C 18 F8 3A C7 3E 30 44 C9 61 D4
89+
</explicitValue>
90+
</byteArrayExplicitValueModification>
91+
```
92+
93+
- XOR:
94+
```xml
95+
<byteArrayXorModification>
96+
<xor>11 22</xor>
97+
<startPosition>1</startPosition>
98+
</byteArrayXorModification>
99+
```
100+
Here, we XOR the original value with the xor value, starting with the startPosition:
101+
102+
- Insert:
103+
```xml
104+
<byteArrayInsertModification>
105+
<bytesToInsert>
106+
3D 9F 3B 77 65 03 F9 8A 93 6D 94 CD 7E 4A C5 1B
107+
</bytesToInsert>
108+
<startPosition>0</startPosition>
109+
</byteArrayInsertModification>
110+
```
111+
112+
- Delete:
113+
```xml
114+
<byteArrayDeleteModification>
115+
<count>2</count>
116+
<startPosition>0</startPosition>
117+
</byteArrayDeleteModification>
118+
```

0 commit comments

Comments
 (0)