Skip to content

Commit 11cca2e

Browse files
Add files via upload
1 parent 15210b6 commit 11cca2e

File tree

4 files changed

+185
-19
lines changed

4 files changed

+185
-19
lines changed

Sample Open Source Implementations/head/Bar.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ public final class Bar extends Foo //Sample object that inheres
1111
double d2 = 5;
1212
Object sampleParent;
1313

14-
public Bar(Object... args) {
15-
// TODO Auto-generated constructor stub
16-
}
17-
1814
@Override
1915
public String toString()
2016
{
@@ -56,4 +52,36 @@ public Class<? extends Foo> applicableFor()
5652
return Bar.class;
5753
}
5854
}
55+
56+
public byte getBy0() {
57+
return by0;
58+
}
59+
60+
public void setBy0(byte by0) {
61+
this.by0 = by0;
62+
}
63+
64+
public short getS0() {
65+
return s0;
66+
}
67+
68+
public void setS0(short s0) {
69+
this.s0 = s0;
70+
}
71+
72+
public double getD2() {
73+
return d2;
74+
}
75+
76+
public void setD2(double d2) {
77+
this.d2 = d2;
78+
}
79+
80+
public Object getSampleParent() {
81+
return sampleParent;
82+
}
83+
84+
public void setSampleParent(Object sampleParent) {
85+
this.sampleParent = sampleParent;
86+
}
5987
}

Sample Open Source Implementations/head/Foo.java

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Random;
77
import java.util.concurrent.CopyOnWriteArrayList;
88

9-
import ugp.org.SerialX.Protocols.SerializationProtocol;
9+
import ugp.org.SerialX.protocols.SerializationProtocol;
1010

1111
public class Foo //Sample object
1212
{
@@ -16,15 +16,15 @@ public class Foo //Sample object
1616
char ch = 'l';
1717
String s = "a";
1818
boolean nah = false;
19-
List<Object> l = new CopyOnWriteArrayList<Object>(Arrays.asList(6, 45,464654, 9.9, 56f));
19+
List<Object> l = new CopyOnWriteArrayList<Object>(Arrays.asList(6, 45, 464654, 9.9, 56f));
2020

2121
public Foo()
2222
{
2323
l.add(6);
2424
l.add(9);
2525
l.add(13);
2626
l.add(new Random());
27-
l.add(new ArrayList<>(new ArrayList<>(new ArrayList<>(Arrays.asList(4, 5,6d)))));
27+
l.add(new ArrayList<>(new ArrayList<>(new ArrayList<>(Arrays.asList(4, 5, 6d)))));
2828
}
2929

3030
@Override
@@ -38,8 +38,7 @@ public static class FooProtocol extends SerializationProtocol<Foo> //Protocol to
3838
@Override
3939
public Object[] serialize(Foo object)
4040
{
41-
return new Object[] {}; //Nothing here for now
42-
41+
return new Object[] {object.a, object.b, object.c, object.d, object.f, object.ch, object.s, object.nah, object.l};
4342
}
4443

4544
@SuppressWarnings("unchecked")
@@ -65,5 +64,79 @@ public Class<? extends Foo> applicableFor()
6564
{
6665
return Foo.class;
6766
}
67+
}
68+
69+
public int getA() {
70+
return a;
71+
}
72+
73+
public void setA(int a) {
74+
this.a = a;
75+
}
76+
77+
public int getB() {
78+
return b;
79+
}
80+
81+
public void setB(int b) {
82+
this.b = b;
83+
}
84+
85+
public int getC() {
86+
return c;
87+
}
88+
89+
public void setC(int c) {
90+
this.c = c;
91+
}
92+
93+
public double getD() {
94+
return d;
95+
}
96+
97+
public void setD(double d) {
98+
this.d = d;
99+
}
100+
101+
public float getF() {
102+
return f;
103+
}
104+
105+
public void setF(float f) {
106+
this.f = f;
107+
}
108+
109+
public char getCh() {
110+
return ch;
111+
}
112+
113+
public void setCh(char ch) {
114+
this.ch = ch;
115+
}
116+
117+
public String getS() {
118+
return s;
119+
}
120+
121+
public void setS(String s) {
122+
this.s = s;
123+
}
124+
125+
public boolean isNah() {
126+
return nah;
127+
}
128+
129+
public void setNah(boolean nah) {
130+
this.nah = nah;
131+
}
132+
133+
public List<Object> getL() {
134+
return l;
135+
}
136+
137+
public void setL(List<Object> l) {
138+
this.l = l;
68139
};
140+
141+
public static void a() {};
69142
}

Sample Open Source Implementations/head/Main.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@
88
import java.util.Random;
99
import java.util.concurrent.atomic.AtomicLong;
1010

11-
import com.sun.javafx.css.parser.CSSParser;
12-
1311
import ugp.org.SerialX.Scope;
1412
import ugp.org.SerialX.Serializer;
15-
import ugp.org.SerialX.Protocols.SerializationProtocol;
13+
import ugp.org.SerialX.protocols.SerializationProtocol;
1614

