Package com.google.common.collect
Class ComparisonChain
java.lang.Object
com.google.common.collect.ComparisonChain
Deprecated.
The Google Guava Core Libraries are deprecated and will not be part of the AEM SDK after April 2023
A utility for performing a chained comparison statement. For example:
public int compareTo(Foo that) {
return ComparisonChain.start()
.compare(this.aString, that.aString)
.compare(this.anInt, that.anInt)
.compare(this.anEnum, that.anEnum, Ordering.natural().nullsLast())
.result();
}
The value of this expression will have the same sign as the first nonzero comparison result in the chain, or will be zero if every comparison result was zero.
Performance note: Even though the ComparisonChain caller always
invokes its compare methods unconditionally, the
ComparisonChain implementation stops calling its inputs' compareTo and compare
methods as soon as one of them returns a nonzero result. This optimization is
typically important only in the presence of expensive compareTo and
compare implementations.
See the Guava User Guide article on
ComparisonChain.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionfinal ComparisonChaincompare(boolean left, boolean right) Deprecated.UsecompareFalseFirst(boolean, boolean); or, if the parameters passed are being either negated or reversed, undo the negation or reversal and usecompareTrueFirst(boolean, boolean).abstract ComparisonChaincompare(double left, double right) Deprecated.Compares twodoublevalues as specified byDouble.compare(double, double), if the result of this comparison chain has not already been determined.abstract ComparisonChaincompare(float left, float right) Deprecated.Compares twofloatvalues as specified byFloat.compare(float, float), if the result of this comparison chain has not already been determined.abstract ComparisonChaincompare(int left, int right) Deprecated.Compares twointvalues as specified byInts.compare(int, int), if the result of this comparison chain has not already been determined.abstract ComparisonChaincompare(long left, long right) Deprecated.Compares twolongvalues as specified byLongs.compare(long, long), if the result of this comparison chain has not already been determined.abstract ComparisonChaincompare(Comparable<?> left, Comparable<?> right) Deprecated.Compares two comparable objects as specified byComparable.compareTo(T), if the result of this comparison chain has not already been determined.abstract <T> ComparisonChaincompare(T left, T right, Comparator<T> comparator) Deprecated.Compares two objects using a comparator, if the result of this comparison chain has not already been determined.abstract ComparisonChaincompareFalseFirst(boolean left, boolean right) Deprecated.Compares twobooleanvalues, consideringfalseto be less thantrue, if the result of this comparison chain has not already been determined.abstract ComparisonChaincompareTrueFirst(boolean left, boolean right) Deprecated.Compares twobooleanvalues, consideringtrueto be less thanfalse, if the result of this comparison chain has not already been determined.abstract intresult()Deprecated.Ends this comparison chain and returns its result: a value having the same sign as the first nonzero comparison result in the chain, or zero if every result was zero.static ComparisonChainstart()Deprecated.Begins a new chained comparison statement.
-
Method Details
-
start
Deprecated.Begins a new chained comparison statement. See example in the class documentation. -
compare
Deprecated.Compares two comparable objects as specified byComparable.compareTo(T), if the result of this comparison chain has not already been determined. -
compare
public abstract <T> ComparisonChain compare(@Nullable T left, @Nullable T right, Comparator<T> comparator) Deprecated.Compares two objects using a comparator, if the result of this comparison chain has not already been determined. -
compare
Deprecated.Compares twointvalues as specified byInts.compare(int, int), if the result of this comparison chain has not already been determined. -
compare
Deprecated.Compares twolongvalues as specified byLongs.compare(long, long), if the result of this comparison chain has not already been determined. -
compare
Deprecated.Compares twofloatvalues as specified byFloat.compare(float, float), if the result of this comparison chain has not already been determined. -
compare
Deprecated.Compares twodoublevalues as specified byDouble.compare(double, double), if the result of this comparison chain has not already been determined. -
compareTrueFirst
Deprecated.Compares twobooleanvalues, consideringtrueto be less thanfalse, if the result of this comparison chain has not already been determined.- Since:
- 12.0
-
compareFalseFirst
Deprecated.Compares twobooleanvalues, consideringfalseto be less thantrue, if the result of this comparison chain has not already been determined.- Since:
- 12.0 (present as
comparesince 2.0)
-
compare
Deprecated.UsecompareFalseFirst(boolean, boolean); or, if the parameters passed are being either negated or reversed, undo the negation or reversal and usecompareTrueFirst(boolean, boolean). This method is scheduled for deletion in September 2013.Old name ofcompareFalseFirst(boolean, boolean). -
result
public abstract int result()Deprecated.Ends this comparison chain and returns its result: a value having the same sign as the first nonzero comparison result in the chain, or zero if every result was zero.
-