Skip to content

Commit ca73f6e

Browse files
committed
We don't have neo4j
We are usually working around this by having a copy of the actual config which overrides the fields that are using problematic converters to use something else. However, with the refactor around configs, the generated builders don't really work anymore and I wanted to use a config builder to build the individual dijkstra configs. This is a bit of a hack, but it works, soooo 😎
1 parent 388860e commit ca73f6e

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

config-api/src/main/java/org/neo4j/gds/config/NodeIdParser.java

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,27 @@ private static Double parsePropertyValue(Object input, String parameterName) {
9898
}
9999

100100
private static Long parseNodeId(Object input, String parameterName) {
101-
if (input instanceof Node) {
102-
return ((Node) input).getId();
103-
} else if (input instanceof Number) {
104-
return ((Number) input).longValue();
101+
if (input instanceof Number num) {
102+
return num.longValue();
105103
}
106104

107-
throw new IllegalArgumentException(formatWithLocale(
108-
"Failed to parse `%s` as a List of node IDs. A Node, Number or collection of the same can be parsed, but this `%s` cannot.",
109-
parameterName,
110-
input.getClass().getSimpleName()
111-
));
105+
try {
106+
if (input instanceof Node node) {
107+
return node.getId();
108+
}
109+
110+
throw new IllegalArgumentException(formatWithLocale(
111+
"Failed to parse `%s` as a List of node IDs. A Node, Number or collection of the same can be parsed, but this `%s` cannot.",
112+
parameterName,
113+
input.getClass().getSimpleName()
114+
));
115+
} catch (NoClassDefFoundError neo4jNotAvailable) {
116+
throw new IllegalArgumentException(formatWithLocale(
117+
"Failed to parse `%s` as a List of node IDs. A number or collection of numbers can be parsed, but this `%s` cannot.",
118+
parameterName,
119+
input.getClass().getSimpleName()
120+
));
121+
}
112122
}
113123

114124
/**
@@ -120,7 +130,7 @@ private static Long parseNodeId(Object input, String parameterName) {
120130
* @return A {@code java.lang.Long} of node IDs.
121131
*/
122132
public static long parseToSingleNodeId(Object input, String parameterName) {
123-
if (input instanceof Collection collection) {
133+
if (input instanceof Collection<?> collection) {
124134
if (collection.size() != 1) {
125135
throw new IllegalArgumentException(formatWithLocale(
126136
"Failed to parse `%s` as a single node ID. A collection can be parsed if it contains a single element, but this `%s` contains `%s` elements.",
@@ -131,16 +141,25 @@ public static long parseToSingleNodeId(Object input, String parameterName) {
131141
}
132142
input = collection.iterator().next();
133143
}
134-
if (input instanceof Number) {
135-
return ((Number) input).longValue();
144+
if (input instanceof Number num) {
145+
return num.longValue();
136146
}
137-
if (input instanceof Node) {
138-
return ((Node) input).getId();
147+
try {
148+
if (input instanceof Node node) {
149+
return node.getId();
150+
}
151+
152+
throw new IllegalArgumentException(formatWithLocale(
153+
"Failed to parse `%s` as a single node ID. A Node, a Number or a collection containing a single Node or Number can be parsed, but this `%s` cannot.",
154+
parameterName,
155+
input.getClass().getSimpleName()
156+
));
157+
} catch (NoClassDefFoundError neo4jNotAvailable) {
158+
throw new IllegalArgumentException(formatWithLocale(
159+
"Failed to parse `%s` as a single node ID. A number or a collection containing a single number can be parsed, but this `%s` cannot.",
160+
parameterName,
161+
input.getClass().getSimpleName()
162+
));
139163
}
140-
throw new IllegalArgumentException(formatWithLocale(
141-
"Failed to parse `%s` as a single node ID. A Node, a Number or a collection containing a single Node or Number can be parsed, but this `%s` cannot.",
142-
parameterName,
143-
input.getClass().getSimpleName()
144-
));
145164
}
146165
}

0 commit comments

Comments
 (0)