Skip to content

Commit dce815d

Browse files
finally finsihing refactor of operators AritOprs and LogiOpers,
reverting mistake with debug try catch, optimizing some stuff...
1 parent 7cce36b commit dce815d

File tree

7 files changed

+225
-211
lines changed

7 files changed

+225
-211
lines changed

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -596,23 +596,23 @@ else if (quote % 2 != 0)
596596
*/
597597
public static int indexOfNotInObj(CharSequence s, char... oneOf)
598598
{
599-
return indexOfNotInObj(s, 0, s.length(), true, oneOf);
599+
return indexOfNotInObj(s, 0, s.length(), -1, true, oneOf);
600600
}
601601

602602
/**
603603
* @param s | CharSequence to search!
604604
* @param from | The beginning index, where to start the search (should be 0 in most cases).
605605
* @param to | Ending index of search (exclusive, should be s.length()).
606+
* @param defaultReturn | Index to return by default (usually -1).
606607
* @param firstIndex | If true, first index will be returned, if false last index will be returned.
607608
* @param oneOf | Characters to find!
608609
*
609610
* @return Index of first character found that is not in object meaning it is not in string nor between '{' or '[' and ']' or '}', otherwise -1!
610611
*
611612
* @since 1.3.5
612613
*/
613-
public static int indexOfNotInObj(CharSequence s, int from, int to, boolean firstIndex, char... oneOf)
614+
public static int indexOfNotInObj(CharSequence s, int from, int to, int defaultReturn, boolean firstIndex, char... oneOf)
614615
{
615-
int index = -1;
616616
for (int brackets = 0, quote = 0; from < to; from++)
617617
{
618618
char ch = s.charAt(from);
@@ -625,7 +625,7 @@ public static int indexOfNotInObj(CharSequence s, int from, int to, boolean firs
625625
{
626626
if (firstIndex)
627627
return from;
628-
index = from;
628+
defaultReturn = from;
629629
}
630630
else if ((ch | ' ') == '{')
631631
brackets++;
@@ -638,7 +638,7 @@ else if ((ch | ' ') == '}')
638638
}
639639
}
640640
}
641-
return index;
641+
return defaultReturn;
642642
}
643643

644644
/**
@@ -714,23 +714,24 @@ else if ((ch | ' ') == '}')
714714
*/
715715
public static String fastReplace(String str, String target, CharSequence replacement)
716716
{
717-
int targetLength = target.length();
718-
if (targetLength == 0)
719-
return str;
720-
721-
int i1 = 0, i2 = str.indexOf(target);
722-
if (i2 < 0)
723-
return str;
724-
725-
StringBuilder sb = new StringBuilder(targetLength > replacement.length() ? str.length() : str.length() * 2);
726-
do
727-
{
728-
sb.append(str, i1, i2).append(replacement);
729-
i1 = i2 + targetLength;
730-
i2 = str.indexOf(target, i1);
731-
} while (i2 > 0);
732-
733-
return sb.append(str, i1, str.length()).toString();
717+
int targetLength = target.length();
718+
if (targetLength == 0)
719+
return str;
720+
721+
int i1 = 0, i2 = str.indexOf(target);
722+
if (i2 < 0)
723+
return str;
724+
725+
int len = str.length();
726+
StringBuilder sb = new StringBuilder(targetLength > replacement.length() ? len : len * 2);
727+
do
728+
{
729+
sb.append(str, i1, i2).append(replacement);
730+
i1 = i2 + targetLength;
731+
i2 = str.indexOf(target, i1);
732+
} while (i2 > 0);
733+
734+
return sb.append(str, i1, len).toString();
734735
}
735736

736737
/**
@@ -797,14 +798,14 @@ public static boolean equalsLowerCase(CharSequence str, CharSequence lowerCaseOt
797798
* @param str | String to display!
798799
* @param pos | Position to display!
799800
*
800-
* @return String with displayed position!
801+
* @return String with displayed position by using »!
801802
* Use for debugging or error printing!
802803
*
803804
* @since 1.3.2
804805
*/
805806
public static String showPosInString(CharSequence str, int pos)
806807
{
807-
return str + "\n" + multilpy(' ', pos) + "^";
808+
return str.subSequence(0, pos) + "»" + str.subSequence(pos, str.length());
808809
}
809810

