Skip to content

Commit b5c67ca

Browse files
array converter supp for 0 len and 1 len arrs
1 parent 006e551 commit b5c67ca

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

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

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,19 @@ public class ArrayConverter implements DataConverter
4949
@Override
5050
public Object parse(ParserRegistry myHomeRegistry, String str, Object... args)
5151
{
52-
if (indexOfNotInObj(str, ' ') > 0)
52+
int len, startI = 0;
53+
if ((len = str.length()) != 0 && str.charAt(0) == '@' || (startI = indexOfNotInObj(str, 1, len, 0, true, ' ')) > 0)
5354
{
54-
String[] strObjs = tokenize(str);
55-
int len, i = 0;
56-
Object[] objs = new Object[len = strObjs.length];
55+
String[] strObjs = tokenize(startI == 0 ? str.substring(1).trim() : str, startI);
56+
int arrLen, i = 0;
57+
Object[] arr = new Object[arrLen = strObjs.length];
5758

5859
if (args.length < 2 || !(args[1] instanceof Boolean) || (boolean) args[1])
5960
{
6061
Class<?> arrClass = null;
61-
for (; i < len; i++)
62+
for (; i < arrLen; i++)
6263
{
63-
Object obj = objs[i] = myHomeRegistry.parse(strObjs[i], args);
64+
Object obj = arr[i] = myHomeRegistry.parse(strObjs[i], args);
6465
if (obj != null)
6566
if (arrClass == null)
6667
arrClass = obj.getClass();
@@ -71,16 +72,16 @@ else if (arrClass != obj.getClass())
7172
if (arrClass != null && arrClass != Object.class)
7273
try
7374
{
74-
return castArray(objs, arrClass);
75+
return castArray(arr, arrClass);
7576
}
7677
catch (IllegalArgumentException e)
7778
{}
78-
return objs;
79+
return arr;
7980
}
8081

81-
for (; i < len; i++)
82-
objs[i] = myHomeRegistry.parse(strObjs[i], args);
83-
return objs;
82+
for (; i < arrLen; i++)
83+
arr[i] = myHomeRegistry.parse(strObjs[i], args);
84+
return arr;
8485
}
8586
return CONTINUE;
8687
}
@@ -108,21 +109,23 @@ public CharSequence toString(ParserRegistry myHomeRegistry, Object obj, Object..
108109

109110
Object[] elms = fromAmbiguousArray(obj);
110111
final int len = elms.length;
111-
StringBuilder sb = new StringBuilder();
112+
if (len == 0)
113+
return "@";
114+
115+
StringBuilder sb = new StringBuilder("@");
112116
if (args.length > 5 && args[5] instanceof Byte && (byte) args[5] != 0) // Format
113117
{
114118
for (int i = 0, sizeEndl = 10000; i < len; i++)
115119
{
116-
if (i != 0)
117-
if (sb.length() > sizeEndl)
118-
{
119-
sb.append('\n');
120-
for (int j = 0; j < tabs+1; j++)
121-
sb.append('\t');
122-
sizeEndl += 10000;
123-
}
124-
else
125-
sb.append(' ');
120+
if (sb.length() > sizeEndl)
121+
{
122+
sb.append('\n');
123+
for (int j = 0; j < tabs+1; j++)
124+
sb.append('\t');
125+
sizeEndl += 10000;
126+
}
127+
else
128+
sb.append(' ');
126129

127130
CharSequence str = myHomeRegistry.toString(elms[i], args);
128131
char ch = str.charAt(0);
@@ -136,8 +139,7 @@ public CharSequence toString(ParserRegistry myHomeRegistry, Object obj, Object..
136139
{
137140
for (int i = 0; i < len; i++)
138141
{
139-
if (i != 0)
140-
sb.append(' ');
142+
sb.append(' ');
141143

142144
CharSequence str = myHomeRegistry.toString(elms[i], args);
143145
char ch = str.charAt(0);
@@ -167,8 +169,8 @@ public CharSequence getDescription(ParserRegistry myHomeRegistry, Object objToDe
167169
*
168170
* @since 1.3.2
169171
*/
170-
public String[] tokenize(String str)
172+
public String[] tokenize(String str, int firstSplitterI)
171173
{
172-
return splitValues(str, ' ');
174+
return str.isEmpty() ? new String[0] : splitValues(str, firstSplitterI, 0, 2, new char[0], ' ');
173175
}
174176
}

0 commit comments

Comments
 (0)