org.rightcollections.impl
Class AbstractRightCollection<E>

java.lang.Object
  extended by org.rightcollections.impl.AbstractRightCollection<E>
Type Parameters:
E - type of elements.
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, Closurable<E>, Filterable<E>, MaxCalculator<E>, RightCollection<E>
Direct Known Subclasses:
RightCollectionImpl, RightListImpl, RightSetImpl

public abstract class AbstractRightCollection<E>
extends java.lang.Object
implements RightCollection<E>

Abstract implementation for collections.

Author:
Ruslan Pilin

Constructor Summary
AbstractRightCollection()
           
 
Method Summary
 boolean add(E e)
           
 boolean addAll(java.util.Collection<? extends E> c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection<?> c)
           
 boolean equals(java.lang.Object o)
           
<T extends Closure<E>>
T
execute(T closure)
          Executes closure on each element of collection.
 void filter(Predicate<E> predicate)
          Filters collection by predicate.
protected abstract  java.util.Collection<E> getCollection()
          Method for implementing by subclasses have to return collection to delegate all collection methods to.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Iterator<E> iterator()
           
 E max()
          Calculates maximum based on netural order.
 E max(java.util.Comparator<E> comparator)
          Calculates maximum based on comparator.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection<?> c)
           
 boolean retainAll(java.util.Collection<?> c)
           
 int size()
           
 java.lang.Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRightCollection

public AbstractRightCollection()
Method Detail

add

public boolean add(E e)
Specified by:
add in interface java.util.Collection<E>
Parameters:
e - element
Returns:
true if this collection changed as a result of the call
See Also:
Collection.add(java.lang.Object)

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Specified by:
addAll in interface java.util.Collection<E>
Parameters:
c -
Returns:
See Also:
Collection.addAll(java.util.Collection)

clear

public void clear()
Specified by:
clear in interface java.util.Collection<E>
See Also:
Collection.clear()

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<E>
Parameters:
o -
Returns:
See Also:
Collection.contains(java.lang.Object)

containsAll

public boolean containsAll(java.util.Collection<?> c)
Specified by:
containsAll in interface java.util.Collection<E>
Parameters:
c -
Returns:
See Also:
Collection.containsAll(java.util.Collection)

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection<E>
Overrides:
equals in class java.lang.Object
Parameters:
o -
Returns:
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection<E>
Overrides:
hashCode in class java.lang.Object
Returns:
See Also:
Object.hashCode()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<E>
Returns:
See Also:
Collection.isEmpty()

iterator

public java.util.Iterator<E> iterator()
Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Returns:
See Also:
Collection.iterator()

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<E>
Parameters:
o -
Returns:
See Also:
Collection.remove(java.lang.Object)

removeAll

public boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<E>
Parameters:
c -
Returns:
See Also:
Collection.removeAll(java.util.Collection)

retainAll

public boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<E>
Parameters:
c -
Returns:
See Also:
Collection.retainAll(java.util.Collection)

size

public int size()
Specified by:
size in interface java.util.Collection<E>
Returns:
See Also:
Collection.size()

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<E>
Returns:
See Also:
Collection.toArray()

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface java.util.Collection<E>
Type Parameters:
T -
Parameters:
a -
Returns:
See Also:
java.util.Collection#toArray(T[])

getCollection

protected abstract java.util.Collection<E> getCollection()
Method for implementing by subclasses have to return collection to delegate all collection methods to.

Returns:
internal collection.

max

public E max()
Description copied from interface: MaxCalculator
Calculates maximum based on netural order.

Specified by:
max in interface MaxCalculator<E>
Returns:
See Also:
MaxCalculator.max()

execute

public <T extends Closure<E>> T execute(T closure)
Description copied from interface: Closurable
Executes closure on each element of collection.

Specified by:
execute in interface Closurable<E>
Type Parameters:
T - type of closure to execute on each element of collection.
Parameters:
closure - closure to execute on each element of collection.
Returns:
closure passed by parameter to extract the result from it.
See Also:
Closurable.execute(org.rightcollections.Closure)

filter

public void filter(Predicate<E> predicate)
Description copied from interface: Filterable
Filters collection by predicate. (removes elemets where predicate(element) = false)

Specified by:
filter in interface Filterable<E>
Parameters:
predicate -
See Also:
Filterable.filter(org.rightcollections.Predicate)

max

public E max(java.util.Comparator<E> comparator)
Description copied from interface: MaxCalculator
Calculates maximum based on comparator.

Specified by:
max in interface MaxCalculator<E>
Parameters:
comparator - comparator to compare elements
Returns:
maximum element


Copyright © 2009 Ruslan Pilin. All Rights Reserved.