810811
/* Arrays */

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
@@ -165,7 +165,7 @@ public String format(Number num)
165165
/**
166166
* @param str | Source char sequence with number to parse.
167167
* @param ch0 | Should be <code>str.charAt(0)</code>. This is to ensure that string is not null or empty and also for possible optimizations.
168-
* @param end | Index of where to end with parsing. If whole string is meant to be parsed, then <code>str.length()-1</code>, should not be greater than that!
168+
* @param end | Index of where to end with parsing (inclusive). If whole string is meant to be parsed, then <code>str.length()-1</code>, should not be greater than that!
169169
* @param base | Base of the parsed number. Theoretically can be anything but usually should be 2, 8, 10 or 16... Note that base will be overridden by suffixes <code>#</code>. for 16, <code>0x</code> for 16, <code>0b</code> for 2 or <code>0</code> for 8 (only if not followed by <code>.</code>).
170170
* @param type | Preferred datatype of of the number represented by suffixes 'S' for {@link Short}, 'Y' for {@link Byte}, 'L' for {@link Long}, 'D' for {@link Double}, 'F' for {@link Float}. Other stands for {@link Integer}.<br>
171171
* Note that floating point numberer will be treated as {@link Double} if no suffix is present by default. Also numbers in E-notation format with negative exponents can be converted to {@link Double}. Further more, integers will be auto-converted to {@link Long} if overflow should occur!<br>

SerialX-devtools/src/main/java/org/ugp/serialx/devtools/DebugParserRegistry.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public Object parse(String str, boolean returnAsStringIfNotFound, Class<? extend
114114
DataParser parser = parsingCache[i];
115115
if (parser != null && (ignore == null || ignore != parser.getClass()))
116116
{
117-
try
118-
{
117+
// try
118+
// {
119119
double t0 = System.nanoTime();
120120
obj = parser.parse(this, str, args);
121121
double t = System.nanoTime();
@@ -124,12 +124,12 @@ public Object parse(String str, boolean returnAsStringIfNotFound, Class<? extend
124124
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms (from cache)\n>>\t\"" + str + "\"\t -->\t" + SerializationDebugger.toStringAndCls(obj));
125125
return obj;
126126
}
127-
}
128-
catch (Exception ex)
129-
{
130-
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " (from cache)\n>>\t\"" + str + "\"\tthrew\t" + ex);
131-
return null;
132-
}
127+
// }
128+
// catch (Exception ex)
129+
// {
130+
// iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " (from cache)\n>>\t\"" + str + "\"\tthrew\t" + ex);
131+
// return null;
132+
// }
133133
}
134134
}
135135

@@ -139,8 +139,8 @@ public Object parse(String str, boolean returnAsStringIfNotFound, Class<? extend
139139
if (ignore != null && ignore == parser.getClass())
140140
continue;
141141

142-
try
143-
{
142+
// try
143+
// {
144144
double t0 = System.nanoTime();
145145
obj = parser.parse(this, str, args);
146146
double t = System.nanoTime();
@@ -151,12 +151,12 @@ public Object parse(String str, boolean returnAsStringIfNotFound, Class<? extend
151151
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms\n>>\t\"" + str + "\"\t -->\t" + SerializationDebugger.toStringAndCls(obj));
152152
return obj;
153153
}
154-
}
155-
catch (Exception ex)
156-
{
157-
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + "\n>>\t\"" + str + "\"\tthrew\t" + ex);
158-
return null;
159-
}
154+
// }
155+
// catch (Exception ex)
156+
// {
157+
// iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + "\n>>\t\"" + str + "\"\tthrew\t" + ex);
158+
// return null;
159+
// }
160160
}
161161

162162
if (returnAsStringIfNotFound)

SerialX-juss/src/main/java/org/ugp/serialx/juss/JussSerializer.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ public <S extends Scope> S LoadFrom(Reader reader, Object... args)
408408
if (args[3] == null)
409409
args[3] = getProtocols();
410410

411-
String str = readAndFormat(reader, formatRequired);
412-
List<Object> objs = splitAndParse(str, 0, args);
411+
StringBuilder str = readAndFormat(reader, formatRequired);
412+
List<Object> objs = splitAndParse(str, args);
413413
addAll(objs);
414414

415415
//double t0 = System.nanoTime();
@@ -504,7 +504,7 @@ else if (ch == '}' || ch == ']')
504504
*
505505
* @since 1.3.2
506506
*/
507-
protected String readAndFormat(Reader reader, boolean format)
507+
protected StringBuilder readAndFormat(Reader reader, boolean format)
508508
{
509509
int quote = 0, multLineCom = -1;
510510
//int brackets = 0, lastIndex = 0, delChars = 0;
@@ -581,24 +581,24 @@ else if (ch == '}' || ch == ']')
581581
e.printStackTrace();
582582
}
583583

