net.sf.ivmaidns.util
Class GComparator
java.lang.Object
net.sf.ivmaidns.util.GComparator
- All Implemented Interfaces:
- java.io.Serializable, Immutable
- Direct Known Subclasses:
- DNSRecAltCmp, StrComparator
public class GComparator
- extends java.lang.Object
- implements Immutable, java.io.Serializable
Class for 'greater-than' comparators.
A binary predicate, which tests whether the first its argument is
greater than the second one, should extend this adapter class and
override greater(Object, Object)
, implementing own
comparison rules. Immutable
interface is implemented
to underline that such comparators must have constant internal
state. The comparators may be used in serializable data
structures since Serializable
interface is
implemented. In addition, this class provides the default
comparator for objects of Sortable
interface, and of
String
class and of the standard wrappers for the
primitive types.
- Since:
- 1.8
- Version:
- 2.0
- Author:
- Ivan Maidanski
- See Also:
Sortable
,
StrComparator
,
Serialized Form
Constructor Summary |
GComparator()
Constructs a new comparator. |
Method Summary |
boolean |
greater(java.lang.Object objA,
java.lang.Object objB)
The body of 'Greater-Than' comparator. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
INSTANCE
public static final GComparator INSTANCE
- The standard comparator for objects.
This constant field is initialized with the instantiation of
exactly this comparator. The implemented standard comparator
correctly orders any two objects of the class which implements
Sortable
interface, or both of String
class, or both of the same primary-type value wrapper.
- See Also:
greater(java.lang.Object, java.lang.Object)
GComparator
public GComparator()
- Constructs a new comparator.
This constructor is made
public
to allow custom
dynamic instantiation of this class.
- See Also:
INSTANCE
greater
public boolean greater(java.lang.Object objA,
java.lang.Object objB)
- The body of 'Greater-Than' comparator.
Tests whether or not the first specified object is greater than
the second one (according to the semantics). This method should
be overridden in the adapter subclasses. If any argument is not
instance of the expected type then standard comparison should be
performed (which is implemented in this method of this class).
The standard comparison of two objects is as follows: if
objA == objB
then false
is returned
else if objA is instance of Sortable
then
greaterThan(objB)
for objA is returned
else if objB is instance of Sortable
then
!greaterThan(objA)
for objB is returned,
else if objA is null
then
true
is returned, else if objA and
objB are both of the same class (either
Boolean
, Byte
, Short
,
Integer
, Long
, Float
,
Double
, Character
or
String
) and the first (primary) value is greater
than the second one then true
else
false
is returned. Important notes:
String
objects are compared here in the
case-sensitive manner; Float
and Double
objects are compared here handling their zero and
NaN
values specially (0
is greater than
-0
and NaN
is greater than
non-NaN
).
- Parameters:
objA
- the first compared argument (may be null
).objB
- the second compared argument (may be null
).
- Returns:
true
if and only if objA is greater than
objB.- See Also:
INSTANCE