1
1
package n10s .result ;
2
2
3
- import org .apache .commons .collections .CollectionUtils ;
4
3
import org .neo4j .graphdb .*;
5
4
import org .neo4j .graphdb .traversal .Paths ;
6
5
10
9
import java .util .concurrent .atomic .AtomicReference ;
11
10
12
11
13
- //import static org.apache.commons.collections4.IterableUtils.reversedIterable;
14
-
15
-
16
12
public class VirtualPath implements Path {
17
13
private final Node start ;
18
14
private final List <Relationship > relationships ;
@@ -124,36 +120,31 @@ public String toString() {
124
120
125
121
private void requireConnected (Relationship relationship ) {
126
122
final List <Node > previousNodes = getPreviousNodes ();
127
- boolean isRelConnectedToPrevious = CollectionUtils . containsAny ( previousNodes , Arrays .asList (relationship .getNodes ()) );
123
+ boolean isRelConnectedToPrevious = containsAny ( previousNodes , Arrays .asList (relationship .getNodes ()));
128
124
if (!isRelConnectedToPrevious ) {
129
125
throw new IllegalArgumentException ("Relationship is not part of current path." );
130
126
}
131
127
}
132
128
129
+ public static boolean containsAny (Collection <?> coll1 , Collection <?> coll2 ) {
130
+ if (coll1 == null || coll2 == null ) {
131
+ return false ;
132
+ }
133
+
134
+ for (Object obj : coll1 ) {
135
+ if (coll2 .contains (obj )) {
136
+ return true ;
137
+ }
138
+ }
139
+
140
+ return false ;
141
+ }
142
+
133
143
private List <Node > getPreviousNodes () {
134
144
Relationship previousRelationship = lastRelationship ();
135
145
if (previousRelationship != null ) {
136
146
return Arrays .asList (previousRelationship .getNodes ());
137
147
}
138
148
return List .of (endNode ());
139
149
}
140
-
141
- public static final class Builder {
142
- private final Node start ;
143
- private final List <Relationship > relationships = new ArrayList <>();
144
-
145
- public Builder (Node start ) {
146
- this .start = start ;
147
- }
148
-
149
- public Builder push (Relationship relationship ) {
150
- this .relationships .add (relationship );
151
- return this ;
152
- }
153
-
154
- public VirtualPath build () {
155
- return new VirtualPath (start , relationships );
156
- }
157
-
158
- }
159
150
}
0 commit comments