PCJ API
Version 1.2

bak.pcj.set
Class ByteRangeSet

java.lang.Object
  extended bybak.pcj.AbstractByteCollection
      extended bybak.pcj.set.AbstractByteSet
          extended bybak.pcj.set.ByteRangeSet
All Implemented Interfaces:
ByteCollection, ByteSet, ByteSortedSet, Cloneable, Serializable

public class ByteRangeSet
extends AbstractByteSet
implements ByteSortedSet, Cloneable, Serializable

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

Implementation of ByteSortedSet is supported from PCJ 1.2. Prior to 1.2, only ByteSet was implemented.

Since:
1.0
See Also:
ByteRange, Serialized Form

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

Constructor Detail

ByteRangeSet

public ByteRangeSet()
Creates a new empty range set.


ByteRangeSet

public ByteRangeSet(byte[] 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.

ByteRangeSet

public ByteRangeSet(ByteCollection 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(byte v)
Description copied from interface: ByteSortedSet
Adds an element to this set.

Specified by:
add in interface ByteSortedSet
Overrides:
add in class AbstractByteCollection

iterator

public ByteIterator iterator()
Description copied from interface: ByteCollection
Returns an iterator over this collection.

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

first

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

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

last

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

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

headSet

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

tailSet

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

subSet

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

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

trimToSize

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

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

Specified by:
clear in interface ByteCollection
Overrides:
clear in class AbstractByteCollection

contains

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

Specified by:
contains in interface ByteCollection
Overrides:
contains in class AbstractByteCollection

hashCode

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

Specified by:
hashCode in interface ByteCollection
Overrides:
hashCode in class AbstractByteSet

isEmpty

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

Specified by:
isEmpty in interface ByteCollection
Overrides:
isEmpty in class AbstractByteCollection

size

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

Specified by:
size in interface ByteCollection
Overrides:
size in class AbstractByteCollection

remove

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

Specified by:
remove in interface ByteCollection
Overrides:
remove in class AbstractByteCollection

toArray

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

Specified by:
toArray in interface ByteCollection
Overrides:
toArray in class AbstractByteCollection

containsAll

public boolean containsAll(ByteRange 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:
AbstractByteCollection.containsAll(ByteCollection)

addAll

public boolean addAll(ByteRangeSet 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(byte), addAll(ByteRange), AbstractByteCollection.addAll(ByteCollection), addAll(byte, byte), addAll(byte[])

addAll

public boolean addAll(ByteRange 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(byte), addAll(ByteRangeSet), AbstractByteCollection.addAll(ByteCollection), addAll(byte, byte), addAll(byte[])

addAll

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

Parameters:
a - the array of byte values to add to this set.
Throws:
NullPointerException - if a is null.
See Also:
add(byte), addAll(ByteRange), addAll(ByteRangeSet), AbstractByteCollection.addAll(ByteCollection), addAll(byte, byte)

ranges

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