com.koloboke.collect
Interface CharCollection

All Superinterfaces:
Collection<Character>, Container, Iterable<Character>
All Known Subinterfaces:
CharSet, HashCharSet

public interface CharCollection
extends Collection<Character>, Container

A Collection specialization with char elements.


Method Summary
 boolean add(char e)
          Ensures that this collection contains the specified element (optional operation).
 boolean add(Character e)
          Deprecated. Use specialization add(char) instead
 boolean contains(char v)
          Returns true if this collection contains at least one element equals to the specified one.
 boolean contains(Object o)
          Deprecated. Use specialization contains(char) instead
 CharCursor cursor()
          Returns a new cursor over this collection's elements.
 void forEach(CharConsumer action)
          Performs the given action for each element of this collection until all elements have been processed or the action throws an exception.
 boolean forEachWhile(CharPredicate predicate)
          Checks the given predicate on each element of this collection until all element have been processed or the predicate returns false for some element, or throws an Exception.
 CharIterator iterator()
          Deprecated. Instead of explicit iterator() calls, use cursor(); iterator() is still sensible only as a backing mechanism for Java 5's for-each statements.
 boolean remove(Object o)
          Deprecated. Use specialization removeChar(char) instead
 boolean removeChar(char v)
          Removes a single copy of the specified element from this collection, if it is present (optional operation).
 boolean removeIf(CharPredicate filter)
          Removes all of the elements of this collection that satisfy the given predicate.
 Object[] toArray()
          Deprecated. Use specialization toCharArray() instead
 char[] toArray(char[] a)
          Returns an array containing elements in this collection.
<T> T[]
toArray(T[] array)
          Deprecated. Use specialization toArray(char[]) instead
 char[] toCharArray()
          Returns an array containing all of the elements in this collection.
 
Methods inherited from interface Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, size
 
Methods inherited from interface com.koloboke.collect.Container
clear, ensureCapacity, isEmpty, shrink, size, sizeAsLong
 

Method Detail

contains

@Deprecated
boolean contains(Object o)
Deprecated. Use specialization contains(char) instead

Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).

Specified by:
contains in interface Collection<Character>
Parameters:
o - element whose presence in this collection is to be tested
Returns:
true if this collection contains the specified element

contains

boolean contains(char v)
Returns true if this collection contains at least one element equals to the specified one.

Parameters:
v - element whose presence in this collection is to be tested
Returns:
true if this collection contains the specified element

toArray

@Deprecated
@Nonnull
Object[] toArray()
Deprecated. Use specialization toCharArray() instead

Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Specified by:
toArray in interface Collection<Character>
Returns:
an array containing all of the elements in this collection

toArray

@Deprecated
@Nonnull
<T> T[] toArray(@Nonnull
                                   T[] array)
Deprecated. Use specialization toArray(char[]) instead

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)

If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

Like the Collection.toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

Suppose x is a collection known to contain only strings. The following code can be used to dump the collection into a newly allocated array of String:

     String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to toArray().

Specified by:
toArray in interface Collection<Character>
Parameters:
array - the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing all of the elements in this collection

toCharArray

@Nonnull
char[] toCharArray()
Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Returns:
an array containing all the elements in this collection
See Also:
toArray(char[])

toArray

@Nonnull
char[] toArray(@Nonnull
                       char[] a)
Returns an array containing elements in this collection.

If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to (char) 0 (zero). This is useful in determining the length of this collection only if the caller knows that this collection does not contain any elements equal to (char) 0.

If the native array is smaller than the collection size, the array will be filled with elements in Iterator order until it is full and exclude the remainder.

If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

Parameters:
a - the array into which the elements of this collection are to be stored.
Returns:
an char[] containing all the elements in this collection
Throws:
NullPointerException - if the specified array is null
See Also:
toCharArray()

cursor

@Nonnull
CharCursor cursor()
Returns a new cursor over this collection's elements. Cursor iteration order is always corresponds to the iterator's order.

Basic cursor usage idiom is:

for (CharCursor cur = collection.cursor(); cur.moveNext();) {
     // Work with cur.elem()
     // Call cur.remove() to remove the current entry
 }

Returns:
a new cursor over this collection's elements
See Also:
Comparison of iteration options in the library

iterator

@Deprecated
@Nonnull
CharIterator iterator()
Deprecated. Instead of explicit iterator() calls, use cursor(); iterator() is still sensible only as a backing mechanism for Java 5's for-each statements.

Returns a new iterator over this collection's elements.

Specified by:
iterator in interface Collection<Character>
Specified by:
iterator in interface Iterable<Character>
Returns:
a new iterator over this collection's elements
See Also:
Comparison of iteration options in the library

forEach

void forEach(@Nonnull
             CharConsumer action)
Performs the given action for each element of this collection until all elements have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the caller.

Parameters:
action - the action to be performed for each element
See Also:
Comparison of iteration options in the library

forEachWhile

boolean forEachWhile(@Nonnull
                     CharPredicate predicate)
Checks the given predicate on each element of this collection until all element have been processed or the predicate returns false for some element, or throws an Exception. Exceptions thrown by the predicate are relayed to the caller.

Unless otherwise specified by the implementing class, elements are checked by the predicate in the order of iteration (if an iteration order is specified).

If this collection is empty, this method returns true immediately.

Parameters:
predicate - the predicate to be checked for each element of this collection
Returns:
true if the predicate returned true for all elements of this collection, false if it returned false for the element
See Also:
Comparison of iteration options in the library

add

@Deprecated
boolean add(@Nonnull
                       Character e)
Deprecated. Use specialization add(char) instead

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Specified by:
add in interface Collection<Character>
Parameters:
e - element whose presence in this collection is to be ensured
Returns:
true if this collection changed as a result of the call

add

boolean add(char e)
Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Parameters:
e - element whose presence in this collection is to be ensured
Returns:
true if this collection changed as a result of the call
Throws:
UnsupportedOperationException - if the add operation is not supported by this collection
IllegalArgumentException - if some property of the element prevents it from being added to this collection
IllegalStateException - if the element cannot be added at this time due to insertion restrictions
See Also:
Collection.add(Object)

remove

@Deprecated
boolean remove(Object o)
Deprecated. Use specialization removeChar(char) instead

Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this collection contains one or more such elements. Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).

Specified by:
remove in interface Collection<Character>
Parameters:
o - element to be removed from this collection, if present
Returns:
true if an element was removed as a result of this call

removeChar

boolean removeChar(char v)
Removes a single copy of the specified element from this collection, if it is present (optional operation). Returns true if this collection contained the specified element (or equivalently, if this collection changed as a result of the call).

The name of this method is "removeChar", not "remove", because "remove" conflicts with List.remove(int).

Parameters:
v - element to be removed from this collection, if present
Returns:
true if an element was removed as a result of this call
Throws:
UnsupportedOperationException - if the remove operation is not supported by this collection
See Also:
remove(Object)

removeIf

boolean removeIf(@Nonnull
                 CharPredicate filter)
Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller.

Parameters:
filter - a predicate which returns true for elements to be removed
Returns:
true if any elements were removed
Throws:
NullPointerException - if the specified filter is null
UnsupportedOperationException - if elements cannot be removed from this collection. Implementations may throw this exception if a matching element cannot be removed or if, in general, removal is not supported.
See Also:
Comparison of iteration options in the library