ijuma commented on a change in pull request #9566:
URL: https://github.com/apache/kafka/pull/9566#discussion_r523336595



##########
File path: 
clients/src/main/java/org/apache/kafka/common/protocol/types/Struct.java
##########
@@ -266,12 +266,12 @@ public Long getLong(String name) {
         return (Long) get(name);
     }
 
-    public UUID getUUID(BoundField field) {
-        return (UUID) get(field);
+    public Uuid getUUID(BoundField field) {
+        return (Uuid) get(field);
     }
 
-    public UUID getUUID(String name) {
-        return (UUID) get(name);
+    public Uuid getUUID(String name) {

Review comment:
       Should we update the method name too?

##########
File path: clients/src/main/java/org/apache/kafka/common/Uuid.java
##########
@@ -20,101 +20,100 @@
 import java.util.Base64;
 
 /**
- * This class defines an immutable universally unique identifier (UUID). It 
represents a 128-bit value.
- * More specifically, the random UUIDs generated by this class are variant 2 
(Leach-Salz) version 4 UUIDs.
- * This is the same type of UUID as the ones generated by java.util.UUID 
except that the toString() method prints
+ * This class defines an immutable universally unique identifier (Uuid). It 
represents a 128-bit value.
+ * More specifically, the random Uuids generated by this class are variant 2 
(Leach-Salz) version 4 Uuids.
+ * This is the same type of Uuid as the ones generated by java.util.UUID. The 
toString() method prints
  * using the base64 string encoding. Likewise, the fromString method expects a 
base64 string encoding.
  */
-public class UUID {
+public class Uuid {
 
     private static final java.util.UUID SENTINEL_ID_INTERNAL = new 
java.util.UUID(0L, 1L);
 
     /**
-     * A UUID that represents a null or empty UUID. Will never be returned by 
the randomUUID method
+     * A Uuid that represents a null or empty Uuid. Will never be returned by 
the randomUuid method.
      */
-    public static final UUID ZERO_UUID = new UUID(new java.util.UUID(0L, 0L));
+    public static final Uuid ZERO_UUID = new Uuid(0L, 0L);
     private static final java.util.UUID ZERO_ID_INTERNAL = new 
java.util.UUID(0L, 0L);
 
-    private final java.util.UUID uuid;
+    private final long mostSignificantBits;
+    private final long leastSignificantBits;
 
     /**
-     * Constructs a 128-bit type 4 UUID where the first long represents the 
the most significant 64 bits
+     * Constructs a 128-bit type 4 Uuid where the first long represents the 
the most significant 64 bits
      * and the second long represents the least significant 64 bits.
      */
-    public UUID(long mostSigBits, long leastSigBits) {
-        this.uuid = new java.util.UUID(mostSigBits, leastSigBits);
-    }
-
-    private UUID(java.util.UUID uuid) {
-        this.uuid = uuid;
+    public Uuid(long mostSigBits, long leastSigBits) {
+        this.mostSignificantBits = mostSigBits;
+        this.leastSignificantBits = leastSigBits;
     }
 
     /**
-     * Static factory to retrieve a type 4 (pseudo randomly generated) UUID.
+     * Static factory to retrieve a type 4 (pseudo randomly generated) Uuid.
      */
-    public static UUID randomUUID() {
+    public static Uuid randomUuid() {
         java.util.UUID uuid = java.util.UUID.randomUUID();
         while (uuid.equals(SENTINEL_ID_INTERNAL) || 
uuid.equals(ZERO_ID_INTERNAL)) {
             uuid = java.util.UUID.randomUUID();
         }
-        return new UUID(uuid);
+        return new Uuid(uuid.getMostSignificantBits(), 
uuid.getLeastSignificantBits());
     }
 
     /**
-     * Returns the most significant bits of the UUID's 128 value.
+     * Returns the most significant bits of the Uuid's 128 value.
      */
     public long getMostSignificantBits() {
-        return uuid.getMostSignificantBits();
+        return this.mostSignificantBits;
     }
 
     /**
-     * Returns the least significant bits of the UUID's 128 value.
+     * Returns the least significant bits of the Uuid's 128 value.
      */
     public long getLeastSignificantBits() {
-        return uuid.getLeastSignificantBits();
+        return this.leastSignificantBits;
     }
 
     /**
-     * Returns true iff obj is another UUID represented by the same two long 
values.
+     * Returns true iff obj is another Uuid represented by the same two long 
values.
      */
     @Override
     public boolean equals(Object obj) {
         if ((null == obj) || (obj.getClass() != this.getClass()))
             return false;
-        UUID id = (UUID) obj;
-        return this.getMostSignificantBits() == id.getMostSignificantBits() &&
-                this.getLeastSignificantBits() == id.getLeastSignificantBits();
+        Uuid id = (Uuid) obj;
+        return this.mostSignificantBits == id.mostSignificantBits &&
+                this.leastSignificantBits == id.leastSignificantBits;
     }
 
     /**
-     * Returns a hash code for this UUID
+     * Returns a hash code for this Uuid
      */
     @Override
     public int hashCode() {
-        return uuid.hashCode();
+        long xor = mostSignificantBits ^ leastSignificantBits;
+        return (int) (xor >> 32) ^ (int) xor;
     }
 
     /**
-     * Returns a base64 string encoding of the UUID.
+     * Returns a base64 string encoding of the Uuid.
      */
     @Override
     public String toString() {
-        return 
Base64.getUrlEncoder().withoutPadding().encodeToString(getBytesFromUuid(uuid));
+        return 
Base64.getUrlEncoder().withoutPadding().encodeToString(getBytesFromUuid());
     }
 
     /**
-     * Creates a UUID based on a base64 string encoding used in the toString() 
method.
+     * Creates a Uuid based on a base64 string encoding used in the toString() 
method.

Review comment:
       Isn't it better to keep `UUID` in javadoc when we're referring to the 
concept?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to