Decouple HashCodeBuilder from Builder 27/99327/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Jan 2022 16:09:58 +0000 (17:09 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Jan 2022 16:10:59 +0000 (17:10 +0100)
We are deprecating Builder concept and HashCodeBuilder does not really
like having to inflate to java.lang.Integer. Ditch the indirection.

JIRA: YANGTOOLS-1327
Change-Id: Ia19d9d97064cb099c25f11dac6aa7c08e983effd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/src/main/java/org/opendaylight/yangtools/util/HashCodeBuilder.java
common/util/src/test/java/org/opendaylight/yangtools/util/HashCodeBuilderTest.java

index 5bd02335465bf8b81d020011a0ee691c786aec03..650c00e15043ee43a99709bec8047c30bddd77d4 100644 (file)
@@ -7,15 +7,12 @@
  */
 package org.opendaylight.yangtools.util;
 
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Builder;
-
 /**
  * Utility class for incrementally building object hashCode by hashing together component objects, one by one.
  *
  * @param <T> Component object type
  */
-public final class HashCodeBuilder<T> implements Builder<Integer> {
+public final class HashCodeBuilder<T> {
     /**
      * The value 31 was chosen because it is an odd prime. If it were even and the multiplication overflowed,
      * information would be lost, as multiplication by 2 is equivalent to shifting. The advantage of using a prime is
@@ -65,8 +62,12 @@ public final class HashCodeBuilder<T> implements Builder<Integer> {
         currentHash = nextHashCode(currentHash, obj);
     }
 
-    @Override
-    public @NonNull Integer build() {
+    /**
+     * Return the currently-accumulated hash code.
+     *
+     * @return Current hash code
+     */
+    public int build() {
         return currentHash;
     }
 }
index 4863357d13344198f2df47bc33d719a24d56a102..5c5be21eacad4646f44ebca6396f4248f6156c6b 100644 (file)
@@ -12,16 +12,15 @@ import static org.junit.Assert.assertEquals;
 import org.junit.Test;
 
 public class HashCodeBuilderTest {
-
     @Test
     public void testAllMethodsOfHashCodeBuilder() {
         final HashCodeBuilder<String> builder = new HashCodeBuilder<>();
-        assertEquals("Default hash code should be '1'.", 1, builder.build().intValue());
+        assertEquals("Default hash code should be '1'.", 1, builder.build());
 
         int nextHashCode = HashCodeBuilder.nextHashCode(1, "test");
         assertEquals("Next hash code should be '3556529'.", 3556529, nextHashCode);
 
         builder.addArgument("another test");
-        assertEquals("Updated internal hash code should be '700442706'.", -700442706, builder.build().intValue());
+        assertEquals("Updated internal hash code should be '700442706'.", -700442706, builder.build());
     }
 }