edu.sdsc.mbt.util
Class RangeMap

java.lang.Object
  extended byedu.sdsc.mbt.util.RangeMap

public class RangeMap
extends java.lang.Object

The RangeMap class provides a means to map an integer value (such as an index) that falls in a fixed range (min and max) to application-supplied Objects. This can be used to efficiently associate properties (colors, radii, etc) to a numbered set of objects.

Author:
John L. Moreland

Constructor Summary
RangeMap(int min, int max, java.lang.Object defaultObject)
          Construct a RangeMap object with the specified min, max, and default value.
 
Method Summary
 void append(java.lang.Object value)
          Append a new value (increasing the range maximum by 1).
 void clearAll()
          Clear the entire RangeMap by setting everything to the default value.
 void clearRange(int start, int stop)
          Clear the specified range by setting it to the default value.
 boolean getCollapseOn()
          Get flag to enable/disable collapse feature.
 java.lang.Object getContiguousValue(int start_index, int end_index)
          Get the value object asocciated with the given start and end indexes.
 int getMax()
          Get the maximum range index.
 int getMin()
          Get the minimum range index.
 int[] getRange(int rangeIndex)
          Get the range currently associated with the given rangeIndex.
 int getRangeCount()
          Get the number of ranges currently assigned to this map.
 int getRangeEnd(int rangeIndex)
          Get the endIndex for the given rangeIndex.
 int getRangeStart(int rangeIndex)
          Get the startIndex for the given rangeIndex.
 java.lang.Object getRangeValue(int rangeIndex)
          Get the value currently associated with the given rangeIndex.
 java.lang.Object getValue(int index)
          Get the value object asocciated with the given index.
 void remove(int index)
          Remove an index (decreasing the range maximum by 1 and causing all subsequent index values to be decreased by 1).
 void reset(int min, int max, java.lang.Object defaultValue)
          Reset the entire RangeMap by setting new max, min and default values, and by clearing all existing ranges.
 void setCollapseOn(boolean state)
          Set flag to enable/disable collapse feature.
 void setDefaultValue(java.lang.Object newDefault)
          Set the default value to a new value.
 void setRange(int start, int stop, java.lang.Object value)
          Assign an object value to the specified range.
 void setRangeValue(int rangeIndex, java.lang.Object value)
          Set the value currently associated with the given rangeIndex.
 void setValue(int index, java.lang.Object value)
          Assign an object value to the specified index.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangeMap

public RangeMap(int min,
                int max,
                java.lang.Object defaultObject)
Construct a RangeMap object with the specified min, max, and default value.

Method Detail

getMin

public int getMin()
Get the minimum range index.


getMax

public int getMax()
Get the maximum range index.


setCollapseOn

public void setCollapseOn(boolean state)
Set flag to enable/disable collapse feature.


getCollapseOn

public boolean getCollapseOn()
Get flag to enable/disable collapse feature.


setRange

public void setRange(int start,
                     int stop,
                     java.lang.Object value)
Assign an object value to the specified range.


clearRange

public void clearRange(int start,
                       int stop)
Clear the specified range by setting it to the default value.


clearAll

public void clearAll()
Clear the entire RangeMap by setting everything to the default value.


reset

public void reset(int min,
                  int max,
                  java.lang.Object defaultValue)
Reset the entire RangeMap by setting new max, min and default values, and by clearing all existing ranges.


setDefaultValue

public void setDefaultValue(java.lang.Object newDefault)
Set the default value to a new value. Make sure that prior ranges with the default value are updated.


setValue

public void setValue(int index,
                     java.lang.Object value)
Assign an object value to the specified index.


getValue

public java.lang.Object getValue(int index)
Get the value object asocciated with the given index.


getContiguousValue

public java.lang.Object getContiguousValue(int start_index,
                                           int end_index)
Get the value object asocciated with the given start and end indexes. If a single range does not span the entire start and end indexes, null is returned.

This method is useful for efficiently determining if an entire index range maps contiguously (unbroken) to the same value object.

Example, in order to test that a given chain is selected, simply pass the chain's start atom index and end atom index to this method. If the chain is selected, the return value should be a boolean "True" object. If all atoms in the given chain are not all selected, then this method would return null.


getRangeCount

public int getRangeCount()
Get the number of ranges currently assigned to this map.


getRangeValue

public java.lang.Object getRangeValue(int rangeIndex)
Get the value currently associated with the given rangeIndex.


setRangeValue

public void setRangeValue(int rangeIndex,
                          java.lang.Object value)
Set the value currently associated with the given rangeIndex.


getRange

public int[] getRange(int rangeIndex)
Get the range currently associated with the given rangeIndex.


getRangeStart

public int getRangeStart(int rangeIndex)
Get the startIndex for the given rangeIndex.


getRangeEnd

public int getRangeEnd(int rangeIndex)
Get the endIndex for the given rangeIndex.


append

public void append(java.lang.Object value)
Append a new value (increasing the range maximum by 1).


remove

public void remove(int index)
Remove an index (decreasing the range maximum by 1 and causing all subsequent index values to be decreased by 1).