PCJ API
Version 1.2

bak.pcj.adapter
Class CollectionToShortCollectionAdapter

java.lang.Object
  extended bybak.pcj.AbstractShortCollection
      extended bybak.pcj.adapter.CollectionToShortCollectionAdapter
All Implemented Interfaces:
ShortCollection

public class CollectionToShortCollectionAdapter
extends AbstractShortCollection

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

Adapters from JCF collections to primitive collections will fail if the JCF collection contains null values or values of the wrong class. However, adapters are not fast failing in the case that the underlying collection should contain illegal values. To implement fast failure would require every operation to check every element of the underlying collection before doing anything. Instead validation methods are provided. They can be called using the assertion facility in the client code:

      CollectionToShortCollectionAdapter s;
      ...
      assert s.validate();
  
or by letting the adapter throw an exception on illegal values:
      CollectionToShortCollectionAdapter s;
      ...
      s.evalidate();  // Throws an exception on illegal values
  
Either way, validation must be invoked directly by the client code.

Since:
1.0

Field Summary
protected  Collection collection
          The underlying collection.
 
Constructor Summary
CollectionToShortCollectionAdapter(Collection collection)
          Creates a new adaption of a collection to a collection of short values.
CollectionToShortCollectionAdapter(Collection collection, boolean validate)
          Creates a new adaption of a collection to a collection of short values.
 
Method Summary
 boolean add(short v)
          Throws UnsupportedOperationException.
 void clear()
          Clears this collection.
 boolean contains(short v)
          Indicates whether this collection contains a specified element.
 void evalidate()
          Validates the collection underlying this adapter and throws an exception if it is invalid.
 int hashCode()
          Returns a hash code value for this collection.
 ShortIterator iterator()
          Returns an iterator over this collection.
 boolean remove(short v)
          Removes a specified element from this collection.
 int size()
          Returns the number of elements in this collection.
 boolean validate()
          Indicates whether the underlying collection is valid for this adapter.
 
Methods inherited from class bak.pcj.AbstractShortCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface bak.pcj.ShortCollection
equals
 

Field Detail

collection

protected Collection collection
The underlying collection.

Constructor Detail

CollectionToShortCollectionAdapter

public CollectionToShortCollectionAdapter(Collection collection)
Creates a new adaption of a collection to a collection of short values.

Parameters:
collection - the underlying collection. This collection must consist of values of class Short. Otherwise a ClassCastException will be thrown by some methods.
Throws:
NullPointerException - if collection is null.

CollectionToShortCollectionAdapter

public CollectionToShortCollectionAdapter(Collection collection,
                                          boolean validate)
Creates a new adaption of a collection to a collection of short values. The collection to adapt is optionally validated.

Parameters:
collection - the underlying collection. This collection must consist of values of class Short. Otherwise a ClassCastException will be thrown by some methods.
validate - indicates whether collection should be checked for illegal values.
Throws:
NullPointerException - if collection is null.
IllegalStateException - if validate is true and collection contains a null value or a value that is not of class Short.
Method Detail

add

public boolean add(short v)
Description copied from class: AbstractShortCollection
Throws UnsupportedOperationException.

Specified by:
add in interface ShortCollection
Overrides:
add in class AbstractShortCollection

clear

public void clear()
Description copied from interface: ShortCollection
Clears this collection.

Specified by:
clear in interface ShortCollection
Overrides:
clear in class AbstractShortCollection

contains

public boolean contains(short v)
Description copied from interface: ShortCollection
Indicates whether this collection contains a specified element.

Specified by:
contains in interface ShortCollection
Overrides:
contains in class AbstractShortCollection

hashCode

public int hashCode()
Description copied from interface: ShortCollection
Returns a hash code value for this collection.


iterator

public ShortIterator iterator()
Description copied from interface: ShortCollection
Returns an iterator over this collection.

Returns:
an iterator over this collection.

remove

public boolean remove(short v)
Description copied from interface: ShortCollection
Removes a specified element from this collection.

Specified by:
remove in interface ShortCollection
Overrides:
remove in class AbstractShortCollection

size

public int size()
Description copied from interface: ShortCollection
Returns the number of elements in this collection.

Specified by:
size in interface ShortCollection
Overrides:
size in class AbstractShortCollection

validate

public boolean validate()
Indicates whether the underlying collection is valid for this adapter. For the underlying collection to be valid, it can only contain Short values and no null values.

Returns:
true if the underlying collection is valid; returns false otherwise.

evalidate

public void evalidate()
Validates the collection underlying this adapter and throws an exception if it is invalid. For the underlying collection to be valid, it can only contain Short values and no null values.

Throws:
IllegalStateException - if the underlying collection is invalid.

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