Package eu.simuline.util
Class ArraysExt.ArrayComparator<O>
- java.lang.Object
-
- eu.simuline.util.ArraysExt.ArrayComparator<O>
-
- Type Parameters:
O- Some object type to be compared.
- All Implemented Interfaces:
Comparator<O[]>
static class ArraysExt.ArrayComparator<O> extends Object implements Comparator<O[]>
Comparator class which implements a kind of lexical ordering on arrays based on the ordering of the components defined byatomic.
-
-
Field Summary
Fields Modifier and Type Field Description private Comparator<Object>atomicAComparatorfor components of an array.
-
Constructor Summary
Constructors Constructor Description ArrayComparator(Comparator<Object> atomic)Creates a newArrayComparatorto compare two object-arrays by lexical ordering.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompare(Object[] arr1, Object[] arr2)Describecomparemethod here.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Field Detail
-
atomic
private final Comparator<Object> atomic
AComparatorfor components of an array. This is allocated by the constructorArrayComparator(Comparator).
-
-
Constructor Detail
-
ArrayComparator
ArrayComparator(Comparator<Object> atomic)
Creates a newArrayComparatorto compare two object-arrays by lexical ordering. Here, the orderin of the components is defined byatomic.- Parameters:
atomic- aComparatorfor components of an array.
-
-
Method Detail
-
compare
public int compare(Object[] arr1, Object[] arr2)
Describecomparemethod here.- Specified by:
comparein interfaceComparator<O>- Parameters:
arr1- anObject[]object. The componentso1[i]ando2[i]must be pairwise comparable with respect toatomicprovided botho1[i]ando2[i]exist.arr2- anObject[]object. The componentso1[i]ando2[i]must be pairwise comparable with respect toatomicprovided botho1[i]ando2[i]exist.- Returns:
0if and only ifo1.length == o2.lengthandatomic.compare(o1[i], o2[i]) == 0for all indicesi. Hence this comparator is consistent with equals if and only if this is true foratomic.-1resp.1ifo1is a true prefix ofo2res. the other way round.atomic.compare(o1[i], o2[i])whereiis the lowest index such thatatomic.compare(o1[i], o2[i]) != 0. (Provided such an index in the common range exists. )
- Throws:
NullPointerException- if one of the arguments isnull.ClassCastException- if one of the arguments is noObject[]. in particular for typeint[].
-
-