PCJ API
Version 1.2

bak.pcj.set
Class CharRangeSet

java.lang.Object
  extended bybak.pcj.AbstractCharCollection
      extended bybak.pcj.set.AbstractCharSet
          extended bybak.pcj.set.CharRangeSet
All Implemented Interfaces:
CharCollection, CharSet, CharSortedSet, Cloneable, Serializable

public class CharRangeSet
extends AbstractCharSet
implements CharSortedSet, Cloneable, Serializable

This class represents range based sets of char values. The implementation is optimized for cases where most set elements fall into ranges of consecutive char values.

Implementation of CharSortedSet is supported from PCJ 1.2. Prior to 1.2, only CharSet was implemented.

Since:
1.0
See Also:
CharRange, Serialized Form

Constructor Summary
CharRangeSet()
          Creates a new empty range set.
CharRangeSet(char[] a)
          Creates a new empty range set containing specified values.
CharRangeSet(CharCollection c)
          Creates a new range set with the same elements as a specified collection.
 
Method Summary
 boolean add(char v)
          Adds an element to this set.
 boolean addAll(char[] a)
          Adds an array of char values to this set.
 boolean addAll(char first, char last)
          Adds a specified range to this set.
 boolean addAll(CharRange range)
          Adds a specified range to this set.
 boolean addAll(CharRangeSet c)
          Adds all the elements of a specified range set to this set.
 void clear()
          Clears this collection.
 Object clone()
          Returns a clone of this range set.
 boolean contains(char v)
          Indicates whether this collection contains a specified element.
 boolean containsAll(CharRange range)
          Indicates whether all elements of a specified range is contained in this set.
 char first()
          Returns the lowest element of this set.
 int hashCode()
          Returns a hash code value for this collection.
 CharSortedSet headSet(char to)
          Returns the subset of values lower than a specified value.
 boolean isEmpty()
          Indicates whether this collection is empty.
 CharIterator iterator()
          Returns an iterator over this collection.
 char last()
          Returns the highest element of this set.
 CharRange[] ranges()
          Returns the ranges of this set.
 boolean remove(char v)
          Removes a specified element from this collection.
 int size()
          Returns the number of elements in this collection.
 CharSortedSet subSet(char from, char to)
          Returns the subset of values lower that a specified value and higher than or equal to another specified value.
 CharSortedSet tailSet(char from)
          Returns the subset of values higher than or equal to a specified value.
 char[] toArray(char[] a)
          Returns the elements of this collection as an array.
 String toString()
          Returns a string representation of this collection.
 void trimToSize()
          Minimizes the memory used by this collection.
 
Methods inherited from class bak.pcj.set.AbstractCharSet
equals
 
Methods inherited from class bak.pcj.AbstractCharCollection
addAll, containsAll, removeAll, retainAll, toArray
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface bak.pcj.CharCollection
addAll, containsAll, equals, removeAll, retainAll, toArray
 

Constructor Detail

CharRangeSet

public CharRangeSet()
Creates a new empty range set.


CharRangeSet

public CharRangeSet(char[] a)
Creates a new empty range set containing specified values.

Parameters:
a - the values that the new set should contain.
Throws:
NullPointerException - if a is null.

CharRangeSet

public CharRangeSet(CharCollection c)
Creates a new range set with the same elements as a specified collection.

Parameters:
c - the collection whose elements to add to the new set.
Throws:
NullPointerException - if c is null.
Method Detail

add

public boolean add(char v)
Description copied from interface: CharSortedSet
Adds an element to this set.

Specified by:
add in interface CharSortedSet
Overrides:
add in class AbstractCharCollection

iterator

public CharIterator iterator()
Description copied from interface: CharCollection
Returns an iterator over this collection.

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

first

public char first()
Description copied from interface: CharSortedSet
Returns the lowest element of this set.

Specified by:
first in interface CharSortedSet
Returns:
the lowest element of this set.
Since:
1.2

last

public char last()
Description copied from interface: CharSortedSet
Returns the highest element of this set.

Specified by:
last in interface CharSortedSet
Returns:
the highest element of this set.
Since:
1.2

headSet

public CharSortedSet headSet(char to)
Description copied from interface: CharSortedSet
Returns the subset of values lower than a specified value. The returned subset is a view of this set, so changes to the subset are reflected by this set and vice versa.

Specified by:
headSet in interface CharSortedSet
Parameters:
to - the upper bound of the returned set (not included).
Since:
1.2

