38 |
* Compliant with JDK 1.1. |
* Compliant with JDK 1.1. |
39 |
* |
* |
40 |
* @author Paul N. Fisher |
* @author Paul N. Fisher |
41 |
|
* @author Eric Blake <ebb9@email.byu.edu> |
42 |
* @since JDK1.0 |
* @since JDK1.0 |
43 |
*/ |
*/ |
44 |
public final class String implements Comparable, CharSequence, Serializable { |
public final class String implements Comparable, CharSequence, Serializable { |
80 |
private int cachedHashCode; |
private int cachedHashCode; |
81 |
|
|
82 |
/** |
/** |
83 |
|
* An implementation for {@link CASE_INSENSITIVE_ORDER}. |
84 |
|
* This must be {@link Serializable}. |
85 |
|
*/ |
86 |
|
private static final class CaseInsensitiveComparator |
87 |
|
implements Comparator, Serializable |
88 |
|
{ |
89 |
|
/** |
90 |
|
* The default private constructor generates unnecessary overhead |
91 |
|
*/ |
92 |
|
CaseInsensitiveComparator() {} |
93 |
|
|
94 |
|
/** |
95 |
|
* Compares to Strings, using |
96 |
|
* <code>String.compareToIgnoreCase(String)</code>. |
97 |
|
* |
98 |
|
* @param o1 the first string |
99 |
|
* @param o2 the second string |
100 |
|
* @return < 0, 0, or > 0 depending on the case-insensitive |
101 |
|
* comparison of the two strings. |
102 |
|
* @throws NullPointerException if either argument is null |
103 |
|
* @throws ClassCastException if either argument is not a String |
104 |
|
* @see #compareToIgnoreCase(String) |
105 |
|
*/ |
106 |
|
public int compare(Object o1, Object o2) |
107 |
|
{ |
108 |
|
return ((String) o1).compareToIgnoreCase((String) o2); |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
|
/** |
113 |
* A Comparator that uses <code>String.compareToIgnoreCase(String)</code>. |
* A Comparator that uses <code>String.compareToIgnoreCase(String)</code>. |
114 |
|
* This comparator is {@link Serializable}. |
115 |
* |
* |
116 |
* @since 1.2 |
* @since 1.2 |
117 |
*/ |
*/ |
118 |
public static final Comparator CASE_INSENSITIVE_ORDER |
public static final Comparator CASE_INSENSITIVE_ORDER |
119 |
= new Comparator() { |
= new CaseInsensitiveComparator(); |
|
public int compare(Object o1, Object o2) { |
|
|
return ((String)o1).compareToIgnoreCase((String)o2); |
|
|
} |
|
|
}; |
|
120 |
|
|
121 |
/** |
/** |
122 |
* Creates an empty String (length 0) |
* Creates an empty String (length 0) |