Skip to content

Commit 9e61423

Browse files
update to switch case statement
1 parent 377d87c commit 9e61423

1 file changed

Lines changed: 75 additions & 54 deletions

File tree

src/main/java/org/ogo/util/CastObjectArrayToPrimitive.java

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -120,62 +120,83 @@ public static Character[] castToCharacter(String[] propertyValue) {
120120
*/
121121
public static Node castToNeo4JPropertyType(
122122
String propertyName, String[] propertyValue, String propertyType, Node node) {
123-
if (propertyType.compareTo("JBOOLEAN_ARRAY") == 0) {
124-
node.setProperty(propertyName, castToBoolean(propertyValue));
125-
} else if (propertyType.compareTo("JBYTE_ARRAY") == 0) {
126-
node.setProperty(propertyName, castToByte(propertyValue));
127-
} else if (propertyType.compareTo("JCHAR_ARRAY") == 0) {
128-
node.setProperty(propertyName, castToCharacter(propertyValue));
129-
} else if (propertyType.compareTo("JSHORT_ARRAY") == 0) {
130-
node.setProperty(propertyName, castToShort(propertyValue));
131-
} else if (propertyType.compareTo("JINT_ARRAY") == 0) {
132-
node.setProperty(propertyName, castToInteger(propertyValue));
133-
} else if (propertyType.compareTo("JLONG_ARRAY") == 0) {
134-
node.setProperty(propertyName, castToLong(propertyValue));
135-
} else if (propertyType.compareTo("JFLOAT_ARRAY") == 0) {
136-
node.setProperty(propertyName, castToFloat(propertyValue));
137-
} else if (propertyType.compareTo("JDOUBLE_ARRAY") == 0) {
138-
node.setProperty(propertyName, castToDouble(propertyValue));
139-
} else if (propertyType.compareTo("JSTRING_ARRAY") == 0) {
140-
node.setProperty(propertyName, propertyValue);
141-
} else {
142-
if (propertyValue.length == 1) {
143-
if (propertyType.compareTo("JBOOLEAN") == 0) {
144-
node.setProperty(propertyName, Boolean.parseBoolean(propertyValue[0]));
145-
} else if (propertyType.compareTo("JBYTE") == 0) {
146-
node.setProperty(propertyName, Byte.parseByte(propertyValue[0]));
147-
} else if (propertyType.compareTo("JCHAR") == 0) {
148-
node.setProperty(propertyName, propertyValue[0].charAt(0));
149-
} else if (propertyType.compareTo("JSHORT") == 0) {
150-
node.setProperty(propertyName, Short.parseShort(propertyValue[0]));
151-
} else if (propertyType.compareTo("JINT") == 0) {
152-
node.setProperty(propertyName, Integer.parseInt(propertyValue[0]));
153-
} else if (propertyType.compareTo("JLONG") == 0) {
154-
node.setProperty(propertyName, Long.parseLong(propertyValue[0]));
155-
} else if (propertyType.compareTo("JFLOAT") == 0) {
156-
if (propertyValue[0].compareTo("inf") == 0) {
157-
node.setProperty(propertyName, Float.POSITIVE_INFINITY);
158-
} else if (propertyValue[0].compareTo("-inf") == 0) {
159-
node.setProperty(propertyName, Float.NEGATIVE_INFINITY);
160-
} else if (propertyValue[0].compareTo("nan") == 0) {
161-
node.setProperty(propertyName, Float.NaN);
162-
} else {
163-
node.setProperty(propertyName, Float.parseFloat(propertyValue[0]));
123+
switch (propertyType) {
124+
case "JBOOLEAN_ARRAY":
125+
node.setProperty(propertyName, castToBoolean(propertyValue));
126+
break;
127+
case "JBYTE_ARRAY":
128+
node.setProperty(propertyName, castToByte(propertyValue));
129+
break;
130+
case "JCHAR_ARRAY":
131+
node.setProperty(propertyName, castToCharacter(propertyValue));
132+
break;
133+
case "JSHORT_ARRAY":
134+
node.setProperty(propertyName, castToShort(propertyValue));
135+
break;
136+
case "JINT_ARRAY":
137+
node.setProperty(propertyName, castToInteger(propertyValue));
138+
break;
139+
case "JLONG_ARRAY":
140+
node.setProperty(propertyName, castToLong(propertyValue));
141+
break;
142+
case "JFLOAT_ARRAY":
143+
node.setProperty(propertyName, castToFloat(propertyValue));
144+
break;
145+
case "JDOUBLE_ARRAY":
146+
node.setProperty(propertyName, castToDouble(propertyValue));
147+
break;
148+
case "JSTRING_ARRAY":
149+
node.setProperty(propertyName, propertyValue);
150+
break;
151+
default:
152+
if (propertyValue.length == 1) {
153+
switch (propertyType) {
154+
case "JBOOLEAN":
155+
node.setProperty(propertyName, Boolean.parseBoolean(propertyValue[0]));
156+
break;
157+
case "JBYTE":
158+
node.setProperty(propertyName, Byte.parseByte(propertyValue[0]));
159+
break;
160+
case "JCHAR":
161+
node.setProperty(propertyName, propertyValue[0].charAt(0));
162+
break;
163+
case "JSHORT":
164+
node.setProperty(propertyName, Short.parseShort(propertyValue[0]));
165+
break;
166+
case "JINT":
167+
node.setProperty(propertyName, Integer.parseInt(propertyValue[0]));
168+
break;
169+
case "JLONG":
170+
node.setProperty(propertyName, Long.parseLong(propertyValue[0]));
171+
break;
172+
case "JFLOAT":
173+
if ("inf".equals(propertyValue[0])) {
174+
node.setProperty(propertyName, Float.POSITIVE_INFINITY);
175+
} else if ("-inf".equals(propertyValue[0])) {
176+
node.setProperty(propertyName, Float.NEGATIVE_INFINITY);
177+
} else if ("nan".equals(propertyValue[0])) {
178+
node.setProperty(propertyName, Float.NaN);
179+
} else {
180+
node.setProperty(propertyName, Float.parseFloat(propertyValue[0]));
181+
}
182+
break;
183+
case "JDOUBLE":
184+
if ("inf".equals(propertyValue[0])) {
185+
node.setProperty(propertyName, Double.POSITIVE_INFINITY);
186+
} else if ("-inf".equals(propertyValue[0])) {
187+
node.setProperty(propertyName, Double.NEGATIVE_INFINITY);
188+
} else if ("nan".equals(propertyValue[0])) {
189+
node.setProperty(propertyName, Double.NaN);
190+
} else {
191+
node.setProperty(propertyName, Double.parseDouble(propertyValue[0]));
192+
}
193+
break;
194+
case "JSTRING":
195+
node.setProperty(propertyName, propertyValue[0]);
196+
break;
164197
}
165-
} else if (propertyType.compareTo("JDOUBLE") == 0) {
166-
if (propertyValue[0].compareTo("inf") == 0) {
167-
node.setProperty(propertyName, Double.POSITIVE_INFINITY);
168-
} else if (propertyValue[0].compareTo("-inf") == 0) {
169-
node.setProperty(propertyName, Double.NEGATIVE_INFINITY);
170-
} else if (propertyValue[0].compareTo("nan") == 0) {
171-
node.setProperty(propertyName, Double.NaN);
172-
} else {
173-
node.setProperty(propertyName, Double.parseDouble(propertyValue[0]));
174-
}
175-
} else if (propertyType.compareTo("JSTRING") == 0) {
176-
node.setProperty(propertyName, propertyValue[0]);
177198
}
178-
}
199+
break;
179200
}
180201
return node;
181202
}

0 commit comments

Comments
 (0)