PCJ API
Version 1.2

bak.pcj.set
Class LongRangeSet

java.lang.Object
  extended bybak.pcj.AbstractLongCollection
      extended bybak.pcj.set.AbstractLongSet
          extended bybak.pcj.set.LongRangeSet
All Implemented Interfaces:
Cloneable, LongCollection, LongSet, LongSortedSet, Serializable

public class LongRangeSet
extends AbstractLongSet
implements LongSortedSet, Cloneable, Serializable

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

Implementation of LongSortedSet is supported from PCJ 1.2. Prior to 1.2, only LongSet was implemented.

Since:
1.0
See Also:
LongRange, Serialized Form

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

Constructor Detail

LongRangeSet

public LongRangeSet()
Creates a new empty range set.


LongRangeSet

public LongRangeSet(long[] 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.

LongRangeSet

public LongRangeSet(LongCollection 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(long v)
Description copied from interface: LongSortedSet
Adds an element to this set.

Specified by:
add in interface LongSortedSet
Overrides:
add in class AbstractLongCollection

iterator

public LongIterator iterator()
Description copied from interface: LongCollection
Returns an iterator over this collection.

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

first

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

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

last

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

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

headSet

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

tailSet

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

subSet

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

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

trimToSize

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

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

Specified by:
clear in interface LongCollection
Overrides:
clear in class AbstractLongCollection

contains

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

Specified by:
contains in interface LongCollection
Overrides:
contains in class AbstractLongCollection

hashCode

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

Specified by:
hashCode in interface LongCollection
Overrides:
hashCode in class AbstractLongSet

isEmpty

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

Specified by:
isEmpty in interface LongCollection
Overrides:
isEmpty in class AbstractLongCollection

size

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

Specified by:
size in interface LongCollection
Overrides:
size in class AbstractLongCollection

remove

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

Specified by:
remove in interface LongCollection
Overrides:
remove in class AbstractLongCollection

toArray

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

Specified by:
toArray in interface LongCollection
Overrides:
toArray in class AbstractLongCollection

containsAll

public boolean containsAll(LongRange 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:
AbstractLongCollection.containsAll(LongCollection)

addAll

public boolean addAll(LongRangeSet 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(long), addAll(LongRange), AbstractLongCollection.addAll(LongCollection), addAll(long, long), addAll(long[])

addAll

public boolean addAll(LongRange 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(long), addAll(LongRangeSet), AbstractLongCollection.addAll(LongCollection), addAll(long, long), addAll(long[])

addAll

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

Parameters:
a - the array of long values to add to this set.
Throws:
NullPointerException - if a is null.
See Also:
add(long), addAll(LongRange), addAll(LongRangeSet), AbstractLongCollection.addAll(LongCollection), addAll(long, long)

ranges

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