Interface Path
A Path denotes a particular walk through a
Graph as defined by a Traversal.
In abstraction, any Path implementation maintains two lists: a list of sets of labels and a list of objects.
The list of labels are the labels of the steps traversed. The list of objects are the objects traversed.- Author:
- Marko A. Rodriguez (http://markorodriguez.com)
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionclone()Add a new step to the path with an object and any number of associated labels.Add labels to the head of the path.default voidforEach(BiConsumer<Object, Set<String>> consumer) default <A> Aget(int index) Get the object associated with the specified index into the path.default <A> AGet the object associated with the particular label of the path.default <A> APop the object(s) associated with the label of the path.default booleanReturn true if the path has the specified label, else return false.default <A> Ahead()Get the head of the path.default booleanisEmpty()Determine if the path is empty or not.default booleanisSimple()Determines whether the path is a simple or not.iterator()labels()An ordered list of the labels associated with the path The set of labels for a particular step are ordered by the order in whichextend(Object, Set)was called.objects()An ordered list of the objects in the path.default booleanRemove labels from path.default intsize()Get the number of step in the path.stream()default PathIsolate a sub-path from the path object.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
size
default int size()Get the number of step in the path.- Returns:
- the size of the path
-
isEmpty
default boolean isEmpty()Determine if the path is empty or not.- Returns:
- whether the path is empty or not.
-
head
default <A> A head()Get the head of the path.- Type Parameters:
A- the type of the head of the path- Returns:
- the head of the path
-
extend
Add a new step to the path with an object and any number of associated labels.- Parameters:
object- the new head of the pathlabels- the labels at the head of the path- Returns:
- the extended path
-
extend
Add labels to the head of the path.- Parameters:
labels- the labels at the head of the path- Returns:
- the path with added labels
-
retract
Remove labels from path.- Parameters:
labels- the labels to remove- Returns:
- the path with removed labels
-
get
Get the object associated with the particular label of the path. If the path as multiple labels of the type, then return aListof those objects.- Type Parameters:
A- the type of the object associated with the label- Parameters:
label- the label of the path- Returns:
- the object associated with the label of the path
- Throws:
IllegalArgumentException- if the path does not contain the label
-
get
Pop the object(s) associated with the label of the path.- Type Parameters:
A- the type of the object associated with the label- Parameters:
pop- first for least recent, last for most recent, and all for all in a listlabel- the label of the path- Returns:
- the object associated with the label of the path
- Throws:
IllegalArgumentException- if the path does not contain the label
-
get
default <A> A get(int index) Get the object associated with the specified index into the path.- Type Parameters:
A- the type of the object associated with the index- Parameters:
index- the index of the path- Returns:
- the object associated with the index of the path
-
hasLabel
Return true if the path has the specified label, else return false.- Parameters:
label- the label to search for- Returns:
- true if the label exists in the path
-
objects
An ordered list of the objects in the path.- Returns:
- the objects of the path
-
labels
An ordered list of the labels associated with the path The set of labels for a particular step are ordered by the order in whichextend(Object, Set)was called.- Returns:
- the labels of the path
-
clone
Path clone() -
isSimple
default boolean isSimple()Determines whether the path is a simple or not. A simple path has no cycles and thus, no repeated objects.- Returns:
- Whether the path is simple or not
-
iterator
-
forEach
-
stream
-
popEquals
-
subPath
Isolate a sub-path from the path object. The isolation is based solely on the path labels. The to-label is inclusive. Thus, from "b" to "c" would isolate the example path as followsa,[b,c],d. Note that if there are multiple path segments with the same label, then its the last occurrence that is isolated. For instance, from "b" to "c" would bea,b,[b,c,d,c].- Parameters:
fromLabel- The label to start recording the sub-path from.toLabel- The label to end recording the sub-path to.- Returns:
- the isolated sub-path.
-