Apache9 commented on code in PR #7575:
URL: https://github.com/apache/hbase/pull/7575#discussion_r2651120794


##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/CoprocessorDescriptorBuilder.java:
##########
@@ -111,5 +114,34 @@ public String toString() {
       return "class:" + className + ", jarPath:" + jarPath + ", priority:" + 
priority
         + ", properties:" + properties;
     }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (this == obj) {
+        return true;
+      }
+      if (!(obj instanceof CoprocessorDescriptor)) {
+        return false;
+      }
+      CoprocessorDescriptor other = (CoprocessorDescriptor) obj;
+      if (
+        priority != other.getPriority() || !Objects.equals(className, 
other.getClassName())
+          || !Objects.equals(getJarPath(), other.getJarPath())
+      ) {
+        return false;
+      }
+      return Objects.equals(getProperties(), other.getProperties());
+    }
+
+    @Override
+    public int hashCode() {
+      int result = Objects.hash(className, jarPath, priority);
+      List<Map.Entry<String, String>> entries = new 
ArrayList<>(properties.entrySet());

Review Comment:
   I think it is related. We want to make sure the hash code calculation is 
stable, so here we want to sort the entries before calculating. Since we 
already use TreeMap in CoprocessorDescriptorBuilder, we can make sure that the 
Map in CoprocessorDescriptor is a TreeMap, which is sorted, so we do not need 
to sort it again.
   
   To prevent later developers break the assumption, i.e, changing the TreeMap 
to HashMap in CoprocessorDescriptorBuilder without any compilation errors, we'd 
better change the declaration in CoprocessorDescriptor to SortedMap or 
NavigableMap, so the constructor will not accept a HashMap any more. And we 
could also add some comments to explain that we must use SortedMap here as  we 
need it for a stable hash code calculation.
   
   Thanks.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to