Class IntArrayWrapper


  • public final class IntArrayWrapper
    extends java.lang.Object
    A wrapper class for integer arrays so that they can be used inside collections. The default Object.equals(Object) and Object.hashCode() implementation depend only on the storage location of an array and thus comparing to arrays via equals does not make sense and the hash code does not help either. This class just wraps the array and uses Arrays.equals(int[], int[]) and Arrays.hashCode(int[]).
    • Constructor Summary

      Constructors 
      Constructor Description
      IntArrayWrapper​(int[] array)
      Creates a new wrapper with the array.
    • Constructor Detail

      • IntArrayWrapper

        public IntArrayWrapper​(int[] array)
        Creates a new wrapper with the array. The array can be modified from the outside as not copy is used for performance reasons.
        Parameters:
        array - the array to wrap
    • Method Detail

      • getArray

        public int[] getArray()
      • wrap

        public static IntArrayWrapper wrap​(int[] array)
        Convenience method for wrapping a int[] into a IntArrayWrapper.
        Parameters:
        array - the array to wrap
        Returns:
        the wrapped array
      • wrapToList

        public static java.util.List<IntArrayWrapper> wrapToList​(java.util.Collection<int[]> arrays)
        Convenience method for wrapping all int[] in a collection into a list.
        Parameters:
        arrays - the arrays to wrap
        Returns:
        a list containing the wrapped arrays
      • wrapToSet

        public static java.util.Set<IntArrayWrapper> wrapToSet​(java.util.Collection<int[]> arrays)
        Convenience method for wrapping all int[] in a collection into a set. As the wrappers contain sensible hashcode and equals functions, no duplicates are present in the set.
        Parameters:
        arrays - the arrays to wrap
        Returns:
        a set containing the wrapped arrays
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object