584-
return sb.toString();
584+
return sb;
585585
}
586586

587587
/**
588588
* @return List of objects parsed from given formatted string!
589589
*
590590
* @since 1.3.2
591591
*/
592-
protected List<Object> splitAndParse(String formattedStr, int offset, Object... parserArgs)
592+
protected List<Object> splitAndParse(StringBuilder formattedStr, Object... parserArgs)
593593
{
594594
List<Object> result = new ArrayList<>();
595595

596596
ParserRegistry reg = getParsers();
597597

598598
//DataParser[] parsers = new DataParser[DataParser.REGISTRY.size()];
599-
int brackets = 0, quote = 0, lastIndex = 0;
599+
int brackets = 0, quote = 0, lastIndex = 0, len = formattedStr.length();
600600
//boolean isBracketSplit = false;
601-
for (int i = 0, len = formattedStr.length(); i < len; i++)
601+
for (int i = 0; i < len; i++)
602602
{
603603
char ch = formattedStr.charAt(i);
604604
if (ch == '"')
@@ -611,8 +611,8 @@ protected List<Object> splitAndParse(String formattedStr, int offset, Object...
611611
isBracketSplit = false;*/
612612
if (brackets == 0 && (ch == ';' || ch == ',')/* || (brackets == 1 && (isBracketSplit = ch == '}' || ch == ']'))*/)
613613
{
614-
String str = formattedStr.substring(lastIndex == 0 ? 0 : lastIndex + 1, lastIndex = i /*+ (isBracketSplit ? 1 : 0)*/);
615-
if (!(str = str.trim()).isEmpty())
614+
String str = formattedStr.substring(lastIndex == 0 ? 0 : lastIndex + 1, lastIndex = i /*+ (isBracketSplit ? 1 : 0)*/).trim();
615+
if (!str.isEmpty())
616616
{
617617
Object obj = parseObject(reg, str, parserArgs);
618618
if (obj != VOID)
@@ -638,8 +638,8 @@ else if (brackets > 0)
638638
throw new IllegalArgumentException("Unclosed brackets in: " + formattedStr);
639639
else
640640
{
641-
String str = formattedStr.substring(lastIndex == 0 ? 0 : lastIndex + 1, formattedStr.length());
642-
if (!(str = str.trim()).isEmpty())
641+
String str = formattedStr.substring(lastIndex == 0 ? 0 : lastIndex + 1, len).trim();
642+
if (!str.isEmpty())
643643
{
644644
Object obj = parseObject(reg, str, parserArgs);
645645
if (obj != VOID)
@@ -704,7 +704,7 @@ public <T> T cloneOf(String variableName)
704704
*/
705705
public <T> T cloneOf(String variableName, T defaultValue)
706706
{
707-
T obj = get(variableName , defaultValue);
707+
T obj = get(variableName, defaultValue);
708708
if (obj == defaultValue)
709709
return defaultValue;
710710
return Clone(obj, getParsers(), new Object[] {-99999, 0, this, getProtocols(), isGenerateComments()}, this, null, null, getProtocols());

0 commit comments

Comments
 (0)