PCJ API
Version 1.2

bak.pcj.set
Class ShortRangeSet

java.lang.Object
  extended bybak.pcj.AbstractShortCollection
      extended bybak.pcj.set.AbstractShortSet
          extended bybak.pcj.set.ShortRangeSet
All Implemented Interfaces:
Cloneable, Serializable, ShortCollection, ShortSet, ShortSortedSet

public class ShortRangeSet
extends AbstractShortSet
implements ShortSortedSet, Cloneable, Serializable

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

Implementation of ShortSortedSet is supported from PCJ 1.2. Prior to 1.2, only ShortSet was implemented.

Since:
1.0
See Also:
ShortRange, Serialized Form

Constructor Summary
ShortRangeSet()
          Creates a new empty range set.
ShortRangeSet(short[] a)
          Creates a new empty range set containing specified values.
ShortRangeSet(ShortCollection c)
          Creates a new range set with the same elements as a specified collection.
 
Method Summary
 boolean add(short v)
          Adds an element to this set.
 boolean addAll(short[] a)
          Adds an array of short values to this set.
 boolean addAll(ShortRange range)
          Adds a specified range to this set.
 boolean addAll(ShortRangeSet c)
          Adds all the elements of a specified range set to this set.
 boolean addAll(short first, short last)
          Adds a specified range to this set.
 void clear()
          Clears this collection.
 Object clone()
          Returns a clone of this range set.
 boolean contains(short v)
          Indicates whether this collection contains a specified element.
 boolean containsAll(ShortRange range)
          Indicates whether all elements of a specified range is contained in this set.
 short first()
          Returns the lowest element of this set.
 int hashCode()
          Returns a hash code value for this collection.
 ShortSortedSet headSet(short to)
          Returns the subset of values lower than a specified value.
 boolean isEmpty()
          Indicates whether this collection is empty.
 ShortIterator iterator()
          Returns an iterator over this collection.
 short last()
          Returns the highest element of this set.
 ShortRange[] ranges()
          Returns the ranges of this set.
 boolean remove(short v)
          Removes a specified element from this collection.
 int size()
          Returns the number of elements in this collection.
 ShortSortedSet subSet(short from, short to)
          Returns the subset of values lower that a specified value and higher than or equal to another specified value.
 ShortSortedSet tailSet(short from)
          Returns the subset of values higher than or equal to a specified value.
 short[] toArray(short[] 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.AbstractShortSet
equals
 
Methods inherited from class bak.pcj.AbstractShortCollection
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.ShortCollection
addAll, containsAll, equals, removeAll, retainAll, toArray
 

Constructor Detail

ShortRangeSet

public ShortRangeSet()
Creates a new empty range set.


ShortRangeSet

public ShortRangeSet(short[] 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.

ShortRangeSet

public ShortRangeSet(ShortCollection 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(short v)
Description copied from interface: ShortSortedSet
Adds an element to this set.

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

iterator

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

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

first

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

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

last

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

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

headSet

public ShortSortedSet headSet(short to)
Description copied from interface: ShortSortedSet
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 ShortSortedSet
Parameters:
to - the upper bound of the returned set (not included).
Since:
1.2

tailSet

public ShortSortedSet tailSet(short from)
Description copied from interface: ShortSortedSet
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 ShortSortedSet
Parameters:
from - the lower bound of the returned set (included).
Since:
1.2

subSet

public ShortSortedSet subSet(short from,
                             short to)
Description copied from interface: ShortSortedSet
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 ShortSortedSet
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: AbstractShortCollection
Returns a string representation of this collection.

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

trimToSize

public void trimToSize()
Description copied from interface: ShortCollection
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 ShortCollection
Overrides:
trimToSize in class AbstractShortCollection

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: 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.

Specified by:
hashCode in interface ShortCollection
Overrides:
hashCode in class AbstractShortSet

isEmpty

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

Specified by:
isEmpty in interface ShortCollection
Overrides:
isEmpty 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

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

toArray

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

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

containsAll

public boolean containsAll(ShortRange 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:
AbstractShortCollection.containsAll(ShortCollection)

addAll

public boolean addAll(ShortRangeSet 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(short), addAll(ShortRange), AbstractShortCollection.addAll(ShortCollection), addAll(short, short), addAll(short[])

addAll

public boolean addAll(ShortRange 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(short), addAll(ShortRangeSet), AbstractShortCollection.addAll(ShortCollection), addAll(short, short), addAll(short[])

addAll

public boolean addAll(short first,
                      short 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(short[] a)
Adds an array of short values to this set.

Parameters:
a - the array of short values to add to this set.
Throws:
NullPointerException - if a is null.
See Also:
add(short), addAll(ShortRange), addAll(ShortRangeSet), AbstractShortCollection.addAll(ShortCollection), addAll(short, short)

ranges

public ShortRange[] 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