@@ -16,62 +16,55 @@ public final class SentryId implements JsonSerializable {
1616
1717 public static final SentryId EMPTY_ID = new SentryId (new UUID (0 , 0 ));
1818
19- private final @ NotNull LazyEvaluator <UUID > lazyValue ;
19+ private final @ NotNull LazyEvaluator <String > lazyStringValue ;
2020
2121 public SentryId () {
2222 this ((UUID ) null );
2323 }
2424
2525 public SentryId (@ Nullable UUID uuid ) {
2626 if (uuid != null ) {
27- this .lazyValue = new LazyEvaluator <>(() -> uuid );
27+ this .lazyStringValue = new LazyEvaluator <>(() -> uuidToSentryIdString ( uuid ) );
2828 } else {
29- this .lazyValue = new LazyEvaluator <>(UUID :: randomUUID );
29+ this .lazyStringValue = new LazyEvaluator <>(() -> uuidToSentryIdString ( UUID . randomUUID ()) );
3030 }
3131 }
3232
3333 public SentryId (final @ NotNull String sentryIdString ) {
34- if (sentryIdString .length () != 32 && sentryIdString .length () != 36 ) {
34+ String normalized = StringUtils .normalizeUUID (sentryIdString );
35+ if (normalized .length () != 32 && normalized .length () != 36 ) {
3536 throw new IllegalArgumentException (
3637 "String representation of SentryId has either 32 (UUID no dashes) "
3738 + "or 36 characters long (completed UUID). Received: "
3839 + sentryIdString );
3940 }
40- this .lazyValue =
41- new LazyEvaluator <>(() -> fromStringSentryId (StringUtils .normalizeUUID (sentryIdString )));
41+ this .lazyStringValue = new LazyEvaluator <>(() -> uuidStringToSentryIdString (normalized ));
4242 }
4343
4444 @ Override
4545 public String toString () {
46- return StringUtils . normalizeUUID ( lazyValue . getValue (). toString ()). replace ( "-" , "" );
46+ return lazyStringValue . getValue ();
4747 }
4848
4949 @ Override
5050 public boolean equals (final @ Nullable Object o ) {
5151 if (this == o ) return true ;
5252 if (o == null || getClass () != o .getClass ()) return false ;
5353 SentryId sentryId = (SentryId ) o ;
54- return lazyValue .getValue ().compareTo (sentryId .lazyValue .getValue ()) == 0 ;
54+ return lazyStringValue .getValue ().compareTo (sentryId .lazyStringValue .getValue ()) == 0 ;
5555 }
5656
5757 @ Override
5858 public int hashCode () {
59- return lazyValue .getValue ().hashCode ();
59+ return lazyStringValue .getValue ().hashCode ();
6060 }
6161
62- private @ NotNull UUID fromStringSentryId (@ NotNull String sentryIdString ) {
63- if (sentryIdString .length () == 32 ) {
64- // expected format, SentryId is a UUID without dashes
65- sentryIdString =
66- new StringBuilder (sentryIdString )
67- .insert (8 , "-" )
68- .insert (13 , "-" )
69- .insert (18 , "-" )
70- .insert (23 , "-" )
71- .toString ();
72- }
62+ private @ NotNull String uuidToSentryIdString (@ NotNull UUID uuid ) {
63+ return uuidStringToSentryIdString (uuid .toString ());
64+ }
7365
74- return UUID .fromString (sentryIdString );
66+ private @ NotNull String uuidStringToSentryIdString (@ NotNull String uuidString ) {
67+ return StringUtils .normalizeUUID (uuidString ).replace ("-" , "" );
7568 }
7669
7770 // JsonSerializable
0 commit comments