org.jaitools.media.jai.rangelookup
Class RangeLookupTable<T extends Number & Comparable<? super T>,U extends Number & Comparable<? super U>>

java.lang.Object
  extended by org.jaitools.media.jai.rangelookup.RangeLookupTable<T,U>
Type Parameters:
T - type of the source range
U - type of the return value

public class RangeLookupTable<T extends Number & Comparable<? super T>,U extends Number & Comparable<? super U>>
extends Object

Holds a collection of source image value ranges and their corresponding destination image values for the RangeLookup operation.

Since:
1.0
Version:
$Id$
Author:
Michael Bedward, Simone Giannecchini, GeoSolutions

Constructor Summary
RangeLookupTable()
          Creates a new table with no default value.
RangeLookupTable(U defaultValue)
          Creates a new table with a default value.
RangeLookupTable(U defaultValue, boolean overlap)
          Creates a new table with specified default value and overlapping range behaviour.
 
Method Summary
 void add(Range<T> range, U destValue)
          Add source image value range and the corresponding destination image value
 U getDefaultValue()
          Gets the default value which is returned when a lookup value is outside all ranges in the table.
 U getDestValue(T srcValue)
          Lookup a source image value and return the corresponding destination image value
 boolean getOverlapAllowed()
          Checks whether it is allowable to add a range that overlaps with ranges already in the table.
 void setDefaultValue(U value)
          Sets the default value to return when a lookup value is outside all ranges in the table.
 void setOverlapAllowed(boolean overlap)
          Sets whether the table should allow a range to be added that overlaps with one or more ranges in the table.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RangeLookupTable

public RangeLookupTable()
Creates a new table with no default value. The table will throw an IllegalArgumentException if a lookup value cannot be matched. It will allow ranges to be added that overlap existing ranges.


RangeLookupTable

public RangeLookupTable(U defaultValue)
Creates a new table with a default value. The table will allow ranges to be added that overlap existing ranges.

If defaultValue is not null it will be returned when a lookup value cannot be matched; otherwise an unmatched value results in an IllegalArgumentException.

Parameters:
defaultValue - the default destination value or null to disable the default

RangeLookupTable

public RangeLookupTable(U defaultValue,
                        boolean overlap)
Creates a new table with specified default value and overlapping range behaviour.

If defaultValue is not null it will be returned when a lookup value cannot be matched; otherwise an unmatched value results in an IllegalArgumentException.

If overlap is true, adding a new lookup range that overlaps existing ranges will result in the new range being reduced to its non-overlapping intervals, if any; if false adding an overlapping range will result in an IllegalArgumentException.

Parameters:
defaultValue - the default destination value or null to disable the default
overlap - whether to allow overlapping ranges to be added to the table
Method Detail

setOverlapAllowed

public void setOverlapAllowed(boolean overlap)
Sets whether the table should allow a range to be added that overlaps with one or more ranges in the table. If allowed, a new range that overlaps one or more existing ranges will be truncated or split into non-overlapping intervals. For example, if the lookup [5, 10] => 1 is already present in the table and a new range [0, 20] => 2 is added, then the following lookups will result:
     [0, 5) => 2
     [5, 10] => 1
     (10, 20] => 2
 
Where a new range is completely overlapped by existing ranges it will be ignored.

If overlapping ranges are not allowed the table will throw an IllegalArgumentException when one is detected.

Note that it is possible to end up with unintended leaks in the lookup table. If the first range in the above example had been (5, 10] rather than [5, 10] then the table would have been:

     [0, 5) => 2
     (5, 10] => 1
     (10, 20] => 2
 
In this case the value 5 will not match any range.

Parameters:
overlap - overlap setting

getOverlapAllowed

public boolean getOverlapAllowed()
Checks whether it is allowable to add a range that overlaps with ranges already in the table.

Returns:
true if adding an overlapping range is allowed; false otherwise

getDefaultValue

public U getDefaultValue()
Gets the default value which is returned when a lookup value is outside all ranges in the table.

Returns:
the default value or null if none is set

setDefaultValue

public void setDefaultValue(U value)
Sets the default value to return when a lookup value is outside all ranges in the table. Setting the value to null disables the default and causes the table to throw an exception when a lookup value cannot be matched.

Parameters:
value - the default value or null to disable the default

add

public void add(Range<T> range,
                U destValue)
Add source image value range and the corresponding destination image value

Parameters:
range - the source image value range
destValue - the destination image value

getDestValue

public U getDestValue(T srcValue)
Lookup a source image value and return the corresponding destination image value

Parameters:
srcValue - source image value
Returns:
destination image value
Throws:
IllegalStateException - if the source image value is not contained in any of the ranges held by this table and the table was created without a default destination image value

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2009-2012. All Rights Reserved.