PCJ API
Version 1.2

bak.pcj.adapter
Class CharSetToSetAdapter

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractSet
          extended bybak.pcj.adapter.CharSetToSetAdapter
All Implemented Interfaces:
Collection, Set
Direct Known Subclasses:
CharSortedSetToSortedSetAdapter

public class CharSetToSetAdapter
extends AbstractSet

This class represents adapters of char sets to Java Collections Framework sets. The adapter is implemented as a wrapper around a primitive set. Thus, changes to the underlying set are reflected by this set and vice versa.

Since:
1.0
See Also:
CharSet, Set

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

Field Detail

set

protected CharSet set
The underlying primitive set.

Constructor Detail

CharSetToSetAdapter

public CharSetToSetAdapter(CharSet set)
Creates a new adaption of a set of char values to a Java Collections Framework set.

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

add

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

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

clear

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

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

contains

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

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

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

hashCode

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

Returns:
a hash code value for this set.

iterator

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

Returns:
an iterator over this set.

remove

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

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

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

retainAll

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

This method is only overridden to work around a bug in AbstractSet, which does not throw a NullPointerException when the argument is null and the set is empty. The bug is inherited from java.util.AbstractCollection.

Parameters:
c - the collection whose elements to retain in this collection.
Returns:
true if this set 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 set.
NullPointerException - if c is null.

size

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

Returns:
the number of elements in this set.

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