Class IntArrayWrapper
- java.lang.Object
-
- de.rwth.swc.coffee4j.algorithmic.util.IntArrayWrapper
-
public final class IntArrayWrapper extends Object
A wrapper class for integer arrays so that they can be used inside collections. The defaultObject.equals(Object)
andObject.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 usesArrays.equals(int[], int[])
andArrays.hashCode(int[])
.
-
-
Constructor Summary
Constructors Constructor Description IntArrayWrapper(int[] array)
Creates a new wrapper with the array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
int[]
getArray()
int
hashCode()
String
toString()
static IntArrayWrapper
wrap(int... array)
Convenience method for wrapping a int[] into aIntArrayWrapper
.static List<IntArrayWrapper>
wrapToList(Collection<int[]> arrays)
Convenience method for wrapping all int[] in a collection into a list.static Set<IntArrayWrapper>
wrapToSet(Collection<int[]> arrays)
Convenience method for wrapping all int[] in a collection into a set.
-
-
-
Method Detail
-
getArray
public int[] getArray()
-
wrap
public static IntArrayWrapper wrap(int... array)
Convenience method for wrapping a int[] into aIntArrayWrapper
.- Parameters:
array
- the array to wrap- Returns:
- the wrapped array
-
wrapToList
public static List<IntArrayWrapper> wrapToList(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 Set<IntArrayWrapper> wrapToSet(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
-
-