Skip to content

Commit 39fdb1f

Browse files
Adding/improving some docs, fixing some bugs (CharConv...), Improving
SerializationDebuger (OUT, it shows exceptions...), Improving LogProvider, Refactoring/improivng operators, Logical, Comparasional, adding numeric and logical negation... ConditionalAsigment. Improving some other things...
1 parent 211bae2 commit 39fdb1f

File tree

16 files changed

+279
-230
lines changed

16 files changed

+279
-230
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public void logErr(Object obj, Throwable ex)
3636
{
3737
if (reThrowException)
3838
{
39-
if (ex == null)
40-
throw new RuntimeException(obj.toString());
39+
if (ex == null || ex.getMessage() == null || ex.getMessage().isEmpty())
40+
throw new RuntimeException(String.valueOf(obj));
4141
throw new RuntimeException(ex);
4242
}
4343

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -590,40 +590,42 @@ else if (quote % 2 != 0)
590590
* @param s | CharSequence to search!
591591
* @param oneOf | Characters to find!
592592
*
593-
* @return Index of first found character that is not in object meaning it is not in string nor between '{' or '[' and ']' or '}', otherwise -1!
593+
* @return Index of first character found that is not in object meaning it is not in string nor between '{' or '[' and ']' or '}', otherwise -1!
594594
*
595595
* @since 1.3.0
596596
*/
597597
public static int indexOfNotInObj(CharSequence s, char... oneOf)
598598
{
599-
return indexOfNotInObj(s, true, oneOf);
599+
return indexOfNotInObj(s, 0, s.length(), true, oneOf);
600600
}
601601

602602
/**
603603
* @param s | CharSequence to search!
604+
* @param from | The beginning index, where to start the search (should be 0 in most cases).
605+
* @param to | Ending index of search (exclusive, should be s.length()).
604606
* @param firstIndex | If true, first index will be returned, if false last index will be returned.
605607
* @param oneOf | Characters to find!
606608
*
607-
* @return Index of first found character that is not in object meaning it is not in string nor between '{' or '[' and ']' or '}', otherwise -1!
609+
* @return Index of first character found that is not in object meaning it is not in string nor between '{' or '[' and ']' or '}', otherwise -1!
608610
*
609611
* @since 1.3.5
610612
*/
611-
public static int indexOfNotInObj(CharSequence s, boolean firstIndex, char... oneOf)
613+
public static int indexOfNotInObj(CharSequence s, int from, int to, boolean firstIndex, char... oneOf)
612614
{
613-
int found = -1;
614-
for (int i = 0, brackets = 0, quote = 0, len = s.length(); i < len; i++)
615+
int index = -1;
616+
for (int brackets = 0, quote = 0; from < to; from++)
615617
{
616-
char ch = s.charAt(i);
618+
char ch = s.charAt(from);
617619
if (ch == '"')
618620
quote++;
619621

620622
if (quote % 2 == 0)
621623
{
622624
if (brackets == 0 && /*oneOf.length == 0 ? ch == oneOf[0] :*/ isOneOf(ch, oneOf))
623625
{
624-
found = i;
625626
if (firstIndex)
626-
return found;
627+
return from;
628+
index = from;
627629
}
628630
else if ((ch | ' ') == '{')
629631
brackets++;
@@ -636,7 +638,7 @@ else if ((ch | ' ') == '}')
636638
}
637639
}
638640
}
639-
return found;
641+
return index;
640642
}
641643

642644
/**
@@ -663,8 +665,11 @@ public static int indexOfNotInObj(CharSequence s, CharSequence sequenceToFind)
663665
*/
664666
public static int indexOfNotInObj(CharSequence s, CharSequence sequenceToFind, boolean firstIndex)
665667
{
668+
int len = s.length(), lenToFind = sequenceToFind.length();
669+
if (len < lenToFind)
670+
return -1;
666671
int found = -1;
667-
for (int i = 0, brackets = 0, quote = 0, match = 0, len = s.length(), lenToFind = sequenceToFind.length(); i < len; i++)
672+
for (int i = 0, brackets = 0, quote = 0, match = 0; i < len; i++)
668673
{
669674
char ch = s.charAt(i);
670675
if (ch == '"')
@@ -885,7 +890,7 @@ public static void post(Serializer serializer, HttpURLConnection conn) throws IO
885890

886891
for (Object param : serializer)
887892
{
888-
if (postData.length() != 0)
893+
if (postData.length() != 0)
889894
postData.append('&');
890895
postData.append(URLEncoder.encode(serializer.getParsers().toString(param).toString(), "UTF-8"));
891896
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,18 @@
4444
*/
4545
public class BooleanConverter implements DataConverter
4646
{
47-
public boolean shorten;
47+
protected boolean shorten;
4848

4949
public BooleanConverter()
5050
{
5151
this(true);
5252
}
5353

54+
/**
55+
* @param shorten | If true, shortened format (T/F) will be serialized. If false, true/false will be serialized...
56+
*
57+
* @since 1.3.5
58+
*/
5459
public BooleanConverter(boolean shorten)
5560
{
5661
setShorten(shorten);
@@ -84,11 +89,21 @@ public CharSequence getDescription(ParserRegistry myHomeRegistry, Object obj, Ob
8489
return new StringBuilder().append("Primitive data type: \"").append(obj).append("\" the ").append(obj.getClass().getSimpleName().toLowerCase()).append(" value!");
8590
}
8691

92+
/**
93+
* @return If true, shortened format (T/F) will be serialized. If false, true/false will be serialized...
94+
*
95+
* @since 1.3.5
96+
*/
8797
public boolean isShorten()
8898
{
8999
return shorten;
90100
}
91101

102+
/**
103+
* @param shorten | If true, shortened format (T/F) will be serialized. If false, true/false will be serialized...
104+
*
105+
* @since 1.3.5
106+
*/
92107
public void setShorten(boolean shorten)
93108
{
94109
this.shorten = shorten;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Object parse(ParserRegistry myHomeRegistry, String str, Object... args)
4646
}
4747
catch (Exception e)
4848
{
49-
return str.charAt(0);
49+
return str.charAt(1);
5050
}
5151
return CONTINUE;
5252
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface DataConverter extends DataParser
3131
* @param objToDescribe | Object to generate description for!
3232
* @param argsUsedConvert | Array of arguments that were used for converting described object!
3333
*
34-
* @return Description for object (should not contains endlines)!
34+
* @return Description for object (should not contain endlines)!
3535
*
3636
* @since 1.3.0
3737
*/

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ public Object parse(String str, boolean returnAsStringIfNotFound, Class<?>[] ign
247247
/**
248248
* @param classOfParserToPrecache | Class of parser to precache!
249249
*
250-
* @return Int array of 2 signifying the index of where the parser was inserted in parsing cache and converting cache (index 0 = parsing cache index, index 1 = converting cache index)
250+
* @return Int array of 2 signifying the index of where the parser was inserted in parsing cache and converting cache (index 0 = parsing cache index, index 1 = converting cache index). These 2 values should be the same.
251+
*
252+
* @since 1.3.5
251253
*/
252254
public int[] preCache(Class<? extends DataParser> classOfParserToPrecache)
253255
{
@@ -303,8 +305,8 @@ public void resetCache()
303305
/**
304306
* You can use this to manually set caching arrays. Doing this might give you a solid performance boost when parsing or converting large amount of objects with this registry! But sometimes, this might cause some unexpected behavior especially when you have multiple parsers that are dependent on each other!
305307
*
306-
* @param parsingCache | Array of specific parsing cache to use (it can contains some preached parsers to use preferably). This array is supposed to be as long as this registry!
307-
* @param convertingCache | Array of specific converter cache to use (it can contains some preached converters to use preferably). This array is supposed to be as long as this registry!
308+
* @param parsingCache | Array of specific parsing cache to use (it can contains some preached parsers to use preferably). This array is supposed to be as long as this registry and instances and their indexes (order) in cache should be same as in this registry!
309+
* @param convertingCache | Array of specific converter cache to use (it can contains some preached converters to use preferably). This array is supposed to be as long as this registry and instances and their indexes (order) in cache should be same as in this registry!
308310
*
309311
* @since 1.3.5
310312
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ 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!
262+
* @deprecated THIS IS OBSOLET, SLOW AND NO LONGER NECESSARY BECAUSE {@link NumberConverter#numberOf(CharSequence, char, int, int, int)} CAN DO THE SAME THING MUCH FASTET!
263263
*
264264
* @param num | Number string to format!
265265
*
Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.ugp.serialx.devtools.converters;
1+
package org.ugp.serialx.devtools;
22

33
import java.util.Map;
44
import java.util.TreeMap;
@@ -7,7 +7,6 @@
77
import org.ugp.serialx.converters.DataConverter;
88
import org.ugp.serialx.converters.DataParser;
99
import org.ugp.serialx.converters.DataParser.ParserRegistry;
10-
import org.ugp.serialx.devtools.SerializationDebugger;
1110

1211
/**
1312
* Special {@link ParserRegistry} that keeps track of its actions! Use only for debugging!
@@ -115,13 +114,21 @@ public Object parse(String str, boolean returnAsStringIfNotFound, Class<?>[] ign
115114
DataParser parser = parsingCache[i];
116115
if (parser != null)
117116
{
118-
double t0 = System.nanoTime();
119-
obj = parser.parse(this, str, args);
120-
double t = System.nanoTime();
121-
if (obj != SerializationDebugger.CONTINUE)
117+
try
122118
{
123-
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms (from cache)\n>>\t\"" + str + "\"\t -->\t" + SerializationDebugger.toStringAndCls(obj));
124-
return obj;
119+
double t0 = System.nanoTime();
120+
obj = parser.parse(this, str, args);
121+
double t = System.nanoTime();
122+
if (obj != SerializationDebugger.CONTINUE)
123+
{
124+
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms (from cache)\n>>\t\"" + str + "\"\t -->\t" + SerializationDebugger.toStringAndCls(obj));
125+
return obj;
126+
}
127+
}
128+
catch (Exception ex)
129+
{
130+
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " (from cache)\n>>\t\"" + str + "\"\tthrew\t" + ex);
131+
return null;
125132
}
126133
}
127134
}
@@ -134,15 +141,23 @@ public Object parse(String str, boolean returnAsStringIfNotFound, Class<?>[] ign
134141
if (cls == parser.getClass())
135142
continue registryLoop;
136143

137-
double t0 = System.nanoTime();
138-
obj = parser.parse(this, str, args);
139-
double t = System.nanoTime();
140-
if (obj != SerializationDebugger.CONTINUE)
144+
try
145+
{
146+
double t0 = System.nanoTime();
147+
obj = parser.parse(this, str, args);
148+
double t = System.nanoTime();
149+
if (obj != SerializationDebugger.CONTINUE)
150+
{
151+
if (parsingCache != null && i < parsingCache.length)
152+
parsingCache[i] = parser;
153+
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms\n>>\t\"" + str + "\"\t -->\t" + SerializationDebugger.toStringAndCls(obj));
154+
return obj;
155+
}
156+
}
157+
catch (Exception ex)
141158
{
142-
if (parsingCache != null && i < parsingCache.length)
143-
parsingCache[i] = parser;
144-
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms\n>>\t\"" + str + "\"\t -->\t" + SerializationDebugger.toStringAndCls(obj));
145-
return obj;
159+
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + "\n>>\t\"" + str + "\"\tthrew\t" + ex);
160+
return null;
146161
}
147162
}
148163

0 commit comments

Comments
 (0)