Skip to content

Commit 211bae2

Browse files
testing, fixing, jdocking, finilizing
1 parent fc2b9d1 commit 211bae2

File tree

10 files changed

+136
-75
lines changed

10 files changed

+136
-75
lines changed

SerialX-core/src/main/java/org/ugp/serialx/Serializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public Object apply(Object t)
534534
if (t instanceof Serializer)
535535
{
536536
GenericScope<String, ?> srl = ((Scope) t).transform(this);
537-
return new GenericScope<>(srl.variables(), srl.values(), srl.getParent());
537+
return new Scope(srl.variables(), srl.values(), srl.getParent());
538538
}
539539
return t;
540540
}

SerialX-core/src/main/java/org/ugp/serialx/Utils.java

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -223,64 +223,62 @@ public static <T> T Clone(T obj)
223223

224224
/**
225225
* @param obj | Object to clone.
226-
* @param
226+
* @param parsersToUse | Parsers that will be used for cloning...
227227
* @param converterArgs | Argument for {@link DataConverter#objToString(Registry, Object, Object...)}!
228228
* @param parserArgs | Arguments for {@link DataParser#parseObj(Registry, String, boolean, Class[], Object...)}!
229229
*
230230
* @return Cloned object using {@link DataParser}, {@link DataConverter} and {@link SerializationProtocol} or the same object as inserted one if cloning is not possible, for instance when protocol was not found and object is not instance of {@link Cloneable}.
231231
* This clone function will always prioritized the Protocol variation, regular cloning is used only when there is no protocol registered or exception occurs. <br>
232232
* Note: If there are protocols to serialize inserted object and all its sub-objects and variables then this clone will be absolute deep copy, meaning that making any changes to this cloned object or to its variables will not affect original one in any way!
233-
* But keep in mind that this clone is absolute hoverer, based on protocols used, it does not need to be an 100% copy!
233+
* But keep in mind that this clone is absolute hoverer, based on protocols used, it does not need to be an 100% copy! Also note that certain objects such as primitive wrappers ({@link Integer}, {@link Float} etc...) will not be necessarily cloned since cloning them is not reasonable...
234234
*
235235
* @since 1.3.2
236236
*/
237237
@SuppressWarnings("unchecked")
238238
public static <T> T Clone(T obj, Registry<DataParser> parsersToUse, Object[] converterArgs, Object... parserArgs)
239239
{
240240
if (obj == null)
241-
return obj;
242-
else if (obj.getClass() == Byte.class)
243-
return (T) new Byte((byte) obj);
244-
else if (obj.getClass() == Short.class)
245-
return (T) new Short((short) obj);
246-
else if (obj.getClass() == Integer.class)
247-
return (T) new Integer((int) obj);
248-
else if (obj.getClass() == Long.class)
249-
return (T) new Long((long) obj);
250-
else if (obj.getClass() == Float.class)
251-
return (T) new Float((float) obj);
252-
else if (obj.getClass() == Double.class)
253-
return (T) new Double((double) obj);
254-
else if (obj.getClass() == Character.class)
255-
return (T) new Character((char) obj);
256-
else if (obj.getClass() == Boolean.class)
257-
return (T) new Boolean((boolean) obj);
258-
else if (obj.getClass() == String.class)
241+
return null;
242+
if (obj.getClass() == Byte.class)
243+
return (T) (Byte) ((byte) obj); // valueOf call...
244+
if (obj.getClass() == Short.class)
245+
return (T) (Short) ((short) obj);
246+
if (obj.getClass() == Integer.class)
247+
return (T) (Integer) ((int) obj);
248+
if (obj.getClass() == Long.class)
249+
return (T) (Long) ((long) obj);
250+
if (obj.getClass() == Float.class)
251+
return (T) (Float) ((float) obj);
252+
if (obj.getClass() == Double.class)
253+
return (T) (Double) ((double) obj);
254+
if (obj.getClass() == Character.class)
255+
return (T) (Character) ((char) obj);
256+
if (obj.getClass() == Boolean.class)
257+
return (T) (Boolean) ((boolean) obj);
258+
if (obj.getClass() == String.class)
259259
return (T) new String((String) obj);
260-
else
260+
261+
ParserRegistry parsers = parsersToUse instanceof ParserRegistry ? (ParserRegistry) parsersToUse : new ParserRegistry(parsersToUse);
262+
263+
Object cln = parsers.parse(parsers.toString(obj, converterArgs).toString(), parserArgs);
264+
if (cln != null && cln != VOID)
265+
return (T) cln;
266+
267+
if (obj instanceof Cloneable)
261268
{
262-
ParserRegistry parsers = parsersToUse instanceof ParserRegistry ? (ParserRegistry) parsersToUse : new ParserRegistry(parsersToUse);
263-
264-
Object cln = parsers.parse(parsers.toString(obj, converterArgs).toString(), parserArgs);
265-
if (cln != null && cln != VOID)
266-
return (T) cln;
267-
268-
if (obj instanceof Cloneable)
269+
try
269270
{
270-
try
271-
{
272-
Method method = Object.class.getDeclaredMethod("clone");
273-
method.setAccessible(true);
274-
return (T) method.invoke(obj);
275-
}
276-
catch (Exception e)
277-
{
278-
throw new RuntimeException(e);
279-
}
271+
Method method = Object.class.getDeclaredMethod("clone");
272+
method.setAccessible(true);
273+
return (T) method.invoke(obj);
274+
}
275+
catch (Exception e)
276+
{
277+
throw new RuntimeException(e);
280278
}
281-
LogProvider.instance.logErr("Unable to clone " + obj.getClass() + ": " + obj, null);
282-
return obj;
283279
}
280+
LogProvider.instance.logErr("Unable to clone " + obj.getClass() + ": " + obj, null);
281+
return obj;
284282
}
285283

