Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.joda.time
Class DateTimeComparator

    java.lang.Object
      org.joda.time.DateTimeComparator

All Implemented Interfaces:
  java.io.Serializable, java.util.Comparator

    public class DateTimeComparator

extends java.lang.Object
implements java.util.Comparator, java.io.Serializable

DateTimeComparator provides comparators to compare one date with another.

Dates may be specified using any object recognised by the `ConverterManager` class.

The default objects recognised by the comparator are:

- ReadableInstant
- String
- Calendar
- Date
- Long (milliseconds)
- null (now)

DateTimeComparator is thread-safe and immutable.

Since:
  1.0
Author:
  Guy Allard, Stephen Colebourne, Brian S O'Neill
See Also:
  Serialized Form

Constructor Summary
`protected` | `DateTimeComparator(DateTimeFieldType lowerLimit, DateTimeFieldType upperLimit)` Restricted constructor.

Method Summary
`int` | `compare(java.lang.Object lhsObj, java.lang.Object rhsObj)` Compare two objects against only the range of date time fields as specified in the constructor.
`boolean` | `equals(java.lang.Object object)` Compares this comparator to another.
`static DateTimeComparator` | `getDateOnlyInstance()` Returns a comparator that only considers date fields.
`static DateTimeComparator` | `getInstance()` Returns a DateTimeComparator the compares the entire date time value.
`static DateTimeComparator` | `getInstance(DateTimeFieldType lowerLimit)` Returns a DateTimeComparator with a lower limit only.
`static DateTimeComparator` | `getInstance(DateTimeFieldType lowerLimit, DateTimeFieldType upperLimit)` Returns a DateTimeComparator with a lower and upper limit.
`DateTimeFieldType` | `getLowerLimit()` Gets the field type that represents the lower limit of comparison.
`static DateTimeComparator` | `getTimeOnlyInstance()` Returns a comparator that only considers time fields.
`DateTimeFieldType` | `getUpperLimit()` Gets the field type that represents the upper limit of comparison.
`int` | `hashCode()` Gets a suitable hashcode.
`java.lang.String` | `toString()` Gets a debugging string.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### DateTimeComparator

    protected DateTimeComparator(DateTimeFieldType lowerLimit,
                                 DateTimeFieldType upperLimit)

  Restricted constructor.

  Parameters:
    `lowerLimit` - the lower field limit, null means no limit
    `upperLimit` - the upper field limit, null means no limit

Method Detail

### getInstance

    public static DateTimeComparator getInstance()

  Returns a DateTimeComparator the compares the entire date time value.

  Returns:
    a comparator over all fields

### getInstance

    public static DateTimeComparator getInstance(DateTimeFieldType lowerLimit)

  Returns a DateTimeComparator with a lower limit only. Fields of a magnitude less than the lower limit are excluded from comparisons.

  Parameters:
    `lowerLimit` - inclusive lower limit for fields to be compared, null means no limit
  Returns:
    a comparator over all fields above the lower limit

### getInstance

    public static DateTimeComparator getInstance(DateTimeFieldType lowerLimit,
                                                 DateTimeFieldType upperLimit)

  Returns a DateTimeComparator with a lower and upper limit. Fields of a magnitude less than the lower limit are excluded from comparisons. Fields of a magnitude greater than or equal to the upper limit are also excluded from comparisons. Either limit may be specified as null, which indicates an unbounded limit.

  Parameters:
    `lowerLimit` - inclusive lower limit for fields to be compared, null means no limit
    `upperLimit` - exclusive upper limit for fields to be compared, null means no limit
  Returns:
    a comparator over all fields between the limits

### getDateOnlyInstance

    public static DateTimeComparator getDateOnlyInstance()

  Returns a comparator that only considers date fields. Time of day is ignored.

  Returns:
    a comparator over all date fields

### getTimeOnlyInstance

    public static DateTimeComparator getTimeOnlyInstance()

  Returns a comparator that only considers time fields. Date is ignored.

  Returns:
    a comparator over all time fields

### getLowerLimit

    public DateTimeFieldType getLowerLimit()

  Gets the field type that represents the lower limit of comparison.

  Returns:
    the field type, null if no upper limit

### getUpperLimit

    public DateTimeFieldType getUpperLimit()

  Gets the field type that represents the upper limit of comparison.

  Returns:
    the field type, null if no upper limit

### compare

    public int compare(java.lang.Object lhsObj,
                       java.lang.Object rhsObj)

  Compare two objects against only the range of date time fields as specified in the constructor.

  Specified by:
    `compare` in interface `java.util.Comparator`
  Parameters:
    `lhsObj` - the first object, logically on the left of a < comparison, null means now
    `rhsObj` - the second object, logically on the right of a < comparison, null means now
  Returns:
    zero if order does not matter, negative value if lhsObj < rhsObj, positive value otherwise.
  Throws:
    `java.lang.IllegalArgumentException` - if either argument is not supported

### equals

    public boolean equals(java.lang.Object object)

  Compares this comparator to another.

  Specified by:
    `equals` in interface `java.util.Comparator`
  Overrides:
    `equals` in class `java.lang.Object`
  Parameters:
    `object` - the object to compare to
  Returns:
    true if equal

### hashCode

    public int hashCode()

  Gets a suitable hashcode.

  Overrides:
    `hashCode` in class `java.lang.Object`
  Returns:
    the hashcode

### toString

    public java.lang.String toString()

  Gets a debugging string.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    a debugging string

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD