PCJ API
Version 1.2

bak.pcj.set
Class IntRangeSet

java.lang.Object
  extended bybak.pcj.AbstractIntCollection
      extended bybak.pcj.set.AbstractIntSet
          extended bybak.pcj.set.IntRangeSet
All Implemented Interfaces:
Cloneable, IntCollection, IntSet, IntSortedSet, Serializable

public class IntRangeSet
extends AbstractIntSet
implements IntSortedSet, Cloneable, Serializable

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

Implementation of IntSortedSet is supported from PCJ 1.2. Prior to 1.2, only IntSet was implemented.

Since:
1.0
See Also:
IntRange, Serialized Form

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

Constructor Detail

IntRangeSet

public IntRangeSet()
Creates a new empty range set.


IntRangeSet

public IntRangeSet(int[] 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.

IntRangeSet

public IntRangeSet(IntCollection 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(int v)
Description copied from interface: IntSortedSet
Adds an element to this set.

Specified by:
add in interface IntSortedSet
Overrides:
add in class AbstractIntCollection

iterator

public IntIterator iterator()
Description copied from interface: IntCollection
Returns an iterator over this collection.

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

first

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

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

last

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

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

headSet

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

tailSet

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

subSet

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

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

trimToSize

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

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: IntCollection
Clears this collection.

Specified by:
clear in interface IntCollection
Overrides:
clear in class AbstractIntCollection

contains

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

Specified by:
contains in interface IntCollection
Overrides:
contains in class AbstractIntCollection

hashCode

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

Specified by:
hashCode in interface IntCollection
Overrides:
hashCode in class AbstractIntSet

isEmpty

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

Specified by:
isEmpty in interface IntCollection
Overrides:
isEmpty in class AbstractIntCollection

size

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

Specified by:
size in interface IntCollection
Overrides:
size in class AbstractIntCollection

remove

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

Specified by:
remove in interface IntCollection
Overrides:
remove in class AbstractIntCollection

toArray

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

Specified by:
toArray in interface IntCollection
Overrides:
toArray in class AbstractIntCollection

containsAll

public boolean containsAll(IntRange 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:
AbstractIntCollection.containsAll(IntCollection)

addAll

public boolean addAll(IntRangeSet 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(int), addAll(IntRange), AbstractIntCollection.addAll(IntCollection), addAll(int, int), addAll(int[])

addAll

public boolean addAll(IntRange 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(int), addAll(IntRangeSet), AbstractIntCollection.addAll(IntCollection), addAll(int, int), addAll(int[])

addAll

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

Parameters:
a - the array of int values to add to this set.
Throws:
NullPointerException - if a is null.
See Also:
add(int), addAll(IntRange), addAll(IntRangeSet), AbstractIntCollection.addAll(IntCollection), addAll(int, int)

ranges

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