286284
/**

SerialX-core/src/main/java/org/ugp/serialx/converters/NumberConverter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,15 @@ else if (ch != 127 && ch != '+')
259259
}
260260

261261
/**
262+
* @deprecated THIS IS NO LONGER NECESSARY BECAUSE BECAUSE {@link NumberConverter#numberOf(CharSequence, char, int, int, int)} CAN DO THE SAME THING MUCH FASTET!
263+
*
262264
* @param num | Number string to format!
263265
*
264266
* @return Original string with formated sign and deleted '_'!
265267
*
266268
* @since 1.3.0
267269
*/
270+
@Deprecated
268271
public static String normFormatNum(String num)
269272
{
270273
if (num.length() > 2)

SerialX-core/src/main/java/org/ugp/serialx/converters/StringConverter.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class StringConverter implements DataConverter
4343
*
4444
* @since 1.2.0 (moved to {@link StringConverter} since 1.3.0)
4545
*/
46-
public static boolean serializeStringNormally = true; //TODO
46+
protected boolean serializeStringNormally = true;
4747

4848
protected Map<String, String> parsingCache;
4949

@@ -127,6 +127,26 @@ public Map<String, String> getParsingCache()
127127
return parsingCache;
128128
}
129129

130+
/**
131+
* @return Will return value of {@link StringConverter#serializeStringNormally}!
132+
*
133+
* @since 1.3.7 (it was static before = not good)
134+
*/
135+
public boolean isSerializeStringNormally()
136+
{
137+
return serializeStringNormally;
138+
}
139+
140+
/**
141+
* @param serializeStringNormally | Set value of {@link StringConverter#serializeStringNormally}!
142+
*
143+
* @since 1.3.7 (it was static before = not good)
144+
*/
145+
public void setSerializeStringNormally(boolean serializeStringNormally)
146+
{
147+
this.serializeStringNormally = serializeStringNormally;
148+
}
149+
130150
/**
131151
* @param obj | Object to stringify directly.
132152
*

SerialX-core/src/main/java/org/ugp/serialx/protocols/ListProtocol.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @since 1.0.0 and applicable for {@link Collection} since 1.2.2
1313
*/
14-
public class ListProtocol extends SerializationProtocol<Collection<?>>
14+
public class ListProtocol extends SerializationProtocol<Collection<?>>
1515
{
1616
@Override
1717
public Object[] serialize(Collection<?> obj)
@@ -24,7 +24,7 @@ public Collection<?> unserialize(Class<? extends Collection<?>> objectClass, Obj
2424
{
2525
if (objectClass.isInterface())
2626
return new ArrayList<>(Arrays.asList(args));
27-
27+
2828
try
2929
{
3030
return objectClass.getConstructor(Collection.class).newInstance(Arrays.asList(args));

SerialX-json/src/main/java/org/ugp/serialx/json/converters/JsonCharacterConverter.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,52 @@
22

33
import org.ugp.serialx.converters.CharacterConverter;
44

5-
public class JsonCharacterConverter extends CharacterConverter {
6-
5+
/**
6+
* {@link CharacterConverter} modified to match JSON more closely. It will serialize char as {@link String} since JSON does not know char...
7+
*
8+
* @author PETO
9+
*
10+
* @since 1.3.7
11+
*/
12+
public class JsonCharacterConverter extends CharacterConverter
13+
{
714
protected boolean formatAsString;
815

9-
public JsonCharacterConverter(boolean formatAsString) {
10-
setFormatAsString(formatAsString);
16+
/**
17+
* @param formatAsString | If true, character will be serialized in a letter form. Otherwise it will be serialized as ASCII value (int).
18+
*
19+
* @since 1.3.7
20+
*/
21+
public JsonCharacterConverter(boolean formatAsString)
22+
{
23+
setFormatAsString(formatAsString);
1124
}
1225

1326
@Override
1427
public CharSequence toString(ParserRegistry myHomeRegistry, Object obj, Object... args)
1528
{
1629
if (obj instanceof Character)
17-
return isFormatAsString() ? obj.toString() : String.valueOf((int) (char) obj);
30+
return isFormatAsString() ? "\""+obj+"\"" : String.valueOf((int) (char) obj);
1831
return CONTINUE;
1932
}
2033

21-
public boolean isFormatAsString() {
34+
/**
35+
* @return True if character is going to be serialized in a letter form. If false, it will be serialized as ASCII value (int).
36+
*
37+
* @since 1.3.7
38+
*/
39+
public boolean isFormatAsString()
40+
{
2241
return formatAsString;
2342
}
2443

25-
public void setFormatAsString(boolean formatAsString) {
44+
/**
45+
* @param formatAsString | If true, character will be serialized in a letter form. Otherwise it will be serialized as ASCII value (int).
46+
*
47+
* @since 1.3.7
48+
*/
49+
public void setFormatAsString(boolean formatAsString)
50+
{
2651
this.formatAsString = formatAsString;
2752
}
2853
}

SerialX-json/src/main/java/org/ugp/serialx/json/converters/JsonNumberConverter.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22

33
import org.ugp.serialx.converters.NumberConverter;
44

5-
public class JsonNumberConverter extends NumberConverter {
6-
5+
/**
6+
* {@link NumberConverter} modified to match JSON more closely. It will not use Juss number suffixes since JSON does not support them...
7+
*
8+
* @author PETO
9+
*
10+
* @since 1.3.7
11+
*/
12+
public class JsonNumberConverter extends NumberConverter
13+
{
714
@Override
815
public CharSequence toString(ParserRegistry myHomeRegistry, Object obj, Object... args)
916
{

SerialX-juss/src/main/java/org/ugp/serialx/juss/converters/OperationGroups.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public Object parse(ParserRegistry myHomeRegistry, String str, Object... args)
5252
args[2] = runtimeGroupStack;
5353
}
5454
String mark = GROUP_MARK_OP + runtimeGroupStack.size() + GROUP_MARK_CLS;
55-
runtimeGroupStack.put(mark, str.substring(opIndex+1, clsIndex));
55+
runtimeGroupStack.put(mark, str.substring(opIndex+1, clsIndex).trim());
5656

5757
StringBuilder sb = new StringBuilder(str).replace(opIndex, clsIndex+1, mark);
5858
return myHomeRegistry.parse(sb.toString(), args);

SerialX-juss/src/main/java/org/ugp/serialx/juss/converters/VariableConverter.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,40 @@ public Object parse(ParserRegistry myHomeRegistry, String arg, Object... args)
8181
eachVar: for (int i = 0; i < iVal; i++) // Support for assigning multiple vars to the same value... Yea this is not the prettiest code but it does the job and mainly it does it fast so shut up!
8282
{
8383
String var = vars[i];
84-
if (!genericVar && contains(var, ' '))
85-
LogProvider.instance.logErr("Variable name \"" + var + "\" is invalid, blank characters are not allowed!", null);
86-
else if ((op0Index = var.indexOf('.')) > -1)
84+
if (!genericVar)
8785
{
88-
String[] path = splitValues(var, op0Index, 0, 0, new char[0], '.');
89-
int iLast = path.length-1, j = 0;
90-
91-
backlook: do
86+
if (contains(var, ' '))
9287
{
93-
Object sc;
94-
if ((sc = getMemberOperator(scope, path[0])) != VOID) // Attempt to get only when exists...
88+
LogProvider.instance.logErr("Variable name \"" + var + "\" is invalid, blank characters are not allowed!", null);
89+
continue;
90+
}
91+
92+
if ((op0Index = var.indexOf('.')) > -1)
93+
{
94+
String[] path = splitValues(var, op0Index, 0, 0, new char[0], '.');
95+
int iLast = path.length-1, j = 0;
96+
97+
backlook: do
9598
{
96-
for (j = 1; j < iLast; j++) // Subscope/forward lookup (inner path only)...
97-
if ((sc = getMemberOperator(sc, path[j])) == null || sc == VOID)
98-
break backlook;
99-
100-
setMemberOperator(myHomeRegistry, sc, path[iLast], val, genericVar, args);
101-
continue eachVar;
99+
Object sc;
100+
if ((sc = getMemberOperator(scope, path[0])) != VOID) // Attempt to get only when exists...
101+
{
102+
for (j = 1; j < iLast; j++) // Subscope/forward lookup (inner path only)...
103+
if ((sc = getMemberOperator(sc, path[j])) == null || sc == VOID)
104+
break backlook;
105+
106+
setMemberOperator(myHomeRegistry, sc, path[iLast], val, false, args);
107+
continue eachVar;
108+
}
102109
}
110+
while ((scope = scope.getParent()) != null);
111+
112+
LogProvider.instance.logErr("Path \"" + var + "\" cannot be set to \"" + val + "\" because \"" + path[j] + "\" is not a accessible or does not exist!", null);
113+
continue;
103114
}
104-
while ((scope = scope.getParent()) != null);
105-
106-
LogProvider.instance.logErr("Path \"" + var + "\" cannot be set to \"" + val + "\" because \"" + path[j] + "\" is not a accessible or does not exist!", null);
107115
}
108-
else
109-
setMemberOperator(myHomeRegistry, scope, var, val, genericVar, args);
116+
117+
setMemberOperator(myHomeRegistry, scope, var, val, genericVar, args);
110118
}
111119

112120
return getValueModif ? val : VOID;

SerialX-operators/src/main/java/org/ugp/serialx/converters/operators/ArithmeticOperators.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ else if (pow <= Float.MAX_VALUE && pow >= Float.MIN_VALUE && (cof instanceof Flo
335335
else if (cof instanceof Integer || cof2 instanceof Integer)
336336
return (int) pow;
337337
}
338-
return null;
338+
return null;
339339
}
340340

341341
/**

0 commit comments

Comments
 (0)