PCJ API
Version 1.2

bak.pcj.adapter
Class LongCollectionToCollectionAdapter

java.lang.Object
  extended byjava.util.AbstractCollection
      extended bybak.pcj.adapter.LongCollectionToCollectionAdapter
All Implemented Interfaces:
Collection

public class LongCollectionToCollectionAdapter
extends AbstractCollection

This class represents adaptions of primitive collections of long values to Java Collections Framework collections. The adapter is implemented as a wrapper around a primitive collection. Thus, changes to the underlying collection are reflected by this collection and vice versa.

Since:
1.0
See Also:
LongCollection, Collection

Field Summary
protected  LongCollection collection
          The underlying primitive collection.
 
Constructor Summary
LongCollectionToCollectionAdapter(LongCollection collection)
          Creates a new adaption of a collection of long values to a Java Collections Framework collection.
 
Method Summary
 boolean add(Object o)
          Adds an element to this collection.
 void clear()
          Clears this collection.
 boolean contains(Object o)
          Indicates whether this collection contains a specified element.
 int hashCode()
          Returns a hash code value for this collection.
 Iterator iterator()
          Returns an iterator over this collection.
 boolean remove(Object o)
          Removes a specified element from this collection.
 boolean removeAll(Collection c)
          Removes all the elements of a specified collection from this collection.
 boolean retainAll(Collection c)
          Retains only the elements of a specified collection in this collection.
 int size()
          Returns the number of elements in this collection.
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals
 

Field Detail

collection

protected LongCollection collection
The underlying primitive collection.

Constructor Detail

LongCollectionToCollectionAdapter

public LongCollectionToCollectionAdapter(LongCollection collection)
Creates a new adaption of a collection of long values to a Java Collections Framework collection.

Parameters:
collection - the underlying primitive collection.
Throws:
NullPointerException - if collection is null.
Method Detail

add

public boolean add(Object o)
Adds an element to this collection. The element is added to the underlying collection.

Parameters:
o - the element to add to this collection.
Returns:
true if this collection was modified as a result of adding o; returns false otherwise.
Throws:
IllegalArgumentException - if o is null.
ClassCastException - if o is not of class Long.
UnsupportedOperationException - if the operation is not supported by the underlying collection.

clear

public void clear()
Clears this collection. The underlying collection is cleared.

Throws:
UnsupportedOperationException - if the operation is not supported by the underlying collection.

contains

public boolean contains(Object o)
Indicates whether this collection contains a specified element. For this collection to contain an object, the underlying collection must contain its unwrapped value.

Note that this collection can never contain null values or values of other classes than Long. In those cases, this method will return false.

Parameters:
o - the element to test for containment.
Returns:
true if o is contained in this collection; returns false otherwise.

iterator

public Iterator iterator()
Returns an iterator over this collection.

Returns:
an iterator over this collection.

remove

public boolean remove(Object o)
Removes a specified element from this collection. The unwrapped element is removed from the underlying collection.

Note that this collection can never contain null values or values of other classes than Long. In those cases, this method will return false.

Parameters:
o - the Long value to remove from this collection.
Returns:
true if this collection was modified as a result of removing o; returns false otherwise.
Throws:
UnsupportedOperationException - if the operation is not supported by the underlying collection.

removeAll

public boolean removeAll(Collection c)
Removes all the elements of a specified collection from this collection. The unwrapped elements are removed from the underlying collection.

This method is only overridden to work around a bug in AbstractCollection, which does not throw a NullPointerException when the argument is null and the collection is empty.

Parameters:
c - the collection whose elements to remove from this collection.
Returns:
true if this collection was modified as a result of removing the elements of c; returns false otherwise.
Throws:
UnsupportedOperationException - if the operation is not supported by the underlying collection.
NullPointerException - if c is null.

retainAll

public boolean retainAll(Collection c)
Retains only the elements of a specified collection in this collection. The unwrapped elements are removed from the underlying collection.

This method is only overridden to work around a bug in AbstractCollection, which does not throw a NullPointerException when the argument is null and the collection is empty.

Parameters:
c - the collection whose elements to retain in this collection.
Returns:
true if this collection was modified as a result of removing the elements not contained in c; returns false otherwise.
Throws:
UnsupportedOperationException - if the operation is not supported by the underlying collection.
NullPointerException - if c is null.

size

public int size()
Returns the number of elements in this collection. The number of elements is the same as that of the underlying collection.

Returns:
the number of elements in this collection.

hashCode

public int hashCode()
Returns a hash code value for this collection. The hash code returned is that of the underlying collection.

Returns:
a hash code value for this collection.

PCJ API
Version 1.2

Report a bug or request a feature.
Further information on the development and latest release of PCJ can be found at the project homepage.

Primitive Collections for Java is released under the GNU Lesser General Public License.
Copyright © 2002, 2003 Søren Bak. All Rights Reserved.

Hosted by SourceForge.net
SourceForge.net Logo