Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.util
Class FastComparator<T>

    java.lang.Object
      javolution.util.FastComparator<T>

All Implemented Interfaces:
  java.io.Serializable, java.util.Comparator<T>, XMLSerializable

    public abstract class FastComparator<T>

extends java.lang.Object
implements java.util.Comparator<T>, XMLSerializable

This class represents a comparator to be used for equality as well as for ordering; instances of this class provide a hashcode function consistent with equal (if two objects `are equal`, they have the same `hashcode`), equality with `null` values is supported.

`FastComparator` can be employed with `FastMap` (e.g. custom key comparators for identity maps, value retrieval using keys of a different class that the map keys) or with `FastCollection` classes.

Version:
  4.2, December 18, 2006
Author:
  Jean-Marie Dautelle
See Also:
  Serialized Form

Field Summary
`static FastComparator<java.lang.Object>` | `DEFAULT` Holds the default object comparator; rehash is performed if the system hash code (platform dependent) is not evenly distributed.
`static FastComparator<java.lang.Object>` | `DIRECT` Holds the direct object comparator; no rehash is performed.
`static FastComparator<java.lang.Object>` | `IDENTITY` Holds the identity comparator; poorly distributed system hashcodes are rehashed.
`static FastComparator<java.lang.CharSequence>` | `LEXICAL` Holds a lexicographic comparator for any `CharSequence` or `String` instances.
`static FastComparator<java.lang.Object>` | `REHASH` Holds the comparator for objects with uneven hash distribution; objects hashcodes are rehashed.
`static Configurable<java.lang.Boolean>` | `REHASH_SYSTEM_HASHCODE` Indicates if the system hash code should be rehashed (see Javolution Configuration for details).
`static FastComparator<java.lang.String>` | `STRING` Holds a fast comparator for `java.lang.String`.

Constructor Summary
`FastComparator()`

Method Summary
`abstract boolean` | `areEqual(T o1, T o2)` Indicates if the specified objects can be considered equal.
`abstract int` | `compare(T o1, T o2)` Compares the specified objects for order.
`abstract int` | `hashCodeOf(T obj)` Returns the hash code for the specified object (consistent with `areEqual(T, T)`).

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

Methods inherited from interface java.util.Comparator
`equals`

Field Detail

### REHASH_SYSTEM_HASHCODE

    public static final Configurable<java.lang.Boolean> REHASH_SYSTEM_HASHCODE

  Indicates if the system hash code should be rehashed (see Javolution Configuration for details).

### DEFAULT

    public static final FastComparator<java.lang.Object> DEFAULT

  Holds the default object comparator; rehash is performed if the system hash code (platform dependent) is not evenly distributed.

  See Also:
    Javolution Configuration

### DIRECT

    public static final FastComparator<java.lang.Object> DIRECT

  Holds the direct object comparator; no rehash is performed. Two objects o1 and o2 are considered `equal` if and only if `o1.equals(o2)`. The `compare(T, T)` method throws `ClassCastException` if the specified objects are not `Comparable`.

### REHASH

    public static final FastComparator<java.lang.Object> REHASH

  Holds the comparator for objects with uneven hash distribution; objects hashcodes are rehashed. Two objects o1 and o2 are considered `equal` if and only if `o1.equals(o2)`. The `compare(T, T)` method throws `ClassCastException` if the specified objects are not `Comparable`.

### STRING

    public static final FastComparator<java.lang.String> STRING

  Holds a fast comparator for `java.lang.String`. Hashcodes are calculated by taking a sample of few characters instead of the whole string.

### IDENTITY

    public static final FastComparator<java.lang.Object> IDENTITY

  Holds the identity comparator; poorly distributed system hashcodes are rehashed. Two objects o1 and o2 are considered `equal` if and only if `(o1 == o2)`. The `compare(T, T)` method throws `ClassCastException` if the specified objects are not `Comparable`.

### LEXICAL

    public static final FastComparator<java.lang.CharSequence> LEXICAL

  Holds a lexicographic comparator for any `CharSequence` or `String` instances. Two objects are considered `equal` if and only if they represents the same character sequence). The hashcode is calculated using the following formula (same as for `java.lang.String`): `s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]`

Constructor Detail

### FastComparator

    public FastComparator()

Method Detail

### hashCodeOf

    public abstract int hashCodeOf(T obj)

  Returns the hash code for the specified object (consistent with `areEqual(T, T)`). Two objects considered `equal` have the same hash code.

  Parameters:
    `obj` - the object to return the hashcode for.
  Returns:
    the hashcode for the specified object.
  Throws:
    `java.lang.NullPointerException` - if the specified object is `null`.

### areEqual

    public abstract boolean areEqual(T o1,
                                     T o2)

  Indicates if the specified objects can be considered equal.

  Parameters:
    `o1` - the first object (or `null`).
    `o2` - the second object (or `null`).
  Returns:
    `true` if both objects are considered equal; `false` otherwise.

### compare

    public abstract int compare(T o1,
                                T o2)

  Compares the specified objects for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

  Specified by:
    `compare` in interface `java.util.Comparator<T>`
  Parameters:
    `o1` - the first object.
    `o2` - the second object.
  Returns:
    a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
  Throws:
    `java.lang.NullPointerException` - if any of the specified object is `null`.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.3 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2009 Javolution.