@API(status=STABLE,
since="1.0")
public class UniqueId
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
UniqueId
encapsulates the creation, parsing, and display of unique IDs
for TestDescriptors
.
Instances of this class have value semantics and are immutable.
Modifier and Type | Class and Description |
---|---|
static class |
UniqueId.Segment
A segment of a
UniqueId comprises a type and a
value. |
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ENGINE_SEGMENT_TYPE |
private java.util.List<UniqueId.Segment> |
segments |
private static long |
serialVersionUID |
private UniqueIdFormat |
uniqueIdFormat |
Modifier | Constructor and Description |
---|---|
(package private) |
UniqueId(UniqueIdFormat uniqueIdFormat,
java.util.List<UniqueId.Segment> segments)
Initialize a
UniqueId instance. |
private |
UniqueId(UniqueIdFormat uniqueIdFormat,
UniqueId.Segment segment) |
Modifier and Type | Method and Description |
---|---|
UniqueId |
append(java.lang.String segmentType,
java.lang.String value)
Construct a new
UniqueId by appending a new UniqueId.Segment , based
on the supplied segmentType and value , to the end of this
UniqueId . |
UniqueId |
append(UniqueId.Segment segment)
|
protected java.lang.Object |
clone() |
boolean |
equals(java.lang.Object o) |
static UniqueId |
forEngine(java.lang.String engineId)
Create an engine's unique ID from its
engineId using the default
format. |
java.util.Optional<java.lang.String> |
getEngineId()
Get the engine ID stored in this
UniqueId , if available. |
UniqueId.Segment |
getLastSegment()
Get the last
UniqueId.Segment of this UniqueId . |
(package private) java.util.Optional<UniqueId.Segment> |
getRoot() |
java.util.List<UniqueId.Segment> |
getSegments()
Get the immutable list of segments that make up this
UniqueId . |
int |
hashCode() |
boolean |
hasPrefix(UniqueId potentialPrefix)
Determine if the supplied
UniqueId is a prefix for this
UniqueId . |
static UniqueId |
parse(java.lang.String uniqueId)
Parse a
UniqueId from the supplied string representation using the
default format. |
UniqueId |
removeLastSegment()
|
static UniqueId |
root(java.lang.String segmentType,
java.lang.String value)
Create a root unique ID from the supplied
segmentType and
value using the default format. |
java.lang.String |
toString()
Generate the unique, formatted string representation of this
UniqueId
using the configured UniqueIdFormat . |
private static final long serialVersionUID
private static final java.lang.String ENGINE_SEGMENT_TYPE
private final UniqueIdFormat uniqueIdFormat
private final java.util.List<UniqueId.Segment> segments
private UniqueId(UniqueIdFormat uniqueIdFormat, UniqueId.Segment segment)
UniqueId(UniqueIdFormat uniqueIdFormat, java.util.List<UniqueId.Segment> segments)
UniqueId
instance.public static UniqueId parse(java.lang.String uniqueId) throws JUnitException
UniqueId
from the supplied string representation using the
default format.uniqueId
- the string representation to parse; never null
or blankUniqueId
JUnitException
- if the string cannot be parsedpublic static UniqueId forEngine(java.lang.String engineId)
engineId
using the default
format.
The engine ID will be stored in a UniqueId.Segment
with
type
"engine"
.
engineId
- the engine ID; never null
or blankroot(String, String)
public static UniqueId root(java.lang.String segmentType, java.lang.String value)
segmentType
and
value
using the default format.segmentType
- the segment type; never null
or blankvalue
- the value; never null
or blankforEngine(String)
final java.util.Optional<UniqueId.Segment> getRoot()
public final java.util.Optional<java.lang.String> getEngineId()
UniqueId
, if available.forEngine(String)
public final java.util.List<UniqueId.Segment> getSegments()
UniqueId
.public final UniqueId append(java.lang.String segmentType, java.lang.String value)
UniqueId
by appending a new UniqueId.Segment
, based
on the supplied segmentType
and value
, to the end of this
UniqueId
.
This UniqueId
will not be modified.
Neither the segmentType
nor the value
may contain any
of the special characters used for constructing the string representation
of this UniqueId
.
segmentType
- the type of the segment; never null
or blankvalue
- the value of the segment; never null
or blank@API(status=STABLE, since="1.1") public final UniqueId append(UniqueId.Segment segment)
UniqueId
by appending a new UniqueId.Segment
to
the end of this UniqueId
.
This UniqueId
will not be modified.
segment
- the segment to be appended; never null
@API(status=STABLE, since="1.1") public boolean hasPrefix(UniqueId potentialPrefix)
UniqueId
is a prefix for this
UniqueId
.potentialPrefix
- the UniqueId
to be checked; never null
@API(status=STABLE, since="1.5") public UniqueId removeLastSegment()
UniqueId
and removing the last UniqueId.Segment
of
this UniqueId
.
This UniqueId
will not be modified.
UniqueId
; never null
PreconditionViolationException
- if this UniqueId
contains a single segment@API(status=STABLE, since="1.5") public UniqueId.Segment getLastSegment()
UniqueId.Segment
of this UniqueId
.Segment
; never null
protected java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
UniqueId
using the configured UniqueIdFormat
.toString
in class java.lang.Object