PCJ API
Version 1.2

bak.pcj.adapter
Class SetToDoubleSetAdapter

java.lang.Object
  extended bybak.pcj.AbstractDoubleCollection
      extended bybak.pcj.set.AbstractDoubleSet
          extended bybak.pcj.adapter.SetToDoubleSetAdapter
All Implemented Interfaces:
DoubleCollection, DoubleSet
Direct Known Subclasses:
SortedSetToDoubleSortedSetAdapter

public class SetToDoubleSetAdapter
extends AbstractDoubleSet
implements DoubleSet

This class represents adaptions of Java Collections Framework sets to primitive sets of double values. The adapter is implemented as a wrapper around the set. Thus, changes to the underlying set are reflected by this set 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:

      SetToDoubleSetAdapter s;
      ...
      assert s.validate();
  
or by letting the adapter throw an exception on illegal values:
      SetToDoubleSetAdapter 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  Set set
          The underlying set.
 
Constructor Summary
SetToDoubleSetAdapter(Set set)
          Creates a new adaption to a set of double values.
SetToDoubleSetAdapter(Set set, boolean validate)
          Creates a new adaption to a set of double values.
 
Method Summary
 boolean add(double v)
          Adds an element to this collection.
 void clear()
          Clears this collection.
 boolean contains(double v)
          Indicates whether this collection contains a specified element.
 void evalidate()
          Validates the set underlying this adapter and throws an exception if it is invalid.
 int hashCode()
          Returns a hash code value for this collection.
 DoubleIterator iterator()
          Returns an iterator over this collection.
 boolean remove(double v)
          Removes a specified element from this collection.
 int size()
          Returns the number of elements in this collection.
 boolean validate()
          Indicates whether the underlying set is valid for this adapter.
 
Methods inherited from class bak.pcj.set.AbstractDoubleSet
equals
 
Methods inherited from class bak.pcj.AbstractDoubleCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface bak.pcj.DoubleCollection
addAll, containsAll, equals, isEmpty, removeAll, retainAll, toArray, toArray, trimToSize
 

Field Detail

set

protected Set set
The underlying set.

Constructor Detail

SetToDoubleSetAdapter

public SetToDoubleSetAdapter(Set set)
Creates a new adaption to a set of double values.

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

SetToDoubleSetAdapter

public SetToDoubleSetAdapter(Set set,
                             boolean validate)
Creates a new adaption to a set of double values. The set to adapt is optionally validated.

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

add

public boolean add(double v)
Description copied from interface: DoubleCollection
Adds an element to this collection.

Specified by:
add in interface DoubleCollection
Overrides:
add in class AbstractDoubleCollection

clear

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

Specified by:
clear in interface DoubleCollection
Overrides:
clear in class AbstractDoubleCollection

contains

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

Specified by:
contains in interface DoubleCollection
Overrides:
contains in class AbstractDoubleCollection

hashCode

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

Specified by:
hashCode in interface DoubleCollection
Overrides:
hashCode in class AbstractDoubleSet

iterator

public DoubleIterator iterator()
Description copied from interface: DoubleCollection
Returns an iterator over this collection.

Specified by:
iterator in interface DoubleCollection
Returns:
an iterator over this collection.

remove

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

Specified by:
remove in interface DoubleCollection
Overrides:
remove in class AbstractDoubleCollection

size

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

Specified by:
size in interface DoubleCollection
Overrides:
size in class AbstractDoubleCollection

validate

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

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

evalidate

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

Throws:
IllegalStateException - if the underlying set 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