Top Description Inners Fields Constructors Methods
com.google.common.primitives

public final Class Chars

extends Object
Class Inheritance
Annotations
@GwtCompatible
emulated:true
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, .Preconditions.checkElementIndex, .Preconditions.checkNotNull, .Preconditions.checkPositionIndexes

Static utility methods pertaining to char primitives, that are not already found in either Character or Arrays.

All the operations in this class treat char values strictly numerically; they are neither Unicode-aware nor locale-dependent.

See the Guava User Guide article on primitive utilities.

Author
Kevin Bourrillion
Since
1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static enum

Field Summary

Modifier and TypeField and Description
public static final int
BYTES

The number of bytes required to represent a primitive char value.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static List<Character>

Returns:

a list view of the array
asList
(char...
the array to back the list
backingArray
)

Returns a fixed-size list backed by the specified array, similar to Arrays#asList(Object[]).

public static char

Returns:

the char value that equals value
checkedCast
(long
any value in the range of the char type
value
)

Returns the char value that is equal to value, if possible.

public static int

Returns:

a negative value if a is less than b; a positive value if a is greater than b; or zero if they are equal
compare
(char
the first char to compare
a
,
char
the second char to compare
b
)

Compares the two specified char values.

public static char[]

Returns:

a single array containing all the values from the source arrays, in order
concat
(char[]...
zero or more char arrays
arrays
)

Returns the values from each provided array combined into a single array.

public static char
constrainToRange(char
the char value to constrain
value
,
char
the lower bound (inclusive) of the range to constrain value to
min
,
char
the upper bound (inclusive) of the range to constrain value to
max
)

Returns the value nearest to value which is within the closed range [min..max].

public static boolean

Returns:

true if array[i] == target for some value of i
contains
(char[]
an array of char values, possibly empty
array
,
char
a primitive char value
target
)

Returns true if target is present as an element anywhere in array.

public static char[]

Returns:

an array containing the values of array, with guaranteed minimum length minLength
ensureCapacity
(char[]
the source array
array
,
int
the minimum length the returned array must guarantee
minLength
,
int
an extra amount to "grow" the array by if growth is necessary
padding
)

Returns an array containing the same values as array, but guaranteed to be of a specified minimum length.

public static char
fromByteArray(byte[] bytes)

Returns the char value whose big-endian representation is stored in the first 2 bytes of bytes; equivalent to ByteBuffer.wrap(bytes).getChar().

public static char
fromBytes(byte b1, byte b2)

Returns the char value whose byte representation is the given 2 bytes, in big-endian order; equivalent to Chars.fromByteArray(new byte[] {b1, b2}).

public static int

Returns:

a hash code for the value
hashCode
(char
a primitive char value
value
)

Returns a hash code for value; equal to the result of invoking ((Character) value).hashCode().

public static int

Returns:

the least index i for which array[i] == target, or -1 if no such index exists.
indexOf
(char[]
an array of char values, possibly empty
array
,
char
a primitive char value
target
)

Returns the index of the first appearance of the value target in array.

private static int
indexOf(char[] array, char target, int start, int end)

public static int
indexOf(char[]
the array to search for the sequence target
array
,
char[]
the array to search for as a sub-sequence of array
target
)

Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.

public static String
join(String
the text that should appear between consecutive values in the resulting string (but not at the start or end)
separator
,
char...
an array of char values, possibly empty
array
)

Returns a string containing the supplied char values separated by separator.

public static int

Returns:

the greatest index i for which array[i] == target, or -1 if no such index exists.
lastIndexOf
(char[]
an array of char values, possibly empty
array
,
char
a primitive char value
target
)

Returns the index of the last appearance of the value target in array.

private static int
lastIndexOf(char[] array, char target, int start, int end)

public static Comparator<char[]>
lexicographicalComparator()

Returns a comparator that compares two char arrays lexicographically; not advisable for sorting user-visible strings as the ordering may not match the conventions of the user's locale.

public static char

Returns:

the value present in array that is greater than or equal to every other value in the array
max
(char...
a nonempty array of char values
array
)

Returns the greatest value present in array.

public static char

Returns:

the value present in array that is less than or equal to every other value in the array
min
(char...
a nonempty array of char values
array
)

Returns the least value present in array.

public static void
reverse(char[] array)

Reverses the elements of array.

public static void
reverse(char[] array, int fromIndex, int toIndex)

Reverses the elements of array between fromIndex inclusive and toIndex exclusive.

