public final class IntPath extends Object implements Comparable<IntPath>, Iterable<Integer>, Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
IntPath.Builder
A builder for IntPaths.
|
| Modifier and Type | Method and Description |
|---|---|
IntPath |
appending(int value)
Create a new path appending the passed value.
|
IntPath |
appending(IntPath other)
Create a new IntPath of this one concatenated with another.
|
static IntPath.Builder |
builder()
Create a builder for int paths.
|
static IntPath.Builder |
builder(int first)
Create a builder for int paths.
|
boolean |
canJoin(IntPath other)
Returns true if the other path's start is this one's end or vice-versa.
|
IntPath |
childPath()
Create a new path, lopping off the first element.
|
int |
compareTo(IntPath o) |
boolean |
contains(int val)
Determine if this path contains the passed value.
|
boolean |
contains(IntPath path)
Determine if this path contains the subsequence in the passed path, or is
equal to it.
|
boolean |
containsRepeatedNodes()
Returns true if at least one node in this path occurs more than once in
it.
|
int |
end() |
boolean |
endsWith(IntPath other)
Determine if this path ends with (or is equal to) another path.
|
boolean |
equals(Object o) |
int |
first()
Get the first path element
|
int |
firstOverlappingElement(IntPath other)
Returns the index in this IntPath of the first path element also present
in the other, or -1 if there is none.
|
void |
forEachInt(IntConsumer c)
Iterate all elements of the path, passing them to the passed consumer.
|
void |
forEachIntReversed(IntConsumer c)
Iterate all elements of the path in reverse order, passing them to the
passed consumer.
|
int |
get(int index)
Get the path element at the specified index.
|
int |
hashCode() |
int |
indexOf(int val)
Get the first occurrence of the passed value in this path.
|
int |
indexOf(int from,
int val)
Get the first occurrence of the passed value in this path.
|
boolean |
intersects(IntPath other)
Determine if this IntPath contains some nodes in common with another.
|
boolean |
isEdge() |
boolean |
isEmpty()
Determine if this path is empty.
|
boolean |
isNotAPath()
Determine if this path does not represent an actual path - if it has one
element or less.
|
int[] |
items()
Get the contents of this path as an int[].
|
void |
iterate(IntConsumer cons)
Deprecated.
use the better-named
forEachInt() |
Iterator<Integer> |
iterator() |
IntPath |
join(IntPath other)
Join this path with another path, prepending or appending depending on
whether this one's start and the other's end are the same, or the other's
start and this one's end are the same.
|
IntPath |
join(IntPath other,
boolean eliminateOverlap)
Join this path with another path, if they share a start/end pair, without
duplicating elements; if
eliminateOverlap is passed, then
whichever the latter path is in the result, it will be truncated so as
not to include any elements also present in the other - this is commonly
needed when computing sets of paths that have no partial overlap; returns
null if the start/end pairs of neither match. |
int |
last()
Get the last path element
|
int |
lastIndexOf(int val)
Get the first occurrence of the passed value in this path.
|
int |
lastIndexOf(int from,
int val)
Get the last occurrence of the passed value in this path.
|
int |
lastOverlappingElement(IntPath other)
Returns the index in this IntPath of the first path element also present
in the other, or -1 if there is none.
|
static IntPath |
of(Collection<? extends Integer> ints) |
static IntPath |
of(int... items)
Create an IntPath from an array of ints.
|
static IntPath |
ofUnsafe(int... items)
Create an IntPath from an array of ints, using the passed array directly
rather than copying it.
|
IntPath |
parentPath()
Create a new path, lopping off the last element.
|
static IntPath |
parse(String val)
Creates an IntPath from a comma-delimited list of integers (which may
contain whitespace), such as the output of
toString(). |
IntPath |
prepending(int value)
Create a new path prepending the passed value.
|
IntPath |
prepending(IntPath other)
Create a new IntPath of this one concatenated with another.
|
IntPath |
reversed()
Create a new path whose elements are this one's in reverse order.
|
int |
size()
Get the number of elements in this path.
|
int |
start() |
boolean |
startsWith(IntPath other)
Determine if this path starts with (or is equal to) another path.
|
IntPath |
subPath(int start,
int end)
Get a subpath.
|
int |
sum() |
Bits |
toBits()
Get all nodes in this path as a Bits useful for intersection testing.
|
IntPath.Builder |
toBuilder()
Create a builder initialized from this path.
|
<T> ObjectPath<T> |
toObjectPath(IndexedResolvable<T> indexed)
Create an ObjectPath from this IntPath.
|
<T> ObjectPath<T> |
toObjectPath(List<T> indexed)
Create an ObjectPath from this IntPath.
|
<T extends Comparable<T>> |
toObjectPath(T... indexed)
Create an ObjectPath from this IntPath.
|
String |
toString() |
int |
visitAllSubPaths(int minLength,
Consumer<IntPath> c)
Visit every possible child path of this path which is smaller than this
path but greater than or equal to the passed minimum length.
|
int |
visitSubPathsOfLength(int length,
Consumer<IntPath> c)
Visit every possible child path of this path which is smaller than this
path but greater than or equal to the passed minimum length.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static IntPath of(Collection<? extends Integer> ints)
public static IntPath parse(String val)
toString().val - A stringNumberFormatException - If the text contains non-comma,
non-whitespace, non-digit characterspublic IntPath prepending(IntPath other)
other - The other pathpublic boolean canJoin(IntPath other)
other - Another pathpublic IntPath join(IntPath other)
other - Another pathpublic int firstOverlappingElement(IntPath other)
other - Another pathpublic int lastOverlappingElement(IntPath other)
other - Another pathpublic IntPath join(IntPath other, boolean eliminateOverlap)
eliminateOverlap is passed, then
whichever the latter path is in the result, it will be truncated so as
not to include any elements also present in the other - this is commonly
needed when computing sets of paths that have no partial overlap; returns
null if the start/end pairs of neither match.
Examples:
elimimnateOverlap is falseelimimnateOverlap is trueother - Another patheliminateOverlap - If true, truncate one of the paths when
concatenating, as described abovepublic IntPath appending(IntPath other)
other - The other pathpublic IntPath prepending(int value)
value - A valueIllegalArgumentException - if the value is negativepublic IntPath appending(int value)
value - A valueIllegalArgumentException - if the value is negativepublic void forEachInt(IntConsumer c)
c - A consumerpublic void forEachIntReversed(IntConsumer c)
c - A consumerpublic int first()
IndexOutOfBoundsException - if out of rangepublic int last()
IndexOutOfBoundsException - if out of rangepublic static IntPath of(int... items)
items - An array of intspublic static IntPath ofUnsafe(int... items)
items - An array of intspublic static IntPath.Builder builder()
public static IntPath.Builder builder(int first)
first - The first elementpublic IntPath.Builder toBuilder()
public IntPath childPath()
public IntPath parentPath()
public IntPath reversed()
public boolean startsWith(IntPath other)
other - Another pathpublic boolean endsWith(IntPath other)
other - Another pathpublic boolean intersects(IntPath other)
other - Another IntPathpublic Bits toBits()
public int visitAllSubPaths(int minLength,
Consumer<IntPath> c)
minLength - The lengthc - A consumerpublic int visitSubPathsOfLength(int length,
Consumer<IntPath> c)
length - The lengthc - A consumerpublic boolean containsRepeatedNodes()
public IntPath subPath(int start, int end)
start - The start index, inclusiveend - The end index, exclusiveIllegalArgumentException - if the arguments are out of range or
invalidpublic int start()
public int end()
public boolean contains(IntPath path)
path - A pathpublic int indexOf(int val)
val - An integer path elementpublic int indexOf(int from,
int val)
from - The index to start searching atval - An integer path elementpublic int lastIndexOf(int from,
int val)
from - The index to stop searching atval - An integer path elementpublic int lastIndexOf(int val)
val - An integer path elementpublic boolean contains(int val)
val - A valuepublic boolean isEmpty()
public int size()
public boolean isNotAPath()
public boolean isEdge()
public int get(int index)
index - The index within the pathpublic int[] items()
@Deprecated public void iterate(IntConsumer cons)
forEachInt()cons - public final int sum()
public <T> ObjectPath<T> toObjectPath(List<T> indexed)
T - The object typeindexed - A list of objects@SafeVarargs public final <T extends Comparable<T>> ObjectPath<T> toObjectPath(T... indexed)
T - The object typeindexed - An array of comparable itemspublic <T> ObjectPath<T> toObjectPath(IndexedResolvable<T> indexed)
T - The object typeindexed - An IndexedResolvable (has static methods to wrap lists,
etc.)public int compareTo(IntPath o)
compareTo in interface Comparable<IntPath>Copyright © 2010–2021 Mastfrog Technologies. All rights reserved.