15+
/**
16+
* @author PETO
17+
*/
1718
public class Main
1819
{
19-
public static void main(String[] args)
20+
/**
21+
* {@link ArrayList#listIterator()}
22+
* @param args
23+
* @throws Exception
24+
*/
25+
public static void main(String[] args) throws Exception
2026
{
2127
//Protocol registration
22-
Serializer.PROTOCOL_REGISTRY.addAll(new Bar.BarProtocol(), new Foo.FooProtocol(), new SerializationProtocol<Random>() //Sample custom protocol to serialized Random.
28+
SerializationProtocol.REGISTRY.addAll(new Bar.BarProtocol(), new Foo.FooProtocol(), new SerializationProtocol<Random>() //Sample custom protocol to serialized Random.
2329
{ //Random will be serialized also without protocol via classic Java Base64 because it implements java.io.Serializable!
2430
@Override
2531
public Object[] serialize(Random object)
@@ -50,7 +56,7 @@ public Class<? extends Random> applicableFor()
5056
}
5157
});
5258

53-
File f = new File("./test.srlx");
59+
File f = new File("./test.juss");
5460

5561
//Sample objects
5662
Random r = new Random();
@@ -62,16 +68,18 @@ public Class<? extends Random> applicableFor()
6268
vars.put("yourMom", "is heavier than sun...");
6369
vars.put("num", 6);
6470

71+
int[][] ints = {{1, 2, 3}, {4, 5, 4}, {3, 2, 1}};
72+
6573
Serializer.generateComments = true; //Enabling comment generation
6674

6775
Serializer.globalVariables.put("parent", "father"); //Setting global variables
6876

6977
double t0 = System.nanoTime(); //Invokation of static members of this class (calling method "println" and obtaining "hello" field as argument!
70-
Serializer.SerializeTo(f, vars, "145asaa4144akhdgj31hahaXDDLol", r, list, Serializer.Comment("Size of array"), Serializer.Var("arrSize", list.size()), new Bar(), 1, 2.2, 3, 'A', true, false, null, Serializer.Code("$num"), new Scope(), Serializer.StaticMember(Main.class, "println", Serializer.StaticMember(Main.class, "hello"))); //Saving to file (serializing)
78+
Serializer.SerializeTo(f, vars, "145asaa4144akhdgj31hahaXDDLol", r, list, Serializer.Comment("Size of array"), Serializer.Var("arrSize", list.size()), new Bar(), 1, 2.2, 3, 'A', true, false, null, ints, Serializer.Code("$num"), new Scope(), Serializer.StaticMember(Main.class, "println", Serializer.StaticMember(Main.class, "hello"))); //Saving to file (serializing)
7179
double t = System.nanoTime(); //This will insert an comment Another way to add variable except Map<String, Object> $ is used to obtain value from variable
7280
System.out.println("Write: " + (t-t0)/1000000);
7381

74-
Serializer.PROTOCOL_REGISTRY.setActivityForAll(true); //Enabling all protocols
82+
SerializationProtocol.REGISTRY.setActivityForAll(true); //Enabling all protocols
7583
t0 = System.nanoTime();
7684
Scope scope = Serializer.LoadFrom(f); //Loading scope with variables and values from file!
7785
t = System.nanoTime();
@@ -83,8 +91,7 @@ public Class<? extends Random> applicableFor()
8391
System.out.println(scope.toValList());
8492
}
8593

86-
//We can invoke static things from SerialX!
87-
94+
//We can invoke static things in JUSS!
8895
public static String hello = "Hello world!";
8996

9097
public static void println(String str)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package head;
2+
3+
import java.util.Scanner;
4+
5+
import ugp.org.SerialX.Registry;
6+
import ugp.org.SerialX.converters.DataParser;
7+
import ugp.org.SerialX.converters.NumberConverter;
8+
import ugp.org.SerialX.converters.OperationGroups;
9+
import ugp.org.SerialX.converters.operators.ArithmeticOperators;
10+
11+
/**
12+
* Simple implementation of SerialX latest feature the recursive data parser!
13+
* In this example we will be creating simple evaluator of mathematical expressions!
14+
*
15+
* @since 1.3.0
16+
*/
17+
public class SimpleImplementation
18+
{
19+
static Scanner scIn = new Scanner(System.in);
20+
21+
public static void main(String[] args)
22+
{
23+
/*
24+
* We could easily just use DataParser.REGISTRY but there is tone of stuff we do not need and it will just slow it down!
25+
*/
26+
Registry<DataParser> parsersRequiredToEvaluateMath = new Registry<>(new OperationGroups(), new ArithmeticOperators(), new NumberConverter());
27+
28+
/*
29+
* This is an example of simple custom parser this one will allow us to reuse answers of out previous evaluations!
30+
* We will access this old answer using 'ans' word!
31+
* Old ans must be provided as first one of args!
32+
*/
33+
DataParser ansParser = new DataParser()
34+
{
35+
@Override
36+
public Object parse(Registry<DataParser> myHomeRegistry, String str, Object... args)
37+
{
38+
if (str.equalsIgnoreCase("ans"))
39+
{
40+
if (args.length > 0)
41+
return args[0];
42+
return null;
43+
}
44+
return CONTINUE;
45+
}
46+
};
47+
parsersRequiredToEvaluateMath.add(ansParser);
48+
49+
Object oldAnd = null;
50+
while (true)
51+
{
52+
System.out.println("Please insert your math problem!"); //Ask for input!
53+
String input = scIn.nextLine() ;//Read console input
54+
if (!(input = input.trim()).isEmpty()) //Avoiding empty input!
55+
System.out.println(input + " = " + (oldAnd = DataParser.parseObj(parsersRequiredToEvaluateMath, input, oldAnd))+"\n"); //Parsing input!
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)