Javolution 6.0.0 java
javolution.util.internal.comparator.LexicalFastComparatorImpl Class Reference
Inheritance diagram for javolution.util.internal.comparator.LexicalFastComparatorImpl:
[legend]
Collaboration diagram for javolution.util.internal.comparator.LexicalFastComparatorImpl:
[legend]

Public Member Functions

int hashCodeOf (CharSequence csq)
 
int hashCodeOf (T object)
 
boolean areEqual (CharSequence csq1, CharSequence csq2)
 
boolean areEqual (T left, T right)
 
int compare (CharSequence left, CharSequence right)
 
int compare (T left, T right)
 

Static Private Attributes

static final long serialVersionUID = -1449702752185594025L
 

Detailed Description

The high-performance lexical comparator.

Definition at line 14 of file LexicalFastComparatorImpl.java.

Member Function Documentation

◆ areEqual() [1/2]

boolean javolution.util.internal.comparator.LexicalComparatorImpl.areEqual ( CharSequence  csq1,
CharSequence  csq2 
)
inherited

Definition at line 38 of file LexicalComparatorImpl.java.

38  {
39  if (csq1 == csq2)
40  return true;
41  if ((csq1 == null) || (csq2 == null))
42  return false;
43  if (csq1 instanceof String) { // Optimization.
44  if (csq2 instanceof String)
45  return csq1.equals(csq2);
46  return ((String) csq1).contentEquals(csq2);
47  } else if (csq2 instanceof String) { return ((String) csq2)
48  .contentEquals(csq1); }
49 
50  // None of the CharSequence is a String.
51  int n = csq1.length();
52  if (csq2.length() != n)
53  return false;
54  for (int i = 0; i < n;) {
55  if (csq1.charAt(i) != csq2.charAt(i++))
56  return false;
57  }
58  return true;
59  }

◆ areEqual() [2/2]

boolean javolution.util.function.Equality< T >.areEqual ( left,
right 
)
inherited

Indicates if the specified objects can be considered equal. This methods is equivalent to

(compare(o1, o2) == 0)

but usually faster.

Parameters
leftthe first object (or null).
rightthe second object (or null).
Returns
true if both objects are considered equal; false otherwise.

Referenced by javolution.util.internal.map.MapView< K, V >.EntryComparator.areEqual(), javolution.util.internal.collection.CollectionView< R >.contains(), javolution.util.internal.collection.CollectionView< R >.equals(), javolution.util.internal.table.TableView< E >.indexOf(), javolution.util.internal.table.TableView< E >.lastIndexOf(), javolution.util.internal.map.FastMapImpl< K, V >.remove(), javolution.util.internal.collection.CollectionView< R >.remove(), and javolution.util.internal.map.FastMapImpl< K, V >.replace().

Here is the caller graph for this function:

◆ compare() [1/2]

int javolution.util.internal.comparator.LexicalComparatorImpl.compare ( CharSequence  left,
CharSequence  right 
)
inherited

Definition at line 62 of file LexicalComparatorImpl.java.

62  {
63  if (left == null)
64  return -1;
65  if (right == null)
66  return 1;
67  if ((left instanceof String) && (right instanceof String)) // Optimization.
68  return ((String) left).compareTo((String) right);
69  int i = 0;
70  int n = MathLib.min(left.length(), right.length());
71  while (n-- != 0) {
72  char c1 = left.charAt(i);
73  char c2 = right.charAt(i++);
74  if (c1 != c2)
75  return c1 - c2;
76  }
77  return left.length() - right.length();
78  }

References javolution.lang.MathLib.min().

Here is the call graph for this function:

◆ compare() [2/2]

int javolution.util.function.Equality< T >.compare ( left,
right 
)
inherited

Compares the specified objects for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, possibly equal to, or greater than the second. Implementation classes should ensure that comparisons with

null

is supported.

Parameters
leftthe first object.
rightthe second object.
Returns
a negative integer, zero, or a positive integer as the first argument is less than, possibly equal to, or greater than the second.

Referenced by javolution.util.internal.set.sorted.SubSortedSetImpl< E >.add(), javolution.util.internal.map.MapView< K, V >.EntryComparator.compare(), javolution.text.CharArray.compareTo(), javolution.text.Text.compareTo(), javolution.util.internal.set.sorted.SubSortedSetImpl< E >.contains(), javolution.util.internal.map.sorted.SubSortedMapImpl< K, V >.containsKey(), javolution.util.internal.map.sorted.SubSortedMapImpl< K, V >.get(), javolution.util.internal.set.sorted.SubSortedSetImpl< E >.IteratorImpl.hasNext(), javolution.util.internal.map.sorted.SubSortedMapImpl< K, V >.IteratorImpl.hasNext(), javolution.util.internal.map.sorted.SubSortedMapImpl< K, V >.put(), javolution.util.internal.set.sorted.SubSortedSetImpl< E >.remove(), and javolution.util.internal.map.sorted.SubSortedMapImpl< K, V >.remove().

Here is the caller graph for this function:

◆ hashCodeOf() [1/2]

int javolution.util.internal.comparator.LexicalFastComparatorImpl.hashCodeOf ( CharSequence  csq)

Reimplemented from javolution.util.internal.comparator.LexicalComparatorImpl.

Definition at line 19 of file LexicalFastComparatorImpl.java.

19  {
20  if (csq == null)
21  return 0;
22  int n = csq.length();
23  if (n == 0)
24  return 0;
25  // Hash based on 5 characters only.
26  return csq.charAt(0) + csq.charAt(n - 1) * 31 + csq.charAt(n >> 1)
27  * 1009 + csq.charAt(n >> 2) * 27583
28  + csq.charAt(n - 1 - (n >> 2)) * 73408859;
29  }

◆ hashCodeOf() [2/2]

int javolution.util.function.Equality< T >.hashCodeOf ( object)
inherited

Returns the hash code for the specified object (consistent with areEqual). Two objects considered equal have the same hash code. The hash code of null is always 0.

Parameters
objectthe object to return the hashcode for.
Returns
the hashcode for the specified object.

Referenced by javolution.util.internal.map.FastMapImpl< K, V >.containsKey(), javolution.util.internal.map.FastMapImpl< K, V >.get(), javolution.util.internal.collection.CollectionView< R >.hashCode(), javolution.util.internal.map.MapView< K, V >.EntryComparator.hashCodeOf(), javolution.util.internal.map.FastMapImpl< K, V >.put(), javolution.util.internal.map.FastMapImpl< K, V >.putIfAbsent(), javolution.util.internal.map.FastMapImpl< K, V >.remove(), and javolution.util.internal.map.FastMapImpl< K, V >.replace().

Here is the caller graph for this function:

Member Data Documentation

◆ serialVersionUID

final long javolution.util.internal.comparator.LexicalFastComparatorImpl.serialVersionUID = -1449702752185594025L
staticprivate

Definition at line 16 of file LexicalFastComparatorImpl.java.


The documentation for this class was generated from the following file:
javolution.util.internal.comparator.LexicalComparatorImpl.compare
int compare(CharSequence left, CharSequence right)
Definition: LexicalComparatorImpl.java:62