net.sf.ivmaidns.dns
Class DNSRecAltCmp

java.lang.Object
  extended by net.sf.ivmaidns.util.GComparator
      extended by net.sf.ivmaidns.dns.DNSRecAltCmp
All Implemented Interfaces:
java.io.Serializable, Immutable, Metricable

public final class DNSRecAltCmp
extends GComparator
implements Metricable

Class for DNS record comparator/metrics (alternative). This final comparator class overrides the default semantics of GComparator class for the case when both of the objects being compared are instances of DNSRecord class. This class also implements Metricable interface to offer records metrics (which is the level of a resource record name plus one). Instead of canonical ordering for records (which is defined in RFC2535 and may be performed through GComparator instance), this comparator offers an alternative records ordering (more convenient for the end users). The alternative ordering differs from the canonical one in just one thing: records rData is compared not as a sequence of bytes but as a sequence of its decoded fields (each field is compared according to its type).

Since:
2.8
Version:
3.0
Author:
Ivan Maidanski
See Also:
DNSRecord, Serialized Form

Field Summary
static GComparator INSTANCE
          An instance of this comparator.
 
Constructor Summary
DNSRecAltCmp()
          Constructs a new comparator.
 
Method Summary
 int evaluate(java.lang.Object obj)
          The body of the metrics.
 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
 

Field Detail

INSTANCE

public static final GComparator INSTANCE
An instance of this comparator. This constant field is initialized with the instantiation of this comparator (hides INSTANCE of the superclass).

See Also:
greater(java.lang.Object, java.lang.Object)
Constructor Detail

DNSRecAltCmp

public DNSRecAltCmp()
Constructs a new comparator. This constructor is made public only to allow custom dynamic instantiation of this class. In other cases, INSTANCE should be used.

See Also:
INSTANCE
Method Detail

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. If both arguments are of DNSRecord class then (objA compareTo(objB, true) > 0) is returned, else greater(objA, objB) of the superclass is returned.

Overrides:
greater in class GComparator
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, evaluate(java.lang.Object)

evaluate

public int evaluate(java.lang.Object obj)
The body of the metrics. Evaluates the supplied object. If obj is of DNSRecord class then (obj getLevel() + 1) is returned, else this method always returns 0.

Specified by:
evaluate in interface Metricable
Parameters:
obj - the object (may be null) to evaluate.
Returns:
the integer result of the performed evaluation.
Since:
3.0
See Also:
INSTANCE, greater(java.lang.Object, java.lang.Object)