public static void
rotate(char[] array, int distance)

Performs a right rotation of array of "distance" places, so that the first element is moved to index "distance", and the element at index i ends up at index (distance + i) mod array.length.

public static void
rotate(char[] array, int distance, int fromIndex, int toIndex)

Performs a right rotation of array between fromIndex inclusive and toIndex exclusive.

public static char

Returns:

the same value cast to char if it is in the range of the char type, Character#MAX_VALUE if it is too large, or Character#MIN_VALUE if it is too small
saturatedCast
(long
any long value
value
)

Returns the char nearest in value to value.

public static void
sortDescending(char[] array)

Sorts the elements of array in descending order.

public static void
sortDescending(char[] array, int fromIndex, int toIndex)

Sorts the elements of array between fromIndex inclusive and toIndex exclusive in descending order.

public static char[]

Returns:

an array containing the same values as collection, in the same order, converted to primitives
toArray
(Collection<Character>
a collection of Character objects
collection
)

Copies a collection of Character instances into a new array of primitive char values.

public static byte[]
toByteArray(char value)

Returns a big-endian representation of value in a 2-element byte array; equivalent to ByteBuffer.allocate(2).putChar(value).array().

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTESback to summary
public static final int BYTES

The number of bytes required to represent a primitive char value.

Java 8 users: use Character#BYTES instead.

Constructor Detail

Charsback to summary
private Chars()

Method Detail

asListback to summary
public static List<Character> asList(char... backingArray)

Returns a fixed-size list backed by the specified array, similar to Arrays#asList(Object[]). The list supports List#set(int, Object), but any attempt to set a value to null will result in a NullPointerException.

The returned list maintains the values, but not the identities, of Character objects written to or read from it. For example, whether list.get(0) == list.get(0) is true for the returned list is unspecified.

The returned list is serializable.

Parameters
backingArray:char[]

the array to back the list

Returns:List<Character>

a list view of the array

checkedCastback to summary
public static char checkedCast(long value)

Returns the char value that is equal to value, if possible.

Parameters
value:long

any value in the range of the char type

Returns:char

the char value that equals value

Exceptions
IllegalArgumentException:
if value is greater than Character#MAX_VALUE or less than Character#MIN_VALUE
compareback to summary
public static int compare(char a, char b)

Compares the two specified char values. The sign of the value returned is the same as that of ((Character) a).compareTo(b).

Note for Java 7 and later: this method should be treated as deprecated; use the equivalent Character#compare method instead.

Parameters
a:char

the first char to compare

b:char

the second char to compare

Returns:int

a negative value if a is less than b; a positive value if a is greater than b; or zero if they are equal

concatback to summary
public static char[] concat(char[]... arrays)

