Top Description Inners Fields Constructors Methods
org.junit.platform.engine

public final Class UniqueId

extends Object
implements Cloneable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Cloneable
Annotations
@API
status:STABLE
since:1.0
Static Imports
org.apiguardian.api.API.Status.STABLE

UniqueId encapsulates the creation, parsing, and display of unique IDs for TestDescriptors.

Instances of this class have value semantics and are immutable.

Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
UniqueId.Segment

A segment of a UniqueId comprises a type and a value.

Field Summary

Modifier and TypeField and Description
private static final String
private transient int
private final List<UniqueId.Segment>
private static final long
private transient @Nullable SoftReference<String>
private final UniqueIdFormat

Constructor Summary

AccessConstructor and Description
private
UniqueId(UniqueIdFormat uniqueIdFormat, UniqueId.Segment segment)

pack-priv
UniqueId(UniqueIdFormat uniqueIdFormat, List<UniqueId.Segment> segments)

Initialize a UniqueId instance.

Method Summary

Modifier and TypeMethod and Description
public UniqueId
append(String
the type of the segment; never null or blank
segmentType
,
String
the value of the segment; never null or blank
value
)

Construct a new UniqueId by appending a new Segment, based on the supplied segmentType and value, to the end of this UniqueId.

public UniqueId
append(UniqueId.Segment
the segment to be appended; never null
segment
)

Construct a new UniqueId by appending a new Segment to the end of this UniqueId.

public UniqueId
appendEngine(String
the engine ID; never null or blank
engineId
)

Construct a new UniqueId by appending a new Segment, based on the supplied engineId, to the end of this UniqueId.

protected Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static UniqueId
forEngine(String
the engine ID; never null or blank
engineId
)

Create an engine's unique ID from its engineId using the default format.

public Optional<String>
getEngineId()

Get the engine ID stored in this UniqueId, if available.

public UniqueId.Segment

Returns:

the last Segment; never null
getLastSegment
()

Get the last Segment of this UniqueId.

pack-priv Optional<UniqueId.Segment>
public List<UniqueId.Segment>
getSegments()

Get the immutable list of segments that make up this UniqueId.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
hasPrefix(UniqueId
the UniqueId to be checked; never null
potentialPrefix
)

Determine if the supplied UniqueId is a prefix for this UniqueId.

public static UniqueId

Returns:

a properly constructed UniqueId
parse
(String
the string representation to parse; never null or blank
uniqueId
)

Parse a UniqueId from the supplied string representation using the default format.

public UniqueId

Returns:

a new UniqueId; never null
removeLastSegment
()

Construct a new UniqueId and removing the last Segment of this UniqueId.

public static UniqueId
root(String
the segment type; never null or blank
segmentType
,
String
the value; never null or blank
value
)

Create a root unique ID from the supplied segmentType and value using the default format.

public String
toString()

Overrides java.lang.Object.toString.

Generate the unique, formatted string representation of this UniqueId using the configured UniqueIdFormat.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ENGINE_SEGMENT_TYPEback to summary
private static final String ENGINE_SEGMENT_TYPE
hashCodeback to summary
private transient int hashCode
segmentsback to summary
private final List<UniqueId.Segment> segments
Annotations
@SuppressWarnings:serial, RedundantSuppression
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
toStringback to summary
private transient @Nullable SoftReference<String> toString
uniqueIdFormatback to summary
private final UniqueIdFormat uniqueIdFormat

Constructor Detail

UniqueIdback to summary
private UniqueId(UniqueIdFormat uniqueIdFormat, UniqueId.Segment segment)
UniqueIdback to summary
pack-priv UniqueId(UniqueIdFormat uniqueIdFormat, List<UniqueId.Segment> segments)

Initialize a UniqueId instance.

Implementation Note

A defensive copy of the segment list is not created by this implementation. All callers should immediately drop the reference to the list instance that they pass into this constructor.

Method Detail

appendback to summary
public UniqueId append(String segmentType, String value)

Construct a new UniqueId by appending a new 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.

