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:
java.util.Comparator<O[]>
static class ArraysExt.ArrayComparator<O> extends java.lang.Object implements java.util.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 java.util.Comparator<java.lang.Object>atomicAComparatorfor components of an array.
-
Constructor Summary
Constructors Constructor Description ArrayComparator(java.util.Comparator<java.lang.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(java.lang.Object[] arr1, java.lang.Object[] arr2)Describecomparemethod here.
-
-
-
Field Detail
-
atomic
private final java.util.Comparator<java.lang.Object> atomic
AComparatorfor components of an array. This is allocated by the constructorArrayComparator(Comparator).
-
-
Method Detail
-
compare
public int compare(java.lang.Object[] arr1, java.lang.Object[] arr2)Describecomparemethod here.- Specified by:
comparein interfacejava.util.Comparator<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:
java.lang.NullPointerException- if one of the arguments isnull.java.lang.ClassCastException- if one of the arguments is noObject[]. in particular for typeint[].
-
-