3838public final class UniqueId implements Cloneable , Serializable {
3939
4040 @ Serial
41- private static final long serialVersionUID = 1L ;
41+ private static final long serialVersionUID = 2L ;
4242
4343 private static final String ENGINE_SEGMENT_TYPE = "engine" ;
4444
@@ -79,11 +79,9 @@ public static UniqueId forEngine(String engineId) {
7979 * @see #forEngine(String)
8080 */
8181 public static UniqueId root (String segmentType , String value ) {
82- return new UniqueId (UniqueIdFormat . getDefault (), new Segment (segmentType , value ));
82+ return new UniqueId (new Segment (segmentType , value ));
8383 }
8484
85- private final UniqueIdFormat uniqueIdFormat ;
86-
8785 @ SuppressWarnings ({ "serial" , "RedundantSuppression" }) // always used with serializable implementation (List.copyOf())
8886 private final List <Segment > segments ;
8987
@@ -93,19 +91,14 @@ public static UniqueId root(String segmentType, String value) {
9391 // lazily computed
9492 private transient @ Nullable SoftReference <String > toString ;
9593
96- private UniqueId (UniqueIdFormat uniqueIdFormat , Segment segment ) {
97- this (uniqueIdFormat , List .of (segment ));
94+ private UniqueId (Segment segment ) {
95+ this (List .of (segment ));
9896 }
9997
10098 /**
10199 * Initialize a {@code UniqueId} instance.
102- *
103- * @implNote A defensive copy of the segment list is <b>not</b> created by
104- * this implementation. All callers should immediately drop the reference
105- * to the list instance that they pass into this constructor.
106100 */
107- UniqueId (UniqueIdFormat uniqueIdFormat , List <Segment > segments ) {
108- this .uniqueIdFormat = uniqueIdFormat ;
101+ UniqueId (List <Segment > segments ) {
109102 this .segments = List .copyOf (segments );
110103 }
111104
@@ -164,7 +157,7 @@ public UniqueId append(Segment segment) {
164157 List <Segment > baseSegments = new ArrayList <>(this .segments .size () + 1 );
165158 baseSegments .addAll (this .segments );
166159 baseSegments .add (segment );
167- return new UniqueId (this . uniqueIdFormat , baseSegments );
160+ return new UniqueId (baseSegments );
168161 }
169162
170163 /**
@@ -215,7 +208,7 @@ public boolean hasPrefix(UniqueId potentialPrefix) {
215208 @ API (status = STABLE , since = "1.5" )
216209 public UniqueId removeLastSegment () {
217210 Preconditions .condition (this .segments .size () > 1 , "Cannot remove last remaining segment" );
218- return new UniqueId (uniqueIdFormat , List . copyOf ( this .segments .subList (0 , this .segments .size () - 1 ) ));
211+ return new UniqueId (this .segments .subList (0 , this .segments .size () - 1 ));
219212 }
220213
221214 /**
@@ -277,7 +270,7 @@ public String toString() {
277270 SoftReference <String > s = this .toString ;
278271 String value = s == null ? null : s .get ();
279272 if (value == null ) {
280- value = this . uniqueIdFormat .format (this );
273+ value = UniqueIdFormat . getDefault () .format (this );
281274 // this is a benign race like String#hash
282275 // we potentially read and write values from multiple threads
283276 // without a happens-before relationship
0 commit comments