|
LimeWire Collection Component API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.limewire.collection.IntervalSet
public class IntervalSet
Provides an interval of ranges (a "range" version of IntSet).
IntervalSet is = new IntervalSet();
is.add(Range.createRange(1,4));
is.add(Range.createRange(11,14));
is.add(Range.createRange(21,24));
System.out.println("Set is " + is + " intervals: " +
is.getNumberOfIntervals());
is.add(Range.createRange(5,10));
System.out.println("Set is " + is + " intervals: " +
is.getNumberOfIntervals());
IntervalSet is2 = is.invert(50);
System.out.println("Set is " + is2 + " intervals: " +
is2.getNumberOfIntervals());
Output:
Set is [1-4, 11-14, 21-24] intervals: 3
Set is [1-14, 21-24] intervals: 2
Set is [0, 15-20, 25-49] intervals: 3
| Nested Class Summary | |
|---|---|
static class |
IntervalSet.ByteIntervals
Allows you to keep int and long intervals in the same location. |
| Constructor Summary | |
|---|---|
IntervalSet()
|
|
IntervalSet(Range interval)
Creates an interval set with the given base range. |
|
| Method Summary | |
|---|---|
void |
add(IntervalSet set)
Adds a whole IntervalSet into this IntervalSet. |
void |
add(Range addInterval)
|
void |
clear()
|
IntervalSet |
clone()
Clones the IntervalSet. |
boolean |
contains(Range i)
|
boolean |
containsAny(Range i)
|
static IntervalSet |
createSingletonSet(long lowBound,
long highBound)
Creates an interval set representing a single Interval. |
void |
decode(long maxSize,
Integer... id)
decodes an interval set encoded with: http://www.limewire.org/wiki/index.php?title=HashTreeRangeEncoding |
void |
delete(IntervalSet set)
Deletes all intervals in the specified set from this set. |
void |
delete(Range deleteMe)
Deletes any overlap of existing intervals with the Interval to delete. |
Collection<Integer> |
encode(long maxSize)
encodes the current interval set as defined in http://www.limewire.org/wiki/index.php?title=HashTreeRangeEncoding |
boolean |
equals(Object o)
Compares two IntervalSets |
Iterator<Range> |
getAllIntervals()
|
List<Range> |
getAllIntervalsAsList()
|
Range |
getFirst()
Returns the first element without modifying this IntervalSet. |
Range |
getLast()
Returns the last element without modifying this IntervalSet. |
Iterator<Range> |
getNeededIntervals(long maxSize)
|
int |
getNumberOfIntervals()
|
List<Range> |
getOverlapIntervals(Range checkInterval)
|
long |
getSize()
|
IntervalSet |
invert(long maxSize)
Creates an IntervalSet that is the negative to this
IntervalSet. |
boolean |
isEmpty()
|
Iterator<Range> |
iterator()
|
static IntervalSet |
parseBytes(byte[] ranges,
byte[] ranges5)
Parses an IntervalSet from a byte array. |
IntervalSet.ByteIntervals |
toBytes()
|
String |
toString()
Lists the contained intervals. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public IntervalSet()
public IntervalSet(Range interval)
interval - - range to create the interval set with.| Method Detail |
|---|
public static IntervalSet createSingletonSet(long lowBound,
long highBound)
lowBound - the lower bound of the represented IntervalhighBound - the upper bound of the represented Interval
public void add(Range addInterval)
public void add(IntervalSet set)
IntervalSet into this IntervalSet.
public void delete(Range deleteMe)
deleteMe - the Interval that should be deleted.public void delete(IntervalSet set)
public Range getFirst()
throws NoSuchElementException
IntervalSet.
NoSuchElementException - if no intervals exist.
NoSuchElementException
public Range getLast()
throws NoSuchElementException
IntervalSet.
NoSuchElementException - if no intervals exist.
NoSuchElementExceptionpublic int getNumberOfIntervals()
IntervalSet.public boolean contains(Range i)
public boolean containsAny(Range i)
public List<Range> getOverlapIntervals(Range checkInterval)
List of intervals that overlap
checkInterval. For example
if Intervals contains{[1-4],[6-10]} and checkInterval is
[3-8], this method returns a list of 2 intervals {[3-4],[6-8]}.
If there are no overlaps, this method returns an empty List.public Iterator<Range> getAllIntervals()
public Iterator<Range> iterator()
iterator in interface Iterable<Range>public List<Range> getAllIntervalsAsList()
public long getSize()
public boolean isEmpty()
public void clear()
public Collection<Integer> encode(long maxSize)
public void decode(long maxSize,
Integer... id)
maxSize - the size of the fileid - integers from the encodingpublic IntervalSet invert(long maxSize)
IntervalSet that is the negative to this
IntervalSet.
IntervalSet containing all ranges not contained in thispublic Iterator<Range> getNeededIntervals(long maxSize)
IntervalSet. Note that the IntervalSet does
not know the maximum value of all the intervals.
public IntervalSet clone()
throws CloneNotSupportedException
IntervalSet. The underlying intervals are the same
(so they should never be modified), but the TreeSet this is
backed off of is new.
clone in class ObjectCloneNotSupportedExceptionpublic String toString()
toString in class Objectpublic boolean equals(Object o)
IntervalSets
equals in class Objectpublic IntervalSet.ByteIntervals toBytes()
public static IntervalSet parseBytes(byte[] ranges,
byte[] ranges5)
throws IOException
IntervalSet from a byte array. At position 0 are
intervals that fit in 31 bits, at position 1 are those that
need 40 bits.
IOException
|
LimeWire Collection Component API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||