com.miginfocom.util.gfx.geometry.filters
Class RefRangeOperFilter

java.lang.Object
  extended by com.miginfocom.util.gfx.geometry.filters.RefRangeOperFilter
All Implemented Interfaces:
AtRefRangeNumber, java.io.Serializable
Direct Known Subclasses:
RefOperFilter

public class RefRangeOperFilter
extends java.lang.Object
implements AtRefRangeNumber

A filter that can be either wrap a value (Decorator pattern, e.g. BufferedReader) or be set up to filter any value. It can actually be both at the same time.
To use as a decorator just wrap this class around a AtRefRangeNumber or another RefRangeOperFilter. Subclasses to this class can implements AtRefNumber and/or AtNumber.
When asked for the value (this class implements AtRefRangeNumber) the wrapped value is retrived and the opertaion is executed on that value. The result of that operation is returned (possibly to the next layer). This is an easy way to filter a specific value or a linked value to for instance enforce min/max bounds or the like. It does not work very good as a generic filter though, since the innermost value needs to be specified at creation time.

There is also the possibility to use this class as a more generic filter for any value. Call filter(float, float, float) and set the first float to the value to filter. This value will temporarily replace the innermost number and ripple out again to get the final, filtered value. The innermost value may be set to null, but if it isn't that value is simply disregarded.
Example of a generic min/max filter that keeps a some value between the bounds of te reference range. null could be exchanged for some specific value that should always be constrained to be between these min/max bounds. The RefRangeOperFilter is then used as the number instead of the originaly value, as per the definition of the decorator pattern.


 RefRangeOperFilter tmpMin = new RefRangeOperFilter(null, RefOperFilter.MIN, new AtStart(0));
 RefRangeOperFilter minMaxFilter = new RefRangeOperFilter(tmpMin, RefOperFilter.MAX, new AtEnd(0));
 

See Also:
Serialized Form

Field Summary
static int ADD
          An opertaion that adds wrap with value.
protected  float auxValue
           
protected  AtRefRangeNumber constr
           
static int DIV
          An opertaion that divides wrap with value.
static int MAX
          An opertaion that return the bigger of wrap and value.
static int MIN
          An opertaion that return the lesser of wrap and value.
static int MUL
          An opertaion that multiplys wrap with value.
protected  int oper
           
static int PERCENT
          An opertaion that returns a value in relevance to wrap and value.
static int SET
          Forces the value to the reference value.
static int SUB
          An opertaion that subtracts wrap with value.
protected  AtRefRangeNumber wrap
           
 
Constructor Summary
RefRangeOperFilter(AtRefRangeNumber wrap, int oper, AtRefRangeNumber constr)
          Constructor.
RefRangeOperFilter(AtRefRangeNumber wrap, int oper, AtRefRangeNumber constr, float auxValue)
          Constructor.
 
Method Summary
protected  float constrainByType(float value, float constr)
          Takes the values and enforces the type of them returning the result
 RefRangeOperFilter derive(AtRefRangeNumber newWrap)
          Creates a clone with a new wrapped number.
 boolean equals(java.lang.Object o)
           
 float filter(float value, float start, float end)
          Filters value through this filter.
 float getAuxValue()
          Returns the auxValue sent into the constructor.
 int getIntValue(float start, float end)
          Returns the value as an int.
 int getOperation()
          Returns the operation sent into the constructor.
 AtRefRangeNumber getRefRangeConstraint()
          Returns the constraint value.
 AtRefRangeNumber getRefRangeWrapped()
          Returns the constraint value.
 float getValue(float start, float end)
          Returns the value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ADD

public static final int ADD
An opertaion that adds wrap with value.

See Also:
Constant Field Values

SUB

public static final int SUB
An opertaion that subtracts wrap with value.

See Also:
Constant Field Values

MUL

public static final int MUL
An opertaion that multiplys wrap with value.

See Also:
Constant Field Values

DIV

public static final int DIV
An opertaion that divides wrap with value.

See Also:
Constant Field Values

MIN

public static final int MIN
An opertaion that return the lesser of wrap and value.

See Also:
Constant Field Values

MAX

public static final int MAX
An opertaion that return the bigger of wrap and value.

See Also:
Constant Field Values

PERCENT

public static final int PERCENT
An opertaion that returns a value in relevance to wrap and value. The auxValue in the constructor is the relative distance between the two. 0.0f is at wrap and 1.0f is at value. auxValue can be any value. Not that auxValue must be specified.

See Also:
Constant Field Values

SET

public static final int SET
Forces the value to the reference value.

See Also:
Constant Field Values

oper

protected final transient int oper

auxValue

protected final transient float auxValue

constr

protected final transient AtRefRangeNumber constr

wrap

protected final transient AtRefRangeNumber wrap
Constructor Detail

RefRangeOperFilter

public RefRangeOperFilter(AtRefRangeNumber wrap,
                          int oper,
                          AtRefRangeNumber constr)
Constructor.

Parameters:
constr - The cut-value to use in the operation. Normally the min or max value.
oper - The operation. E.g. MIN or MAX
wrap - Wrapped value to be constraint. If null this constraint will only be funcional as a builder. Call derive(com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber) to get a constraint that can be used.
See Also:
ADD, SUB, MUL, DIV, MIN, MAX

RefRangeOperFilter

public RefRangeOperFilter(AtRefRangeNumber wrap,
                          int oper,
                          AtRefRangeNumber constr,
                          float auxValue)
Constructor.

Parameters:
constr - The cut-value to use in the operation. Normally the min or max value.
oper - The operation. E.g. MIN or MAX
wrap - Wrapped value to be constraint. If null this constraint will only be funcional as a builder. Call derive(com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber) to get a constraint that can be used.
auxValue - If the operation needs an extra value, such as PERCENT, that value goes here.
See Also:
ADD, SUB, MUL, DIV, MIN, MAX, PERCENT
Method Detail

getRefRangeConstraint

public final AtRefRangeNumber getRefRangeConstraint()
Returns the constraint value.

Returns:
The constraint value. Not null.

getRefRangeWrapped

public final AtRefRangeNumber getRefRangeWrapped()
Returns the constraint value.

Returns:
The constraint value. Can be null if this is a "buider" constraint.

getOperation

public final int getOperation()
Returns the operation sent into the constructor.

Returns:
The operation sent into the constructor.

getAuxValue

public final float getAuxValue()
Returns the auxValue sent into the constructor.

Returns:
The auxValue sent into the constructor.

getValue

public float getValue(float start,
                      float end)
Description copied from interface: AtRefRangeNumber
Returns the value.

Specified by:
getValue in interface AtRefRangeNumber
Parameters:
start - The start value.
end - The end value.
Returns:
The returned value that depends on one or both of the arguments.

getIntValue

public final int getIntValue(float start,
                             float end)
Description copied from interface: AtRefRangeNumber
Returns the value as an int.

Specified by:
getIntValue in interface AtRefRangeNumber
Parameters:
start - The start value.
end - The end value.
Returns:
The returned value that depends on one or both of the arguments.

filter

public float filter(float value,
                    float start,
                    float end)
Filters value through this filter. In effect value will ripple from the innermost filter and out, being constrained/filtered/ operated on on the way out to the outmost filter. Similar to getValue(float, float) but with the core value replaced with value.

Parameters:
value - The value to filter
start - Start reference. Same as for getValue(float, float)
end - End reference. Same as for getValue(float, float)
Returns:
The filtered value.

constrainByType

protected float constrainByType(float value,
                                float constr)
Takes the values and enforces the type of them returning the result

Parameters:
value - The value to enforce
constr - The value of the constraint
Returns:
The result of the operation

derive

public RefRangeOperFilter derive(AtRefRangeNumber newWrap)
Creates a clone with a new wrapped number. Shallow clone except for setting the new wrapper.

Parameters:
newWrap - The wrapped number for the clone.
Returns:
A clone with a new wrapped number.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.