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

java.lang.Object
  extended by org.jaitools.media.jai.rangelookup.RangeLookupTable.Builder<T,U>
Type Parameters:
T - lookup (source) value type
U - result (destination) valuetype
Enclosing class:
RangeLookupTable<T extends Number & Comparable<? super T>,U extends Number & Comparable<? super U>>

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

Builder to create an immutable lookup table.


Constructor Summary
RangeLookupTable.Builder()
          Creates a new builder.
 
Method Summary
 RangeLookupTable.Builder add(Range<T> srcRange, U resultValue)
          Adds a new lookup defined by a range of source values mapping to a result value.
 RangeLookupTable<T,U> build()
          Creates a new table that will hold the lookup items added to this builder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangeLookupTable.Builder

public RangeLookupTable.Builder()
Creates a new builder.

Method Detail

build

public RangeLookupTable<T,U> build()
Creates a new table that will hold the lookup items added to this builder.

Returns:
a new table instance

add

public RangeLookupTable.Builder add(Range<T> srcRange,
                                    U resultValue)
Adds a new lookup defined by a range of source values mapping to a result value. A new lookup range that overlaps one or more previously set ranges will be truncated or split into non-overlapping intervals. For example, if the lookup [5, 10] => 1 has previously been set, and a new lookup [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.

Note that it is possible to end up with unintended gaps in lookup coverage. If the first range in the above example had been the half-open interval (5, 10] rather than the closed interval [5, 10] then the following would have resulted:

     [0, 5) => 2
     (5, 10] => 1
     (10, 20] => 2
 
In this case the value 5 would not be matched.

Parameters:
srcRange - the source value range
resultValue - the destination value


Copyright © 2009-2013. All Rights Reserved.