Skip to content

Commit 33b1bf3

Browse files
committed
added support of payload for JBBPAbstractField, it allows user to save some specific extra data in such objects, JBBPdoesn't use the field
1 parent ab1d870 commit 33b1bf3

19 files changed

+202
-21
lines changed

src/main/java/com/igormaznitsa/jbbp/model/JBBPAbstractArrayField.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public T next() {
9797
return getElementAt(this.index++);
9898
}
9999

100+
@Override
100101
public void remove() {
101102
throw new UnsupportedOperationException("Removing is unsupported here");
102103
}

src/main/java/com/igormaznitsa/jbbp/model/JBBPAbstractField.java

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,71 @@
2020

2121
/**
2222
* The Class is the ancestor for all fields and arrays of fields.
23+
*
2324
* @since 1.0
2425
*/
2526
public abstract class JBBPAbstractField implements Serializable {
26-
private static final long serialVersionUID = 8142829902016660630L;
27-
27+
28+
private static final long serialVersionUID = 6072321795839048728L;
29+
2830
/**
2931
* The Field contains the field name info
3032
*/
3133
protected final JBBPNamedFieldInfo fieldNameInfo;
3234

35+
/**
36+
* The Variable can hold some payload. It is not used by JBBP and can be used
37+
* without restrictions. By default it is null. The Field is not thread safe.
38+
*
39+
* @since 1.2.0
40+
*/
41+
protected Serializable payload;
42+
43+
/**
44+
* Set payload value. The Operation is not thread safe.
45+
*
46+
* @param value payload value, can be null.
47+
* @since 1.2.0
48+
*/
49+
public void setPayload(final Serializable value) {
50+
this.payload = value;
51+
}
52+
53+
/**
54+
* Get payload value saved by user. The Operation is not thread safe.
55+
*
56+
* @return payload value, can be null
57+
* @since 1.2.0
58+
*/
59+
public Serializable getPayload() {
60+
return this.payload;
61+
}
62+
3363
/**
3464
* The Constructor.
35-
* @param namedField the name field info for the field, it can be null.
65+
*
66+
* @param namedField the name field info for the field, it can be null.
3667
*/
37-
public JBBPAbstractField(final JBBPNamedFieldInfo namedField){
68+
public JBBPAbstractField(final JBBPNamedFieldInfo namedField) {
3869
this.fieldNameInfo = namedField;
3970
}
40-
71+
4172
/**
4273
* Get the field name info.
74+
*
4375
* @return the field name info if it is presented, otherwise null
4476
*/
45-
public JBBPNamedFieldInfo getNameInfo(){
77+
public JBBPNamedFieldInfo getNameInfo() {
4678
return this.fieldNameInfo;
4779
}
48-
80+
4981
/**
5082
* Get the field path.
51-
* @return the field path or null if the field doesn't contain any field name info
83+
*
84+
* @return the field path or null if the field doesn't contain any field name
85+
* info
5286
*/
53-
public String getFieldPath(){
87+
public String getFieldPath() {
5488
return this.fieldNameInfo == null ? null : this.fieldNameInfo.getFieldPath();
5589
}
5690

@@ -60,14 +94,15 @@ public String getFieldPath(){
6094
* @return the field name or null if the field doesn't contain any field name
6195
* info
6296
*/
63-
public String getFieldName(){
97+
public String getFieldName() {
6498
return this.fieldNameInfo == null ? null : this.fieldNameInfo.getFieldName();
6599
}
66100

67101
/**
68102
* Get the field type in string representation.
69-
*
70-
* @return the string representation of field type, like 'int', 'long', 'bool [123]'
103+
*
104+
* @return the string representation of field type, like 'int', 'long', 'bool
105+
* [123]'
71106
* @since 1.2.0
72107
*/
73108
public abstract String getTypeAsString();

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayBit.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public int size() {
7676

7777
@Override
7878
public JBBPFieldBit getElementAt(final int index) {
79-
return new JBBPFieldBit(this.fieldNameInfo, this.getAsInt(index), this.bitNumber);
79+
final JBBPFieldBit result = new JBBPFieldBit(this.fieldNameInfo, this.getAsInt(index), this.bitNumber);
80+
result.payload = this.payload;
81+
return result;
8082
}
8183

8284
@Override

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayBoolean.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public int size() {
5555

5656
@Override
5757
public JBBPFieldBoolean getElementAt(final int index) {
58-
return new JBBPFieldBoolean(this.fieldNameInfo, getAsBool(index));
58+
final JBBPFieldBoolean result = new JBBPFieldBoolean(this.fieldNameInfo, getAsBool(index));
59+
result.payload = this.payload;
60+
return result;
5961
}
6062

6163
@Override

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayByte.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public int size() {
4848

4949
@Override
5050
public JBBPFieldByte getElementAt(final int index) {
51-
return new JBBPFieldByte(this.fieldNameInfo, this.array[index]);
51+
final JBBPFieldByte result = new JBBPFieldByte(this.fieldNameInfo, this.array[index]);
52+
result.payload = this.payload;
53+
return result;
5254
}
5355

5456
@Override

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayInt.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public int size() {
5555

5656
@Override
5757
public JBBPFieldInt getElementAt(final int index) {
58-
return new JBBPFieldInt(this.fieldNameInfo, this.array[index]);
58+
final JBBPFieldInt result = new JBBPFieldInt(this.fieldNameInfo, this.array[index]);
59+
result.payload = this.payload;
60+
return result;
5961
}
6062

6163
@Override

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayLong.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public int size() {
5555

5656
@Override
5757
public JBBPFieldLong getElementAt(final int index) {
58-
return new JBBPFieldLong(this.fieldNameInfo, this.array[index]);
58+
final JBBPFieldLong result = new JBBPFieldLong(this.fieldNameInfo, this.array[index]);
59+
result.payload = this.payload;
60+
return result;
5961
}
6062

6163
@Override

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayShort.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public int size() {
5555

5656
@Override
5757
public JBBPFieldShort getElementAt(final int index) {
58-
return new JBBPFieldShort(this.fieldNameInfo, this.array[index]);
58+
final JBBPFieldShort result = new JBBPFieldShort(this.fieldNameInfo, this.array[index]);
59+
result.payload = this.payload;
60+
return result;
5961
}
6062

6163
@Override

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayUByte.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public int size() {
4848

4949
@Override
5050
public JBBPFieldUByte getElementAt(final int index) {
51-
return new JBBPFieldUByte(this.fieldNameInfo, this.array[index]);
51+
final JBBPFieldUByte result = new JBBPFieldUByte(this.fieldNameInfo, this.array[index]);
52+
result.payload = this.payload;
53+
return result;
5254
}
5355

5456
@Override

src/main/java/com/igormaznitsa/jbbp/model/JBBPFieldArrayUShort.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public int size() {
5555

5656
@Override
5757
public JBBPFieldUShort getElementAt(final int index) {
58-
return new JBBPFieldUShort(this.fieldNameInfo, this.array[index]);
58+
final JBBPFieldUShort result = new JBBPFieldUShort(this.fieldNameInfo, this.array[index]);
59+
result.payload = this.payload;
60+
return result;
5961
}
6062

6163
@Override

0 commit comments

Comments
 (0)