org.apache.ace.range
Class SortedRangeSet

java.lang.Object
  extended by org.apache.ace.range.SortedRangeSet

public class SortedRangeSet
extends Object

Collection that stores a sorted set of ranges and is able to represent them as a string.


Field Summary
static SortedRangeSet FULL_SET
          A static set which contains all possible values.
 
Constructor Summary
SortedRangeSet(long[] items)
          Creates a new instance from an array of longs.
SortedRangeSet(String representation)
          Creates a new instance from a string representation.
 
Method Summary
 boolean contains(long number)
          Checks if a number falls within any range in this set.
 SortedRangeSet diffDest(SortedRangeSet dest)
          Creates the difference between this set and dest, by (in set notation)
result = dest \ this,
that is, if dest = {1, 2} and this = {2, 3}, then result = {1, 2} \ {2, 3} = {1}
 long getHigh()
          Returns the highest value present in any of the ranges in this SortredRangeSet.
 RangeIterator iterator()
          Returns an iterator that iterates over all the ranges in this set.
 String toRepresentation()
          Retrieve a string representation of the SortedRangeSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FULL_SET

public static final SortedRangeSet FULL_SET
A static set which contains all possible values.

Constructor Detail

SortedRangeSet

public SortedRangeSet(String representation)
Creates a new instance from a string representation.

Parameters:
representation - The string representation of a SortedRangeSet.
Throws:
NumberFormatException - If the string representation does not contain a valid SortedRangeSet.

SortedRangeSet

public SortedRangeSet(long[] items)
Creates a new instance from an array of longs.

Parameters:
items - Array of longs
Method Detail

toRepresentation

public String toRepresentation()
Retrieve a string representation of the SortedRangeSet.

Returns:
A string representation of the SortedRangeSet.

diffDest

public SortedRangeSet diffDest(SortedRangeSet dest)
Creates the difference between this set and dest, by (in set notation)
result = dest \ this,
that is, if dest = {1, 2} and this = {2, 3}, then result = {1, 2} \ {2, 3} = {1}

Parameters:
dest - The set from which this set should be 'set-minussed'.
Returns:
The resulting set after the diff.

contains

public boolean contains(long number)
Checks if a number falls within any range in this set.

Parameters:
number - the number to check
Returns:
true if the number was inside any range in this set

iterator

public RangeIterator iterator()
Returns an iterator that iterates over all the ranges in this set.

Returns:
a range iterator

getHigh

public long getHigh()
Returns the highest value present in any of the ranges in this SortredRangeSet.

Returns:
the highest value present in any of the ranges in this SortredRangeSet or 0 if the SortedRangeSet is empty.


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.