Parameters
segmentType:String

the type of the segment; never null or blank

value:String

the value of the segment; never null or blank

appendback to summary
public UniqueId append(UniqueId.Segment segment)

Construct a new UniqueId by appending a new Segment to the end of this UniqueId.

This UniqueId will not be modified.

Parameters
segment:UniqueId.Segment

the segment to be appended; never null

Annotations
@API
status:STABLE
since:1.1
Since
1.1
appendEngineback to summary
public UniqueId appendEngine(String engineId)

Construct a new UniqueId by appending a new Segment, based on the supplied engineId, to the end of this UniqueId.

This UniqueId will not be modified.

The engine ID will be stored in a Segment with type engine.

Parameters
engineId:String

the engine ID; never null or blank

Annotations
@API
status:STABLE
since:1.10
Since
1.8
cloneback to summary
protected Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Annotations
@Override
Exceptions
CloneNotSupportedException:
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
forEngineback to summary
public static UniqueId forEngine(String engineId)

Create an engine's unique ID from its engineId using the default format.

The engine ID will be stored in a Segment with type "engine".

Parameters
engineId:String

the engine ID; never null or blank

See Also
root(String, String)
getEngineIdback to summary
public Optional<String> getEngineId()

Get the engine ID stored in this UniqueId, if available.

See Also
forEngine(String)
getLastSegmentback to summary
public UniqueId.Segment getLastSegment()

Get the last Segment of this UniqueId.

Returns:UniqueId.Segment

the last Segment; never null

Annotations
@API
status:STABLE
since:1.5
Since
1.5
getRootback to summary
pack-priv Optional<UniqueId.Segment> getRoot()
getSegmentsback to summary
public List<UniqueId.Segment> getSegments()

Get the immutable list of segments that make up this UniqueId.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
hasPrefixback to summary
public boolean hasPrefix(UniqueId potentialPrefix)

Determine if the supplied UniqueId is a prefix for this UniqueId.

Parameters
potentialPrefix:UniqueId

the UniqueId to be checked; never null

Annotations
@API
status:STABLE
since:1.1
Since
1.1
parseback to summary
public static UniqueId parse(String uniqueId) throws JUnitException

Parse a UniqueId from the supplied string representation using the default format.

Parameters
uniqueId:String

the string representation to parse; never null or blank

Returns:UniqueId

a properly constructed UniqueId

Exceptions
JUnitException:
if the string cannot be parsed
removeLastSegmentback to summary
public UniqueId removeLastSegment()

Construct a new UniqueId and removing the last Segment of this UniqueId.

This UniqueId will not be modified.

Returns:UniqueId

a new UniqueId; never null

Annotations
@API
status:STABLE
since:1.5
Exceptions
PreconditionViolationException:
if this UniqueId contains a single segment
Since
1.5
rootback to summary
public static UniqueId root(String segmentType, String value)

Create a root unique ID from the supplied segmentType and value using the default format.

Parameters
segmentType:String

the segment type; never null or blank

value:String

the value; never null or blank

See Also
forEngine(String)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Generate the unique, formatted string representation of this UniqueId using the configured UniqueIdFormat.

Annotations
@Override
org.junit.platform.engine back to summary

public final Class UniqueId.Segment

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@API
status:STABLE
since:1.0

A segment of a UniqueId comprises a type and a value.

Field Summary

Modifier and TypeField and Description
private static final long
private final String
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
Segment(String
the type of this segment
type
,
String
the value of this segment
value
)

Create a new Segment using the supplied type and value.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
getType()

Get the type of this segment.

public String
getValue()

Get the value of this segment.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial
typeback to summary
private final String type
valueback to summary
private final String value

Constructor Detail

Segmentback to summary
pack-priv Segment(String type, String value)

Create a new Segment using the supplied type and value.

Parameters
type:String

the type of this segment

value:String

the value of this segment

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getTypeback to summary
public String getType()

Get the type of this segment.

getValueback to summary
public String getValue()

Get the value of this segment.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override