Package org.jboss.logging.processor.util
Class Comparison
- java.lang.Object
-
- org.jboss.logging.processor.util.Comparison
-
- Direct Known Subclasses:
Comparison.DeadComparison
public abstract class Comparison extends java.lang.Object
Date: 30.08.2011
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Comparison.DeadComparison
-
Field Summary
Fields Modifier and Type Field Description private static Comparison
ALLOW_NULL_INSTANCE
static int
EQUAL
static int
GREATER
private static Comparison
GREATER_COMPARISON
private static Comparison
INSTANCE
static int
LESS
private static Comparison
LESS_COMPARISON
-
Constructor Summary
Constructors Modifier Constructor Description private
Comparison()
Private constructor for singleton pattern.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Comparison
begin()
Begins a new comparison.static Comparison
beginAllowNull()
Begins a new comparison, but allows fornull
values to be passed.private Comparison
checkResult(int result)
Checks to see which comparison to return.Comparison
compare(boolean left, boolean right)
Compares the left boolean to the double boolean.Comparison
compare(double left, double right)
Compares the left double to the double integer.Comparison
compare(float left, float right)
Compares the left float to the float integer.Comparison
compare(int left, int right)
Compares the left integer to the right integer.Comparison
compare(long left, long right)
Compares the left long to the right long.abstract Comparison
compare(java.lang.Comparable<?> left, java.lang.Comparable<?> right)
Compares the left comparable to the right as specified by theComparable.compareTo(Object)
interface.abstract <T> Comparison
compare(T left, T right, java.util.Comparator<T> comparator)
Compares the left object to the right object as specified by theComparator.compare(Object, Object)
interface.protected abstract Comparison
getInstance()
Returns the comparison instance being used.int
result()
Ends the comparison and returns 0 if all comparisons were equal, -1 if the any of the left comparisons were less than the right comparisons or 1 if any of the right comparisons were less than the left.
-
-
-
Field Detail
-
EQUAL
public static final int EQUAL
- See Also:
- Constant Field Values
-
LESS
public static final int LESS
- See Also:
- Constant Field Values
-
GREATER
public static final int GREATER
- See Also:
- Constant Field Values
-
LESS_COMPARISON
private static final Comparison LESS_COMPARISON
-
GREATER_COMPARISON
private static final Comparison GREATER_COMPARISON
-
ALLOW_NULL_INSTANCE
private static final Comparison ALLOW_NULL_INSTANCE
-
INSTANCE
private static final Comparison INSTANCE
-
-
Method Detail
-
begin
public static Comparison begin()
Begins a new comparison.- Returns:
- the comparison.
-
beginAllowNull
public static Comparison beginAllowNull()
Begins a new comparison, but allows fornull
values to be passed.If the first value is
null
and the second value isnon-null
, the comparison will return -1. If the first value isnon-null
and the second value isnull
, the comparison will return 1. If both values arenull
0 is returned.- Returns:
- the comparison.
-
compare
public abstract Comparison compare(java.lang.Comparable<?> left, java.lang.Comparable<?> right)
Compares the left comparable to the right as specified by theComparable.compareTo(Object)
interface.- Parameters:
left
- the object to compare to the right.right
- the object compared to the left.- Returns:
- the the same instance if the objects are equal, otherwise a comparison that will return a defined value.
-
compare
public abstract <T> Comparison compare(T left, T right, java.util.Comparator<T> comparator)
Compares the left object to the right object as specified by theComparator.compare(Object, Object)
interface.- Type Parameters:
T
- the type of the object to the compared.- Parameters:
left
- the object to compare to the right.right
- the object compared to the left.comparator
- the comparator used to compare the objects.- Returns:
- the the same instance if the objects are equal, otherwise a comparison that will return a defined value.
-
compare
public Comparison compare(int left, int right)
Compares the left integer to the right integer.- Parameters:
left
- the integer to compare to the right.right
- the integer compared to the left.- Returns:
- the the same instance if the integers are equal, otherwise a comparison that will return a defined value.
-
compare
public Comparison compare(long left, long right)
Compares the left long to the right long.- Parameters:
left
- the long to compare to the right.right
- the long compared to the left.- Returns:
- the the same instance if the longs are equal, otherwise a comparison that will return a defined value.
-
compare
public Comparison compare(float left, float right)
Compares the left float to the float integer.- Parameters:
left
- the float to compare to the right.right
- the float compared to the left.- Returns:
- the the same instance if the floats are equal, otherwise a comparison that will return a defined value.
-
compare
public Comparison compare(double left, double right)
Compares the left double to the double integer.- Parameters:
left
- the double to compare to the right.right
- the double compared to the left.- Returns:
- the the same instance if the doubles are equal, otherwise a comparison that will return a defined value.
-
compare
public Comparison compare(boolean left, boolean right)
Compares the left boolean to the double boolean.- Parameters:
left
- the boolean to compare to the right.right
- the boolean compared to the left.- Returns:
- the the same instance if the booleans are equal, otherwise a comparison that will return a defined value.
-
result
public int result()
Ends the comparison and returns 0 if all comparisons were equal, -1 if the any of the left comparisons were less than the right comparisons or 1 if any of the right comparisons were less than the left.- Returns:
- zero if equal, otherwise the a value with the same sign as the first non-equal comparison.
-
getInstance
protected abstract Comparison getInstance()
Returns the comparison instance being used.- Returns:
- the comparison instance being used.
-
checkResult
private Comparison checkResult(int result)
Checks to see which comparison to return.- Parameters:
result
- the result of the comparison.- Returns:
- the comparison that should be used.
-
-