Returns the values from each provided array combined into a single array. For example, concat(new char[] {a, b}, new char[] {}, new char[] {c} returns the array {a, b, c}.

Parameters
arrays:char[][]

zero or more char arrays

Returns:char[]

a single array containing all the values from the source arrays, in order

constrainToRangeback to summary
public static char constrainToRange(char value, char min, char max)

Returns the value nearest to value which is within the closed range [min..max].

If value is within the range [min..max], value is returned unchanged. If value is less than min, min is returned, and if value is greater than max, max is returned.

Parameters
value:char

the char value to constrain

min:char

the lower bound (inclusive) of the range to constrain value to

max:char

the upper bound (inclusive) of the range to constrain value to

Exceptions
IllegalArgumentException:
if min > max
Since
21.0
containsback to summary
public static boolean contains(char[] array, char target)

Returns true if target is present as an element anywhere in array.

Parameters
array:char[]

an array of char values, possibly empty

target:char

a primitive char value

Returns:boolean

true if array[i] == target for some value of i

ensureCapacityback to summary
public static char[] ensureCapacity(char[] array, int minLength, int padding)

Returns an array containing the same values as array, but guaranteed to be of a specified minimum length. If array already has a length of at least minLength, it is returned directly. Otherwise, a new array of size minLength + padding is returned, containing the values of array, and zeroes in the remaining places.

Parameters
array:char[]

the source array

minLength:int

the minimum length the returned array must guarantee

padding:int

an extra amount to "grow" the array by if growth is necessary

Returns:char[]

an array containing the values of array, with guaranteed minimum length minLength

Exceptions
IllegalArgumentException:
if minLength or padding is negative
fromByteArrayback to summary
public static char fromByteArray(byte[] bytes)

Returns the char value whose big-endian representation is stored in the first 2 bytes of bytes; equivalent to ByteBuffer.wrap(bytes).getChar(). For example, the input byte array {0x54, 0x32} would yield the char value '\\u5432'.

Arguably, it's preferable to use java.nio.ByteBuffer; that library exposes much more flexibility at little cost in readability.

Annotations
@GwtIncompatible
Exceptions
IllegalArgumentException:
if bytes has fewer than 2 elements
fromBytesback to summary
public static char fromBytes(byte b1, byte b2)

Returns the char value whose byte representation is the given 2 bytes, in big-endian order; equivalent to Chars.fromByteArray(new byte[] {b1, b2}).

Annotations
@GwtIncompatible
Since
7.0
hashCodeback to summary
public static int hashCode(char value)

Returns a hash code for value; equal to the result of invoking ((Character) value).hashCode().

Java 8 users: use Character#hashCode(char) instead.

Parameters
value:char

a primitive char value

Returns:int

a hash code for the value

indexOfback to summary
public static int indexOf(char[] array, char target)

Returns the index of the first appearance of the value target in array.

Parameters
array:char[]

an array of char values, possibly empty

target:char

a primitive char value

Returns:int

the least index i for which array[i] == target, or -1 if no such index exists.

indexOfback to summary
private static int indexOf(char[] array, char target, int start, int end)
indexOfback to summary
public static int indexOf(char[] array, char[] target)

Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.

More formally, returns the lowest index i such that Arrays.copyOfRange(array, i, i + target.length) contains exactly the same elements as target.

Parameters
array:char[]

the array to search for the sequence target

target:char[]

the array to search for as a sub-sequence of array

joinback to summary
public static String join(String separator, char... array)

Returns a string containing the supplied char values separated by separator. For example, join("-", '1', '2', '3') returns the string "1-2-3".

Parameters
separator:String

the text that should appear between consecutive values in the resulting string (but not at the start or end)

array:char[]

an array of char values, possibly empty

lastIndexOfback to summary
public static int lastIndexOf(char[] array, char target)

Returns the index of the last appearance of the value target in array.

Parameters
array:char[]

an array of char values, possibly empty

target:char

a primitive char value

Returns:int

the greatest index i for which array[i] == target, or -1 if no such index exists.

lastIndexOfback to summary
private static int lastIndexOf(char[] array, char target, int start, int end)
lexicographicalComparatorback to summary
public static Comparator<char[]> lexicographicalComparator()

Returns a comparator that compares two char arrays lexicographically; not advisable for sorting user-visible strings as the ordering may not match the conventions of the user's locale. That is, it compares, using compare(char, char)), the first pair of values that follow any common prefix, or when one array is a prefix of the other, treats the shorter array as the lesser. For example, [] < ['a'] < ['a', 'b'] < ['b'].

The returned comparator is inconsistent with Object#equals(Object) (since arrays support only identity equality), but it is consistent with Arrays#equals(char[], char[]).

Since
2.0
maxback to summary
public static char max(char... array)

Returns the greatest value present in array.

Parameters
array:char[]

a nonempty array of char values

Returns:char

the value present in array that is greater than or equal to every other value in the array

Exceptions
IllegalArgumentException:
if array is empty
minback to summary
public static char min(char... array)

Returns the least value present in array.

Parameters
array:char[]

a nonempty array of char values

Returns:char

the value present in array that is less than or equal to every other value in the array

Exceptions
IllegalArgumentException:
if array is empty
reverseback to summary
public static void reverse(char[] array)

Reverses the elements of array. This is equivalent to Collections.reverse(Chars.asList(array)), but is likely to be more efficient.

Since
23.1
reverseback to summary
public static void reverse(char[] array, int fromIndex, int toIndex)

Reverses the elements of array between fromIndex inclusive and toIndex exclusive. This is equivalent to Collections.reverse(Chars.asList(array).subList(fromIndex, toIndex)), but is likely to be more efficient.

Exceptions
IndexOutOfBoundsException:
if fromIndex < 0, toIndex > array.length, or toIndex > fromIndex
Since
23.1
rotateback to summary
public static void rotate(char[] array, int distance)

Performs a right rotation of array of "distance" places, so that the first element is moved to index "distance", and the element at index i ends up at index (distance + i) mod array.length. This is equivalent to Collections.rotate(Chars.asList(array), distance), but is considerably faster and avoids allocation and garbage collection.

The provided "distance" may be negative, which will rotate left.

Since
32.0.0
rotateback to summary
public static void rotate(char[] array, int distance, int fromIndex, int toIndex)

Performs a right rotation of array between fromIndex inclusive and toIndex exclusive. This is equivalent to Collections.rotate(Chars.asList(array).subList(fromIndex, toIndex), distance), but is considerably faster and avoids allocations and garbage collection.

The provided "distance" may be negative, which will rotate left.

Exceptions
IndexOutOfBoundsException:
if fromIndex < 0, toIndex > array.length, or toIndex > fromIndex
Since
32.0.0
saturatedCastback to summary
public static char saturatedCast(long value)

Returns the char nearest in value to value.

Parameters
value:long

any long value

Returns:char

the same value cast to char if it is in the range of the char type, Character#MAX_VALUE if it is too large, or Character#MIN_VALUE if it is too small

sortDescendingback to summary
public static void sortDescending(char[] array)

Sorts the elements of array in descending order.

Since
23.1
sortDescendingback to summary
public static void sortDescending(char[] array, int fromIndex, int toIndex)

Sorts the elements of array between fromIndex inclusive and toIndex exclusive in descending order.

Since
23.1
toArrayback to summary
public static char[] toArray(Collection<Character> collection)

Copies a collection of Character instances into a new array of primitive char values.

Elements are copied from the argument collection as if by collection.toArray(). Calling this method is as thread-safe as calling that method.

Parameters
collection:Collection<Character>

a collection of Character objects

Returns:char[]

an array containing the same values as collection, in the same order, converted to primitives

Exceptions
NullPointerException:
if collection or any of its elements is null
toByteArrayback to summary
public static byte[] toByteArray(char value)

Returns a big-endian representation of value in a 2-element byte array; equivalent to ByteBuffer.allocate(2).putChar(value).array(). For example, the input value '\\u5432' would yield the byte array {0x54, 0x32}.

If you need to convert and concatenate several values (possibly even of different types), use a shared java.nio.ByteBuffer instance, or use com.google.common.io.ByteStreams#newDataOutput() to get a growable buffer.

Annotations
@GwtIncompatible
com.google.common.primitives back to summary

private Class Chars.CharArrayAsList

extends AbstractList<Character>
implements RandomAccess, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.util.RandomAccess
Annotations
@GwtCompatible

Field Summary

Modifier and TypeField and Description
pack-priv final char[]
pack-priv final int
private static final long
pack-priv final int
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
pack-priv
CharArrayAsList(char[] array)

pack-priv
CharArrayAsList(char[] array, int start, int end)

Method Summary

Modifier and TypeMethod and Description
public boolean
contains(Object
element whose presence in this list is to be tested
target
)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Returns true if this list contains the specified element.
public boolean
equals(Object
the object to be compared for equality with this list
object
)

Overrides java.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Compares the specified object with this list for equality.
public Character
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this list.
public int
indexOf(Object
element to search for
target
)

Overrides java.util.AbstractList.indexOf.

Implements java.util.List.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
public boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.List.isEmpty, java.util.Collection.isEmpty.

Returns true if this list contains no elements.
public int
lastIndexOf(Object
element to search for
target
)

Overrides java.util.AbstractList.lastIndexOf.

Implements java.util.List.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.
public Character
set(int
index of the element to replace
index
,
Character
element to be stored at the specified position
element
)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Returns the number of elements in this list.
public List<Character>
subList(int
low endpoint (inclusive) of the subList
fromIndex
,
int
high endpoint (exclusive) of the subList
toIndex
)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
pack-priv char[]
public String
toString()

Overrides java.util.AbstractCollection.toString.

Returns a string representation of this collection.
Inherited from java.util.AbstractList:
addaddaddAllcleariteratorlistIteratorlistIteratorremoveremoveRange

Field Detail

arrayback to summary
pack-priv final char[] array
endback to summary
pack-priv final int end
serialVersionUIDback to summary
private static final long serialVersionUID
startback to summary
pack-priv final int start

Constructor Detail

CharArrayAsListback to summary
pack-priv CharArrayAsList(char[] array)
CharArrayAsListback to summary
pack-priv CharArrayAsList(char[] array, int start, int end)

Method Detail

containsback to summary
public boolean contains(Object target)

Overrides java.util.AbstractCollection.contains.

Implements java.util.List.contains, java.util.Collection.contains.

Doc from java.util.List.contains.

Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that Objects.equals(o, e).

Parameters
target:Object

element whose presence in this list is to be tested

Returns:boolean

true if this list contains the specified element

Annotations
@Override
equalsback to summary
public boolean equals(Object object)

Overrides java.util.AbstractList.equals.

Implements java.util.List.equals, java.util.Collection.equals.

Doc from java.util.AbstractList.equals.

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order.

Parameters
object:Object

the object to be compared for equality with this list

Returns:boolean

true if the specified object is equal to this list

Annotations
@Override
getback to summary
public Character get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:Character

Doc from java.util.List.get.

the element at the specified position in this list

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.util.AbstractList.hashCode.

Implements java.util.List.hashCode, java.util.Collection.hashCode.

Doc from java.util.AbstractList.hashCode.

Returns the hash code value for this list.

Returns:int

the hash code value for this list

Annotations
@Override
indexOfback to summary
public int indexOf(Object target)

Overrides java.util.AbstractList.indexOf.

Implements java.util.List.indexOf.

Doc from java.util.AbstractList.indexOf.

Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
target:Object

Doc from java.util.List.indexOf.

element to search for

Returns:int

Doc from java.util.List.indexOf.

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.List.isEmpty, java.util.Collection.isEmpty.

Doc from java.util.List.isEmpty.

Returns true if this list contains no elements.

Returns:boolean

true if this list contains no elements

Annotations
@Override
lastIndexOfback to summary
public int lastIndexOf(Object target)

Overrides java.util.AbstractList.lastIndexOf.

Implements java.util.List.lastIndexOf.

Doc from java.util.AbstractList.lastIndexOf.

Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the highest index i such that Objects.equals(o, get(i)), or -1 if there is no such index.

Parameters
target:Object

Doc from java.util.List.lastIndexOf.

element to search for

Returns:int

Doc from java.util.List.lastIndexOf.

the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element

Annotations
@Override
setback to summary
public Character set(int index, Character element)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Doc from java.util.AbstractList.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Parameters
index:int

Doc from java.util.List.set.

index of the element to replace

element:Character

Doc from java.util.List.set.

element to be stored at the specified position

Returns:Character

Doc from java.util.List.set.

the element previously at the specified position

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.List.size, java.util.Collection.size.

Doc from java.util.List.size.

Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this list

Annotations
@Override
subListback to summary
public List<Character> subList(int fromIndex, int toIndex)

Overrides java.util.AbstractList.subList.

Implements java.util.List.subList.

Doc from java.util.AbstractList.subList.

Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of the optional list operations supported by this list.

This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a list can be used as a range operation by passing a subList view instead of a whole list. For example, the following idiom removes a range of elements from a list:

list.subList(from, to).clear();
Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList.

The semantics of the list returned by this method become undefined if the backing list (i.e., this list) is structurally modified in any way other than via the returned list. (Structural modifications are those that change the size of this list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.)

Parameters
fromIndex:int

Doc from java.util.List.subList.

low endpoint (inclusive) of the subList

toIndex:int

Doc from java.util.List.subList.

high endpoint (exclusive) of the subList

Returns:List<Character>

Doc from java.util.List.subList.

a view of the specified range within this list

Annotations
@Override
toCharArrayback to summary
pack-priv char[] toCharArray()
toStringback to summary
public String toString()

Overrides java.util.AbstractCollection.toString.

Doc from java.util.AbstractCollection.toString.

Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this collection

Annotations
@Override
com.google.common.primitives back to summary

private final Enum Chars.LexicographicalComparator

extends Enum<Chars.LexicographicalComparator>
implements Comparator<char[]>
Class Inheritance
All Implemented Interfaces
java.util.Comparator

Field Summary

Modifier and TypeField and Description
public static final Chars.LexicographicalComparator

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
compare(char[]
the first object to be compared.
left
,
char[]
the second object to be compared.
right
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.
public static Chars.LexicographicalComparator
public static Chars.LexicographicalComparator[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

INSTANCEback to summary
public static final Chars.LexicographicalComparator INSTANCE

Constructor Detail

LexicographicalComparatorback to summary
private LexicographicalComparator()

Method Detail

compareback to summary
public int compare(char[] left, char[] right)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments 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.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
left:char[]

the first object to be compared.

right:char[]

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static Chars.LexicographicalComparator valueOf(String name)
valuesback to summary
public static Chars.LexicographicalComparator[] values()