diff --git a/vavr-benchmark/src/test/java/io/vavr/other/HashCodes.java b/vavr-benchmark/src/test/java/io/vavr/other/HashCodes.java new file mode 100644 index 0000000000..bc0a3e6efe --- /dev/null +++ b/vavr-benchmark/src/test/java/io/vavr/other/HashCodes.java @@ -0,0 +1,465 @@ +package io.vavr.other; + +import java.util.List; +import java.util.Objects; + +// TODO should we generate this file and add more permutations of parameter types? + +/** + * Utility that allows to compute hashcodes without var-arg conversion into arrays for common + * types of vavr. + * + * @author Sebastian Zarnekow + */ +final class HashCodes { + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Integer#hashCode() + */ + public static int hash(int value) { + return Integer.hashCode(value); + } + + /** + * Return the order-dependent hash of the two given integers. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(int v1, int v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Long#hashCode() + */ + public static int hash(long value) { + return Long.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Byte#hashCode() + */ + public static int hash(byte value) { + return Byte.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Short#hashCode() + */ + public static int hash(short value) { + return Short.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Character#hashCode() + */ + public static int hash(char value) { + return Character.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Boolean#hashCode() + */ + public static int hash(boolean value) { + return Boolean.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Float#hashCode() + */ + public static int hash(float value) { + return Float.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Double#hashCode() + */ + public static int hash(double value) { + return Double.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Objects#hashCode() + */ + public static int hash(Object value) { + return Objects.hashCode(value); + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(int v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(long v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(byte v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(short v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(char v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(boolean v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(float v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(double v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the three given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @param v7 the seventh value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + result = 31 * result + hash(v7); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @param v7 the seventh value to hash + * @param v8 the eighth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7, Object v8) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + result = 31 * result + hash(v7); + result = 31 * result + hash(v8); + return result; + } + +} diff --git a/vavr-benchmark/src/test/java/io/vavr/other/ObjectsBenchmark.java b/vavr-benchmark/src/test/java/io/vavr/other/ObjectsBenchmark.java index fe2d9b3c2d..bba84f602b 100644 --- a/vavr-benchmark/src/test/java/io/vavr/other/ObjectsBenchmark.java +++ b/vavr-benchmark/src/test/java/io/vavr/other/ObjectsBenchmark.java @@ -22,7 +22,6 @@ import io.vavr.API; import io.vavr.JmhRunner; import io.vavr.collection.Array; -import io.vavr.control.HashCodes; import org.junit.Test; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; diff --git a/vavr/generator/Generator.scala b/vavr/generator/Generator.scala index 66d293ff71..1b0e369530 100644 --- a/vavr/generator/Generator.scala +++ b/vavr/generator/Generator.scala @@ -2058,7 +2058,7 @@ def generateMainClasses(): Unit = { @Override public int hashCode() { - return ${if (i == 0) "1" else s"""${im.getType("io.vavr.control.HashCodes")}.hash(${(1 to i).gen(j => s"_$j")(", ")})"""}; + return ${if (i == 0) "1" else s"""${im.getType("io.vavr.HashCodes")}.hash(${(1 to i).gen(j => s"_$j")(", ")})"""}; } @Override diff --git a/vavr/src-gen/main/java/io/vavr/Tuple1.java b/vavr/src-gen/main/java/io/vavr/Tuple1.java index 89a430cad4..6fcfb42b8d 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple1.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple1.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.Comparator; import java.util.Objects; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple2.java b/vavr/src-gen/main/java/io/vavr/Tuple2.java index 1e63d14bef..a9fcaf19a7 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple2.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple2.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.AbstractMap; import java.util.Comparator; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple3.java b/vavr/src-gen/main/java/io/vavr/Tuple3.java index dd7cb0458a..8609cd7139 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple3.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple3.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.Comparator; import java.util.Objects; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple4.java b/vavr/src-gen/main/java/io/vavr/Tuple4.java index 2274dca7ea..bc590bf119 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple4.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple4.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.Comparator; import java.util.Objects; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple5.java b/vavr/src-gen/main/java/io/vavr/Tuple5.java index 41ac69de76..32af1a616a 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple5.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple5.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.Comparator; import java.util.Objects; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple6.java b/vavr/src-gen/main/java/io/vavr/Tuple6.java index 113fc66e41..407d04e333 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple6.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple6.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.Comparator; import java.util.Objects; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple7.java b/vavr/src-gen/main/java/io/vavr/Tuple7.java index 68caf4e19d..c9b92538f7 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple7.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple7.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.Comparator; import java.util.Objects; diff --git a/vavr/src-gen/main/java/io/vavr/Tuple8.java b/vavr/src-gen/main/java/io/vavr/Tuple8.java index 1dea836561..227bc2116e 100644 --- a/vavr/src-gen/main/java/io/vavr/Tuple8.java +++ b/vavr/src-gen/main/java/io/vavr/Tuple8.java @@ -26,7 +26,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.List; import io.vavr.collection.Seq; -import io.vavr.control.HashCodes; import java.io.Serializable; import java.util.Comparator; import java.util.Objects; diff --git a/vavr/src/main/java/io/vavr/HashCodes.java b/vavr/src/main/java/io/vavr/HashCodes.java new file mode 100644 index 0000000000..2c5ef97d3e --- /dev/null +++ b/vavr/src/main/java/io/vavr/HashCodes.java @@ -0,0 +1,465 @@ +package io.vavr; + +import java.util.List; +import java.util.Objects; + +// TODO should we generate this file and add more permutations of parameter types? + +/** + * Utility that allows to compute hashcodes without var-arg conversion into arrays for common + * types of vavr. + * + * @author Sebastian Zarnekow + */ +final class HashCodes { + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Integer#hashCode() + */ + public static int hash(int value) { + return Integer.hashCode(value); + } + + /** + * Return the order-dependent hash of the two given integers. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(int v1, int v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Long#hashCode() + */ + public static int hash(long value) { + return Long.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Byte#hashCode() + */ + public static int hash(byte value) { + return Byte.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Short#hashCode() + */ + public static int hash(short value) { + return Short.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Character#hashCode() + */ + public static int hash(char value) { + return Character.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Boolean#hashCode() + */ + public static int hash(boolean value) { + return Boolean.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Float#hashCode() + */ + public static int hash(float value) { + return Float.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Double#hashCode() + */ + public static int hash(double value) { + return Double.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Objects#hashCode() + */ + public static int hash(Object value) { + return Objects.hashCode(value); + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(int v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(long v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(byte v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(short v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(char v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(boolean v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(float v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(double v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the three given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @param v7 the seventh value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + result = 31 * result + hash(v7); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @param v7 the seventh value to hash + * @param v8 the eighth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7, Object v8) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + result = 31 * result + hash(v7); + result = 31 * result + hash(v8); + return result; + } + +} diff --git a/vavr/src/main/java/io/vavr/Lazy.java b/vavr/src/main/java/io/vavr/Lazy.java index 54a5d8b365..1b3df681ab 100644 --- a/vavr/src/main/java/io/vavr/Lazy.java +++ b/vavr/src/main/java/io/vavr/Lazy.java @@ -22,7 +22,6 @@ import io.vavr.collection.Iterator; import io.vavr.collection.Seq; import io.vavr.collection.Vector; -import io.vavr.control.HashCodes; import io.vavr.control.Option; import java.io.IOException; @@ -30,7 +29,6 @@ import java.io.Serializable; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; -import java.util.NoSuchElementException; import java.util.Objects; import java.util.function.Consumer; import java.util.function.Function; diff --git a/vavr/src/main/java/io/vavr/collection/Collections.java b/vavr/src/main/java/io/vavr/collection/Collections.java index ed2d0eede3..08ee21c778 100644 --- a/vavr/src/main/java/io/vavr/collection/Collections.java +++ b/vavr/src/main/java/io/vavr/collection/Collections.java @@ -21,7 +21,6 @@ import io.vavr.collection.JavaConverters.ChangePolicy; import io.vavr.collection.JavaConverters.ListView; -import io.vavr.control.HashCodes; import io.vavr.control.Option; import java.util.*; diff --git a/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java b/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java index 62addcf6d8..640d3336ca 100644 --- a/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java +++ b/vavr/src/main/java/io/vavr/collection/HashArrayMappedTrie.java @@ -22,11 +22,9 @@ import io.vavr.Tuple; import io.vavr.Tuple2; import io.vavr.collection.HashArrayMappedTrieModule.EmptyNode; -import io.vavr.control.HashCodes; import io.vavr.control.Option; import java.io.Serializable; -import java.util.Arrays; import java.util.Objects; import static java.lang.Integer.bitCount; diff --git a/vavr/src/main/java/io/vavr/collection/HashCodes.java b/vavr/src/main/java/io/vavr/collection/HashCodes.java new file mode 100644 index 0000000000..3c528b9b19 --- /dev/null +++ b/vavr/src/main/java/io/vavr/collection/HashCodes.java @@ -0,0 +1,465 @@ +package io.vavr.collection; + +import java.util.List; +import java.util.Objects; + +// TODO should we generate this file and add more permutations of parameter types? + +/** + * Utility that allows to compute hashcodes without var-arg conversion into arrays for common + * types of vavr. + * + * @author Sebastian Zarnekow + */ +final class HashCodes { + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Integer#hashCode() + */ + public static int hash(int value) { + return Integer.hashCode(value); + } + + /** + * Return the order-dependent hash of the two given integers. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(int v1, int v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Long#hashCode() + */ + public static int hash(long value) { + return Long.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Byte#hashCode() + */ + public static int hash(byte value) { + return Byte.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Short#hashCode() + */ + public static int hash(short value) { + return Short.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Character#hashCode() + */ + public static int hash(char value) { + return Character.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Boolean#hashCode() + */ + public static int hash(boolean value) { + return Boolean.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Float#hashCode() + */ + public static int hash(float value) { + return Float.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Double#hashCode() + */ + public static int hash(double value) { + return Double.hashCode(value); + } + + /** + * Returns the hashcode of the given value. + * + * @param value the value to hash + * @return the hashcode + * @see Objects#hashCode() + */ + public static int hash(Object value) { + return Objects.hashCode(value); + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(int v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(long v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(byte v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(short v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(char v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(boolean v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(float v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(double v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the two given values. + *
+ * More formally, it returns the value {@code 31 * (31 + hash(v1)) + hash(v2)}. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + return result; + } + + /** + * Return the order-dependent hash of the three given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @param v7 the seventh value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + result = 31 * result + hash(v7); + return result; + } + + /** + * Return the order-dependent hash of the two given values. + *
+ * The hashcode is equivalent to the hashcode of a {@link List} containing the given values. + * + * @param v1 the first value to hash + * @param v2 the second value to hash + * @param v3 the third value to hash + * @param v4 the fourth value to hash + * @param v5 the fifth value to hash + * @param v6 the sixth value to hash + * @param v7 the seventh value to hash + * @param v8 the eighth value to hash + * @return the hashcode + * @see List#hashCode() + * @see java.util.Arrays#hashCode(Object[]) + */ + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7, Object v8) { + int result = 1; + result = 31 * result + hash(v1); + result = 31 * result + hash(v2); + result = 31 * result + hash(v3); + result = 31 * result + hash(v4); + result = 31 * result + hash(v5); + result = 31 * result + hash(v6); + result = 31 * result + hash(v7); + result = 31 * result + hash(v8); + return result; + } + +} diff --git a/vavr/src/main/java/io/vavr/collection/Tree.java b/vavr/src/main/java/io/vavr/collection/Tree.java index f509e38657..262c5f17fa 100644 --- a/vavr/src/main/java/io/vavr/collection/Tree.java +++ b/vavr/src/main/java/io/vavr/collection/Tree.java @@ -25,7 +25,6 @@ import io.vavr.Tuple3; import io.vavr.collection.List.Nil; import io.vavr.collection.Tree.*; -import io.vavr.control.HashCodes; import io.vavr.control.Option; import java.io.*; diff --git a/vavr/src/main/java/io/vavr/control/HashCodes.java b/vavr/src/main/java/io/vavr/control/HashCodes.java index 7f5d676964..1164ccc579 100644 --- a/vavr/src/main/java/io/vavr/control/HashCodes.java +++ b/vavr/src/main/java/io/vavr/control/HashCodes.java @@ -11,7 +11,7 @@ * * @author Sebastian Zarnekow */ -public interface HashCodes { +final class HashCodes { /** * Returns the hashcode of the given value. @@ -20,7 +20,7 @@ public interface HashCodes { * @return the hashcode * @see Integer#hashCode() */ - static int hash(int value) { + public static int hash(int value) { return Integer.hashCode(value); } @@ -37,7 +37,7 @@ static int hash(int value) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(int v1, int v2) { + public static int hash(int v1, int v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -51,7 +51,7 @@ static int hash(int v1, int v2) { * @return the hashcode * @see Long#hashCode() */ - static int hash(long value) { + public static int hash(long value) { return Long.hashCode(value); } @@ -62,7 +62,7 @@ static int hash(long value) { * @return the hashcode * @see Byte#hashCode() */ - static int hash(byte value) { + public static int hash(byte value) { return Byte.hashCode(value); } @@ -73,7 +73,7 @@ static int hash(byte value) { * @return the hashcode * @see Short#hashCode() */ - static int hash(short value) { + public static int hash(short value) { return Short.hashCode(value); } @@ -84,7 +84,7 @@ static int hash(short value) { * @return the hashcode * @see Character#hashCode() */ - static int hash(char value) { + public static int hash(char value) { return Character.hashCode(value); } @@ -95,7 +95,7 @@ static int hash(char value) { * @return the hashcode * @see Boolean#hashCode() */ - static int hash(boolean value) { + public static int hash(boolean value) { return Boolean.hashCode(value); } @@ -106,7 +106,7 @@ static int hash(boolean value) { * @return the hashcode * @see Float#hashCode() */ - static int hash(float value) { + public static int hash(float value) { return Float.hashCode(value); } @@ -117,7 +117,7 @@ static int hash(float value) { * @return the hashcode * @see Double#hashCode() */ - static int hash(double value) { + public static int hash(double value) { return Double.hashCode(value); } @@ -128,7 +128,7 @@ static int hash(double value) { * @return the hashcode * @see Objects#hashCode() */ - static int hash(Object value) { + public static int hash(Object value) { return Objects.hashCode(value); } @@ -145,7 +145,7 @@ static int hash(Object value) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(int v1, Object v2) { + public static int hash(int v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -165,7 +165,7 @@ static int hash(int v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(long v1, Object v2) { + public static int hash(long v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -185,7 +185,7 @@ static int hash(long v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(byte v1, Object v2) { + public static int hash(byte v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -205,7 +205,7 @@ static int hash(byte v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(short v1, Object v2) { + public static int hash(short v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -225,7 +225,7 @@ static int hash(short v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(char v1, Object v2) { + public static int hash(char v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -245,7 +245,7 @@ static int hash(char v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(boolean v1, Object v2) { + public static int hash(boolean v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -265,7 +265,7 @@ static int hash(boolean v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(float v1, Object v2) { + public static int hash(float v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -285,7 +285,7 @@ static int hash(float v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(double v1, Object v2) { + public static int hash(double v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -305,7 +305,7 @@ static int hash(double v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(Object v1, Object v2) { + public static int hash(Object v1, Object v2) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -324,7 +324,7 @@ static int hash(Object v1, Object v2) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(Object v1, Object v2, Object v3) { + public static int hash(Object v1, Object v2, Object v3) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -345,7 +345,7 @@ static int hash(Object v1, Object v2, Object v3) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(Object v1, Object v2, Object v3, Object v4) { + public static int hash(Object v1, Object v2, Object v3, Object v4) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -368,7 +368,7 @@ static int hash(Object v1, Object v2, Object v3, Object v4) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(Object v1, Object v2, Object v3, Object v4, Object v5) { + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -393,7 +393,7 @@ static int hash(Object v1, Object v2, Object v3, Object v4, Object v5) { * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6) { + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -420,7 +420,7 @@ static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6 * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7) { + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); @@ -449,7 +449,7 @@ static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6 * @see List#hashCode() * @see java.util.Arrays#hashCode(Object[]) */ - static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7, Object v8) { + public static int hash(Object v1, Object v2, Object v3, Object v4, Object v5, Object v6, Object v7, Object v8) { int result = 1; result = 31 * result + hash(v1); result = 31 * result + hash(v2); diff --git a/vavr/src/test/java/io/vavr/TupleTest.java b/vavr/src/test/java/io/vavr/TupleTest.java index 3743720f16..7ee25454a4 100644 --- a/vavr/src/test/java/io/vavr/TupleTest.java +++ b/vavr/src/test/java/io/vavr/TupleTest.java @@ -20,7 +20,6 @@ package io.vavr; import io.vavr.collection.List; -import io.vavr.control.HashCodes; import org.assertj.core.api.Assertions; import org.junit.Test;