|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.utils.intcollections.IntRangeList
public class IntRangeList
A set of non-negative integers.
The set is maintained as a list of integer ranges in increasing order with no overlap and with automatic coalescing of adjacent ranges.
Inspired by the traditional Usenet "newsrc" format.
Field Summary | |
---|---|
(package private) static long |
serialVersionUID
Serial version UID. |
Constructor Summary | |
---|---|
IntRangeList()
Constructs a new empty list. |
|
IntRangeList(int x)
Constructs a new list with an initial single element. |
|
IntRangeList(int first,
int last)
Constructs a new list with an initial range. |
|
IntRangeList(IntRange range)
Constructs a new list from an IntRange object. |
|
IntRangeList(java.lang.String str)
Constructs a new list from a string representation. |
Method Summary | |
---|---|
void |
add(int x)
Adds an integer to the list. |
void |
add(int first,
int last)
Adds a range of integers to the list. |
void |
add(IntRange range)
Adds an integer range to the list. |
IntRangeList |
centerInterval(int x,
int delta)
Gets a centered interval from the list. |
void |
clear()
Clears the list. |
java.lang.Object |
clone()
Returns a copy of the list. |
IntRangeList |
complement(int max)
Returns a new list which is the complement of the list. |
boolean |
contains(int x)
Returns true if the list contains an integer. |
boolean |
contains(int first,
int last)
Returns true if the list contains a range of integers. |
boolean |
contains(IntRangeList other)
Returns true if the list contains another list. |
IntRangeList |
difference(IntRangeList other)
Returns a new list which is this list minus another list. |
boolean |
equals(java.lang.Object other)
Compares this list to another list. |
int |
first()
Gets the first integer in the list. |
int |
get(int i)
Gets the i'th integer in the list. |
int |
indexOf(int x)
Gets the index of a list element. |
IntRangeList |
intersect(IntRangeList other)
Returns a new list which is the intersection of this list with another list. |
IntIterator |
intIterator()
Returns an IntIterator for the list. |
boolean |
isEmpty()
Returns true if the list is empty. |
(package private) boolean |
isValid()
Checks to see if the list is valid. |
int |
last()
Gets the last integer in the list. |
IntRangeList |
leftInterval(int x,
int delta)
Gets a left interval from the list. |
java.util.Iterator |
rangeIterator()
Returns a range iterator for the list. |
void |
readExternal(java.io.ObjectInput in)
Reads the list on deserialization. |
void |
remove(int x)
Removes an integer from the list. |
void |
remove(int first,
int last)
Removes a range of integers from the list. |
void |
remove(IntRange range)
Removes an integer range from the list. |
IntRangeList |
rightInterval(int x,
int delta)
Gets a right interval from the list. |
void |
set(int first,
int last)
Sets the list to a range. |
int |
size()
Returns the size of the list. |
java.lang.String |
toString()
Returns a string representation of the list. |
IntRangeList |
union(IntRangeList other)
Returns a new list which is the union of this list and another list. |
void |
writeExternal(java.io.ObjectOutput out)
Writes the list on serialization. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static final long serialVersionUID
Constructor Detail |
---|
public IntRangeList()
public IntRangeList(int x)
x
- The initial single element. public IntRangeList(int first, int last)
first
- The first integer in the range.last
- The last integer in the range + 1. public IntRangeList(IntRange range)
range
- The IntRange object. public IntRangeList(java.lang.String str)
See toString()
for a description of string representations
of integer range lists.
str
- The string.
java.lang.IllegalArgumentException
- If syntax error in string. Method Detail |
---|
public IntIterator intIterator()
IntIterator
for the list.
The iterator returns the integer list elements in increasing order. The "remove" method is not supported.
IntIterator
for the list. public java.util.Iterator rangeIterator()
The IntRange objects returned by the iterator are cloned. If they are modifed the list is unaffected. They are returned in increasing order. The "remove" method is not supported.
public int size()
The value returned is the number of integers in the list, not the number of ranges.
public boolean isEmpty()
public int get(int i)
i
- The index in the list of the integer to return.
public int indexOf(int x)
x
- The list element.
public int first()
public int last()
public void clear()
public void set(int first, int last)
first
- The first integer in the range.last
- The last integer in the range + 1. public void add(int x)
x
- The integer public void add(int first, int last)
first
- The first integer in the range.last
- The last integer in the range + 1. public void add(IntRange range)
range
- The integer range. public void remove(int x)
x
- The integer public void remove(int first, int last)
first
- The first integer in the range.last
- The last integer in the range + 1. public void remove(IntRange range)
range
- The integer range. public boolean contains(int x)
x
- The integer.
public boolean contains(int first, int last)
first
- The first integer in the range.last
- The last integer in the range + 1.
public boolean contains(IntRangeList other)
other
- The other list.
public IntRangeList rightInterval(int x, int delta)
The interval returned is another IntRangeList which is a sublist of this list. The sublist contains the specified left endpoint of the interval x plus the delta-1 elements following the left endpoint. If there aren't that many elements following the endpoint, as many as possible are included.
x
- The left endpoint of the interval.delta
- The number of elements after the endpoint + 1.
public IntRangeList leftInterval(int x, int delta)
The interval returned is another IntRangeList which is a sublist of this list. The sublist contains the delta elements preceding the specified right endpoint x, but does not include x. If there aren't that many elements preceding the endpoint, as many as possible are included.
x
- The right endpoint of the interval.delta
- The number of elements before the endpoint.
public IntRangeList centerInterval(int x, int delta)
The interval returned is another IntRangeList which is a sublist of this list. The sublist contains the delta elements preceding the midpoint, the midpoint, and the delta-1 elements following the midpoint. If there aren't that many elements preceding and/or following the midpoint, as many as possible are included.
x
- The midpoint of the interval.delta
- The range before and after the midpoint.
public IntRangeList complement(int max)
max
- Maximum value + 1 for complemented list.
public IntRangeList union(IntRangeList other)
other
- The other list.
public IntRangeList intersect(IntRangeList other)
other
- The other list.
public IntRangeList difference(IntRangeList other)
other
- The other list.
public java.lang.String toString()
The string representation is "xxx,xxx,xxx,...,xxx" where each "xxx" is one integer "a" or is a range of integers "a-b".
Note that the end of each range is inclusive in the string representation, while it is exclusive in the API. For example, a call to "add(10,20)" adds the integers 10 to but not including 20 to the list. When represented as a string the notation is "10-19" meaning "10 through 19 inclusive."
toString
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- The other list.
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
out
- Object output stream.
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
in
- Object input stream.
java.io.IOException
java.lang.ClassNotFoundException
boolean isValid()
For debugging.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |