*/
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
currentHash = nextHashCode(currentHash, obj);
}
- @Override
- public @NonNull Integer build() {
+ /**
+ * Return the currently-accumulated hash code.
+ *
+ * @return Current hash code
+ */
+ public int build() {
return currentHash;
}
}
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());
}
}