tailSet

public CharSortedSet tailSet(char from)
Description copied from interface: CharSortedSet
Returns the subset of values higher than or equal to a specified value. The returned subset is a view of this set, so changes to the subset are reflected by this set and vice versa.

Specified by:
tailSet in interface CharSortedSet
Parameters:
from - the lower bound of the returned set (included).
Since:
1.2

subSet

public CharSortedSet subSet(char from,
                            char to)
Description copied from interface: CharSortedSet
Returns the subset of values lower that a specified value and higher than or equal to another specified value. The returned subset is a view of this set, so changes to the subset are reflected by this set and vice versa.

Specified by:
subSet in interface CharSortedSet
Parameters:
from - the lower bound of the returned set (included).
to - the upper bound of the returned set (not included).
Since:
1.2

toString

public String toString()
Description copied from class: AbstractCharCollection
Returns a string representation of this collection.

Overrides:
toString in class AbstractCharCollection
Returns:
a string representation of this collection.

trimToSize

public void trimToSize()
Description copied from interface: CharCollection
Minimizes the memory used by this collection. The exact operation of this method depends on the class implementing it. Implementors may choose to ignore it completely.

Specified by:
trimToSize in interface CharCollection
Overrides:
trimToSize in class AbstractCharCollection

clone

public Object clone()
Returns a clone of this range set.

Returns:
a clone of this range set.
Since:
1.1

clear

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

Specified by:
clear in interface CharCollection
Overrides:
clear in class AbstractCharCollection

contains

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

Specified by:
contains in interface CharCollection
Overrides:
contains in class AbstractCharCollection

hashCode

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

Specified by:
hashCode in interface CharCollection
Overrides:
hashCode in class AbstractCharSet

isEmpty

public boolean isEmpty()
Description copied from interface: CharCollection
Indicates whether this collection is empty.

Specified by:
isEmpty in interface CharCollection
Overrides:
isEmpty in class AbstractCharCollection

size

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

Specified by:
size in interface CharCollection
Overrides:
size in class AbstractCharCollection

remove

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

Specified by:
remove in interface CharCollection
Overrides:
remove in class AbstractCharCollection

toArray

public char[] toArray(char[] a)
Description copied from interface: CharCollection
Returns the elements of this collection as an array.

Specified by:
toArray in interface CharCollection
Overrides:
toArray in class AbstractCharCollection

containsAll

public boolean containsAll(CharRange range)
Indicates whether all elements of a specified range is contained in this set.

Parameters:
range - the range whose elements to test for containment.
Returns:
true if all the elements of range are contained in this collection; returns false otherwise.
Throws:
NullPointerException - if range is null.
See Also:
AbstractCharCollection.containsAll(CharCollection)

addAll

public boolean addAll(CharRangeSet c)
Adds all the elements of a specified range set to this set.

Parameters:
c - the set whose elements to add to this set.
Returns:
true if this set was modified as a result of adding the elements of c; returns false otherwise.
Throws:
NullPointerException - if c is null.
See Also:
add(char), addAll(CharRange), AbstractCharCollection.addAll(CharCollection), addAll(char, char), addAll(char[])

addAll

public boolean addAll(CharRange range)
Adds a specified range to this set.

Parameters:
range - the range to add to this set.
Returns:
true if this set was modified as a result of adding the elements of range; returns false otherwise.
Throws:
NullPointerException - if range is null.
See Also:
add(char), addAll(CharRangeSet), AbstractCharCollection.addAll(CharCollection), addAll(char, char), addAll(char[])

addAll

public boolean addAll(char first,
                      char last)
Adds a specified range to this set.

Parameters:
first - the first value of the range to add to this set.
last - the last value of the range to add to this set.
Returns:
true if this set was modified as a result of adding the values first to last; returns false otherwise.
Throws:
IllegalArgumentException - if first > last.

addAll

public boolean addAll(char[] a)
Adds an array of char values to this set.

Parameters:
a - the array of char values to add to this set.
Throws:
NullPointerException - if a is null.
See Also:
add(char), addAll(CharRange), addAll(CharRangeSet), AbstractCharCollection.addAll(CharCollection), addAll(char, char)

ranges

public CharRange[] ranges()
Returns the ranges of this set. None of the ranges returned will overlap or be adjacent.

Returns:
the ranges of this set. The returned array is a fresh copy that can be modified without modifying 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