com.koloboke.collect
Interface ObjCollection<E>

Type Parameters:
E - the type of elements in this collection
All Superinterfaces:
Collection<E>, Container, Iterable<E>
All Known Subinterfaces:
HashObjSet<E>, ObjSet<E>

public interface ObjCollection<E>
extends Collection<E>, Container

A collection of objects, the library's extension of the classic Collection interface.

All methods of Collection interface defined in terms of elements equality and referring to Object.equals(Object) method are supposed to use equivalence() in this interface. Thus in some sense ObjCollection violates general Collection contract, but this approach provides a great flexibility. If you need strict Collection implementation, you can always construct an ObjCollection with default equality, i. e. equivalence() == Equivalence.defaultEquality().

See Collection mutability matrix for methods which are supported by ObjCollections with the specific mutability. Among methods, defined in this interface directly, removeIf(Predicate) is supported only by collections of mutable profile, others are supported by ObjCollections with any mutability profile.


Method Summary
 ObjCursor<E> cursor()
          Returns a new cursor over this collection's elements.
 Equivalence<E> equivalence()
          Returns the equivalence strategy for elements in this collection.
 void forEach(Consumer<? super E> 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(Predicate<? super E> 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.
 ObjIterator<E> iterator()
          Returns a new iterator over this collection's elements.
 boolean removeIf(Predicate<? super E> filter)
          Removes all of the elements of this collection that satisfy the given predicate.
 
Methods inherited from interface Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
 
Methods inherited from interface com.koloboke.collect.Container
clear, ensureCapacity, isEmpty, shrink, size, sizeAsLong
 

Method Detail

equivalence

@Nonnull
Equivalence<E> equivalence()
Returns the equivalence strategy for elements in this collection. All methods in Collection interface which defined in terms of Object.equals(Object) equality of elements, for example, Collection.contains(Object) and Collection.remove(Object), are supposed to use this equivalence instead.

Returns:
the equivalence strategy for elements in this collection

forEach

void forEach(@Nonnull
             Consumer<? super E> 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
                     Predicate<? super E> 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

cursor

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

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

iterator

@Nonnull
ObjIterator<E> iterator()
Returns a new iterator over this collection's elements.

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

removeIf

boolean removeIf(@Nonnull
                 Predicate<? super E> 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