-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new procs for virtual paths and graphs (#2153)
Fixes #914 Co-authored-by: Giuseppe Villani <[email protected]>
- Loading branch information
1 parent
0a31af2
commit 5b0c459
Showing
19 changed files
with
345 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package apoc.result; | ||
|
||
import org.neo4j.graphdb.Entity; | ||
import org.neo4j.graphdb.Node; | ||
import org.neo4j.graphdb.Path; | ||
import org.neo4j.graphdb.Relationship; | ||
import org.neo4j.graphdb.traversal.Paths; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.apache.commons.collections4.IterableUtils.reversedIterable; | ||
|
||
|
||
public class VirtualPath implements Path { | ||
|
||
private final Node start; | ||
private final List<Relationship> relationships = new ArrayList<>(); | ||
|
||
public VirtualPath(Node start) { | ||
Objects.requireNonNull(start); | ||
this.start = start; | ||
} | ||
|
||
public void addRel(Relationship relationship) { | ||
Objects.requireNonNull(relationship); | ||
this.relationships.add(relationship); | ||
} | ||
|
||
@Override | ||
public Node startNode() { | ||
return start; | ||
} | ||
|
||
@Override | ||
public Node endNode() { | ||
return reverseNodes().iterator().next(); | ||
} | ||
|
||
@Override | ||
public Relationship lastRelationship() { | ||
return relationships.isEmpty() ? null : relationships.get(relationships.size() - 1); | ||
} | ||
|
||
@Override | ||
public Iterable<Relationship> relationships() { | ||
return relationships; | ||
} | ||
|
||
@Override | ||
public Iterable<Relationship> reverseRelationships() { | ||
return reversedIterable(relationships()); | ||
} | ||
|
||
@Override | ||
public Iterable<Node> nodes() { | ||
List<Node> nodes = new ArrayList<>(); | ||
nodes.add(start); | ||
|
||
AtomicReference<Node> currNode = new AtomicReference<>(start); | ||
final List<Node> otherNodes = relationships.stream().map(rel -> { | ||
final Node otherNode = rel.getOtherNode(currNode.get()); | ||
currNode.set(otherNode); | ||
return otherNode; | ||
}).collect(Collectors.toList()); | ||
|
||
nodes.addAll(otherNodes); | ||
return nodes; | ||
} | ||
|
||
@Override | ||
public Iterable<Node> reverseNodes() { | ||
return reversedIterable(nodes()); | ||
} | ||
|
||
@Override | ||
public int length() { | ||
return relationships.size(); | ||
} | ||
|
||
@Override | ||
@Nonnull | ||
public Iterator<Entity> iterator() { | ||
return new Iterator<>() { | ||
Iterator<? extends Entity> current = nodes().iterator(); | ||
Iterator<? extends Entity> next = relationships().iterator(); | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return current.hasNext(); | ||
} | ||
|
||
@Override | ||
public Entity next() { | ||
try { | ||
return current.next(); | ||
} | ||
finally { | ||
Iterator<? extends Entity> temp = current; | ||
current = next; | ||
next = temp; | ||
} | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
next.remove(); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Paths.defaultPathToString(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...doc/modules/ROOT/examples/generated-documentation/apoc.create.clonePathToVirtual-lite.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
¦signature | ||
¦apoc.create.clonePathToVirtual(path :: PATH?) :: (path :: PATH?) |
5 changes: 5 additions & 0 deletions
5
...dules/ROOT/examples/generated-documentation/apoc.create.clonePathToVirtual.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
¦xref::overview/apoc.create/apoc.create.clonePathToVirtual.adoc[apoc.create.clonePathToVirtual icon:book[]] + | ||
|
||
|
||
¦label:procedure[] | ||
¦label:apoc-core[] |
2 changes: 2 additions & 0 deletions
2
...oc/modules/ROOT/examples/generated-documentation/apoc.create.clonePathsToVirtual-lite.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
¦signature | ||
¦apoc.create.clonePathsToVirtual(paths :: LIST? OF PATH?) :: (path :: PATH?) |
5 changes: 5 additions & 0 deletions
5
...ules/ROOT/examples/generated-documentation/apoc.create.clonePathsToVirtual.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
¦xref::overview/apoc.create/apoc.create.clonePathsToVirtual.adoc[apoc.create.clonePathsToVirtual icon:book[]] + | ||
|
||
|
||
¦label:procedure[] | ||
¦label:apoc-core[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...doc/modules/ROOT/pages/overview/apoc.create/apoc.create.clonePathToVirtual.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//// | ||
This file is generated by DocsTest, so don't change it! | ||
//// | ||
|
||
= apoc.create.clonePathToVirtual | ||
:description: This section contains reference documentation for the apoc.create.clonePathToVirtual procedure. | ||
|
||
label:procedure[] label:apoc-core[] | ||
|
||
[.emphasis] | ||
apoc.create.clonePathToVirtual | ||
|
||
== Signature | ||
|
||
[source] | ||
---- | ||
apoc.create.clonePathToVirtual(path :: PATH?) :: (path :: PATH?) | ||
---- | ||
|
||
== Input parameters | ||
[.procedures, opts=header] | ||
|=== | ||
| Name | Type | Default | ||
|path|PATH?|null | ||
|=== | ||
|
||
== Output parameters | ||
[.procedures, opts=header] | ||
|=== | ||
| Name | Type | ||
|path|PATH? | ||
|=== | ||
|
||
xref::virtual/virtual-nodes-rels.adoc[More documentation of apoc.create.clonePathToVirtual,role=more information] | ||
|
Oops, something went wrong.