edu.umd.cfar.lamp.viper.util
Class LengthwiseEncodedList

java.lang.Object
  extended byedu.umd.cfar.lamp.viper.util.LengthwiseEncodedList
All Implemented Interfaces:
ArbitraryIndexList, java.lang.Cloneable

public class LengthwiseEncodedList
extends java.lang.Object
implements java.lang.Cloneable, ArbitraryIndexList

A list, with the elements run length encoded. It offers log n access and edit time, on average. Note that it uses the equals method to check equality, not ==, so null elements will not be accepted. Setting a range to null is the same as removing that range. It does not implement java.util.List, as it takes java.util.Comparable indexes instead of ints.


Constructor Summary
LengthwiseEncodedList()
          Creates a new instance of LengthwiseEncodedList.
 
Method Summary
 java.lang.Object clone()
          Copies the list; does not copy the references.
 java.lang.Object get(java.lang.Comparable index)
          Get the value at the specified index in the list.
 java.util.Iterator iterator()
          An iterator over all the DynamicValue elements of the list.
 boolean remove(java.lang.Comparable start, java.lang.Comparable stop)
          Removes all values at the given range.
 void set(java.lang.Comparable start, java.lang.Comparable stop, java.lang.Object value)
          Sets the value at the given range.
 java.lang.String toString()
          Gets a list in the form n*("item"), n*("item")...
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LengthwiseEncodedList

public LengthwiseEncodedList()
Creates a new instance of LengthwiseEncodedList.

Method Detail

clone

public java.lang.Object clone()
Copies the list; does not copy the references.

See Also:
Object.clone()

get

public java.lang.Object get(java.lang.Comparable index)
Get the value at the specified index in the list.

Specified by:
get in interface ArbitraryIndexList
Parameters:
index - the index into the list
Returns:
the value at the specified index

set

public void set(java.lang.Comparable start,
                java.lang.Comparable stop,
                java.lang.Object value)
Sets the value at the given range. Note that, like SortedMap, this means that value is set in the range from start, inclusive, to stop, exclusive.

Specified by:
set in interface ArbitraryIndexList
Parameters:
start - the first index to set
stop - the first index that is not set
value - all elements in the list in the range [start, stop) will take this value
Throws:
java.lang.IllegalArgumentException - if start is not less than stop

remove

public boolean remove(java.lang.Comparable start,
                      java.lang.Comparable stop)
Removes all values at the given range. Note that, like SortedMap, this means that value is set in the range from start, inclusive, to stop, exclusive.

Specified by:
remove in interface ArbitraryIndexList
Parameters:
start - the first index to remove
stop - the first index that is not removed
Returns:
true if any elements were removed

toString

public java.lang.String toString()
Gets a list in the form n*("item"), n*("item")...

Returns:
a String version of the list

iterator

public java.util.Iterator iterator()
An iterator over all the DynamicValue elements of the list.

Specified by:
iterator in interface ArbitraryIndexList
Returns:
the elements of the list, in order