@@ -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