-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFoo.java
More file actions
142 lines (114 loc) · 2.55 KB
/
Foo.java
File metadata and controls
142 lines (114 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package examples;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;
import org.ugp.serialx.protocols.SerializationProtocol;
public class Foo //Sample object to be serialized using its protocol!
{
int a = 8, b = 1, c = 456;
double d = 5;
float f = 1453.364564564132454654511324f;
char ch = 'l';
String s = "a";
boolean nah = false;
List<Object> l = new CopyOnWriteArrayList<Object>(Arrays.asList(6, 45, 464654, 9.9, 56f));
public Foo()
{
l.add(6);
l.add(9);
l.add(13);
l.add(new Random());
l.add(new ArrayList<>(Arrays.asList(4, 5, 6d, new ArrayList<>(), "hi")));
}
@Override
public String toString()
{
return "Foo[" + a + " " + b + " " + c + " " + d + " " + f + " " + ch + " " + s + " " + nah + " " + l + "]";
}
public static class FooProtocol extends SerializationProtocol<Foo> //Protocol to serialize Foo
{
@Override
public Object[] serialize(Foo object)
{
return new Object[] {object.a, object.b, object.c, object.d, object.f, object.ch, object.s, object.nah, object.l};
}
@SuppressWarnings("unchecked")
@Override
public Foo unserialize(Class<? extends Foo> objectClass, Object... args)
{
Foo f = new Foo();
f.a = (int) args[0];
f.b = (int) args[1];
f.c = (int) args[2];
f.d = (double) args[3];
f.f = (float) args[4];
f.ch = (char) args[5];
f.s = (String) args[6];
f.nah = (boolean) args[7];
f.l = (List<Object>) args[8];
return f;
}
@Override
public Class<? extends Foo> applicableFor()
{
return Foo.class;
}
}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public int getB() {
return b;
}
public void setB(int b) {
this.b = b;
}
public int getC() {
return c;
}
public void setC(int c) {
this.c = c;
}
public double getD() {
return d;
}
public void setD(double d) {
this.d = d;
}
public float getF() {
return f;
}
public void setF(float f) {
this.f = f;
}
public char getCh() {
return ch;
}
public void setCh(char ch) {
this.ch = ch;
}
public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public boolean isNah() {
return nah;
}
public void setNah(boolean nah) {
this.nah = nah;
}
public List<Object> getL() {
return l;
}
public void setL(List<Object> l) {
this.l = l;
};
public static void a() {};
}