Class ChainedComparator
java.lang.Object
org.moeaframework.core.comparator.ChainedComparator
- All Implemented Interfaces:
DominanceComparator
- Direct Known Subclasses:
LinearDominanceComparator
,MinMaxDominanceComparator
,NondominatedSortingComparator
,ParetoDominanceComparator
Applies any number of comparators in succession, returning the result from the first comparator producing a non-zero
return value. If no comparators produce a non-zero return value,
0
is returned.
For example, the following:
Comparator comparator = new ChainedComparator(comparator1, comparator2); return comparator.compare(s1, s2);is equivalent to
int flag1 = comparator1.compare(s1, s2); if (flag1 == 0) { return comparator2.compare(s1, s2); } else { return flag1; }
-
Field Summary
Modifier and TypeFieldDescriptionprotected DominanceComparator[]
The comparators in the order they are to be applied. -
Constructor Summary
ConstructorDescriptionChainedComparator
(DominanceComparator... comparators) Constructs a chained comparator for applying the specified comparators in order, returning the result from the first comparator producing a non-zero return value. -
Method Summary
-
Field Details
-
comparators
The comparators in the order they are to be applied.
-
-
Constructor Details
-
ChainedComparator
Constructs a chained comparator for applying the specified comparators in order, returning the result from the first comparator producing a non-zero return value. If no comparators produce a non-zero return value,0
is returned.- Parameters:
comparators
- the comparators in the order they are to be applied
-
-
Method Details
-
compare
Description copied from interface:DominanceComparator
Compares the two solutions using a dominance relation, returning-1
ifsolution1
dominatessolution2
,1
ifsolution2
dominatessolution1
, and0
if the solutions are non-dominated.- Specified by:
compare
in interfaceDominanceComparator
- Parameters:
solution1
- the first solutionsolution2
- the second solution- Returns:
-1
ifsolution1
dominatessolution2
,1
ifsolution2
dominatessolution1
, and0
if the solutions are non-dominated
-