com.sas.lang
Class BooleanOperator

com.sas.lang.BooleanOperator
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, ComponentInterface, LinkPropertiesInterface, ModelInterface, ViewInterface, MultipleValueEventSourceInterface, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.util.EventListener

public class BooleanOperator

A BooleanOperator is an object which computes a boolean function of one or two boolean values. The two operands and the result are bound properties, so it is convenient to use them for property linking when you need to combine two properties such that the result is the AND or OR of the two inputs, for example, or if you want to negate the value of one property when assigning to another.
Example 1: A submit button should only be enabled if three text fields are valid.
Solution:

  1. Create two BooleanOperators, with the BooleanOperator.AND function, named and1 and and2
  2. link textField1.valid to and1.leftOperand
  3. link textField2.valid to and1.rightOperand
  4. link and1.result to and2.leftOperand
  5. link textField3.valid to and2.rightOperand
  6. link and2.result to submit.enabled

Example 2:
You have two buttons (or any other control) which are mutually exclusive: when one is enabled, the other is disabled.
Solution:
  1. Create a BooleanOperator with the NOT function, named not1
  2. Link the enabled property of button2 to the leftOperand of the not1 operator.
  3. link the result property of the not1 operator to the enabled property of button1.
  4. Create a second NOT BooleanOperator named not2 and create a second pair of links:
  5. button1.enabled sends its value to not2.leftOperand and
  6. not2.result sends its value to button2.enabled.

Specification There are really only 16 possible binary boolean operators. of two operands. Each can be assigned a unique integer from 0 to 15, where:

 bit 0 (binary 0000) is 1 if f(false, false) is true
 bit 1 (binary 0010) is 1 if f(false, true) is true
 bit 2 (binary 0100) is 1 if f(true, false) is true
 bit 3 (binary 1000) is 1 if f(true, true) is true
 
Thus, the function 0xE (binary 1110) computes the function:
   f(false, false) = false (bit 0 == 0)
   f(false, true ) = true  (bit 1 == 1)
   f(true,  false) = true  (bit 2 == 1)
   f(true,  true)  = true  (bit 3 == 1)
 
which is otherwise known as inclusive or (OR).

BooleanOperator provides prebuilt boolean function identifiers with which you can construct all possible BooleanOperators. You should use one of the following Function ID constants in the BooleanOperator(int) constructor or in the setFunction(int) method:
Boolean operations
Function IDComputesBinary Value
FALSE false 0000
NOR !(a|b) 0001
NOTA_AND_B !a&b 0010
NOTA !a 0011
NOT !a 0011
A_AND_NOTB a&!b 0100
NOTB !b 0101
XOR a^b 0110
NAND !(a&b) 0111
AND a&b 1000
XNOR !(a^b) 1001
B b 1010
NOTA_OR_B !a|b 1011
A a 1100
A_OR_NOTB a|!b 1101
OR a|b 1110
TRUE true 1111
In this table, a is the left operand and b is the right operand.

Note that the NOT function is an alias for NOTA. NOT ignores the rightOperand value and simply negates the leftOperand, so no link to the rightOperand is necessary.

See Also:
Serialized Form

Field Summary
static int A
          A boolean function id for the function which computes f(a,b) = a This is one of the possible function values for the BooleanOperator(int) constructor.
static int A_AND_NOTB
          A boolean function id for the function which computes f(a,b) = a&!
static int A_OR_NOTB
          A boolean function id for the function which computes f(a,b) = a|!
static int AND
          A boolean function id for the function which computes f(a,b) = a&b.
static int B
          A boolean function id for the function which computes f(a,b) = b.
static int FALSE
          A boolean function id for the function which computes f(a,b) = false.
static int NAND
          A boolean function id for the function which computes f(a,b) = !
static int NOR
          A boolean function id for the function which computes f(a,b) = !
static int NOT
          A boolean function id for the function which computes f(a,b) = !
static int NOTA
          A boolean function id for the function which computes f(a,b) = !
static int NOTA_AND_B
          A boolean function id for the function which computes f(a,b) = !
static int NOTA_OR_B
          A boolean function id for the function which computes f(a,b) = !
static int NOTB
          A boolean function id for the function which computes f(a,b) = !
static int OR
          A boolean function id for the function which computes f(a,b) = a|b.
static int TRUE
          A boolean function id for the function which computes f(a,b) = true.
static int XNOR
          A boolean function id for the function which computes f(a,b) = !
static int XOR
          A boolean function id for the function which computes f(a,b) = a^b.
 
Constructor Summary
BooleanOperator()
          Construct a BooleanOperator that computes the OR function by default.
BooleanOperator(int function)
          Construct a BooleanOperator which computes the boolean function identified by function.
 
Method Summary
 boolean equals(BooleanOperator other)
          Compare this operator to another BooleanOperator.
 boolean equals(java.lang.Object object)
          Compare this operator to another BooleanOperator
protected  void firePropertyChanges(java.lang.String propertyName, boolean oldValue, boolean newValue, boolean oldResult)
          Fires a property change for the named boolean property, then optionally fires a property change for the result property.
 int getFunction()
          Return the value of the function property.
 boolean getLeftOperand()
          Return the left operand of the boolean operation.
 boolean getResult()
          Compute the result based on the left and right operands.
 boolean getResult(boolean a, boolean b)
          Compute the result based on the left and right operands a and b
 boolean getRightOperand()
          Return the right operand of the boolean operation.
 int hashCode()
          Return the hase code for use in hash tables.
protected  void maybeFireResult(boolean oldResult)
          If the current getResult() differs from oldResult, fire a property change event for "result".
 void setFunction(int functionID)
          Set the boolean function this BooleanOperator uses to compute a result.
 void setLeftOperand(boolean leftOp)
          Set the left operand.
 void setRightOperand(boolean rightOp)
          Set the right operand.
 java.lang.String toString()
          Return the string representation of this operator.
 java.lang.String toString(boolean logicalName)
          Return the string representation of this operator.
 
Methods inherited from class com.sas.Component
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, beansIsDesignTime, beansSetDesignTime, clone, clone, detachModel, detachView, dumpComponent, firePropertyChange, firePropertyChange, fireVetoableChange, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getExtendedBeanInfo, getLinkInfo, getModelInterface, getRequiredInterfaces, getResources, getStringResource, getViewInterfaceSupportInfo, initialize, initializeComponent, isDesignTime, isLinked, propertyChange, queryLinks, queryLinks, refresh, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setComponentDescription, setComponentSupportInfo, setDefaultValues, setLinkInfo, setModelInterface, setRequiredInterfaces, setViewInterfaceSupportInfo, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, validateObject
 

Field Detail

FALSE

public static final int FALSE
A boolean function id for the function which computes f(a,b) = false. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

NOR

public static final int NOR
A boolean function id for the function which computes f(a,b) = !(a|b). This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

NOTA_AND_B

public static final int NOTA_AND_B
A boolean function id for the function which computes f(a,b) = !a&b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

NOTA

public static final int NOTA
A boolean function id for the function which computes f(a,b) = !a. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

A_AND_NOTB

public static final int A_AND_NOTB
A boolean function id for the function which computes f(a,b) = a&!b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

NOTB

public static final int NOTB
A boolean function id for the function which computes f(a,b) = !b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

NAND

public static final int NAND
A boolean function id for the function which computes f(a,b) = !(a&b). This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

XOR

public static final int XOR
A boolean function id for the function which computes f(a,b) = a^b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

AND

public static final int AND
A boolean function id for the function which computes f(a,b) = a&b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

XNOR

public static final int XNOR
A boolean function id for the function which computes f(a,b) = !(a^b). This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

B

public static final int B
A boolean function id for the function which computes f(a,b) = b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

NOTA_OR_B

public static final int NOTA_OR_B
A boolean function id for the function which computes f(a,b) = !a|b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

A

public static final int A
A boolean function id for the function which computes f(a,b) = a This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

A_OR_NOTB

public static final int A_OR_NOTB
A boolean function id for the function which computes f(a,b) = a|!b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

OR

public static final int OR
A boolean function id for the function which computes f(a,b) = a|b. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

TRUE

public static final int TRUE
A boolean function id for the function which computes f(a,b) = true. This is one of the possible function values for the BooleanOperator(int) constructor.

See Also:
Constant Field Values

NOT

public static final int NOT
A boolean function id for the function which computes f(a,b) = !a. This is one of the possible function values for the BooleanOperator(int) constructor. This is the negation function. It is an alias for NOTA.

See Also:
Constant Field Values
Constructor Detail

BooleanOperator

public BooleanOperator(int function)
Construct a BooleanOperator which computes the boolean function identified by function.

Parameters:
function - the identifier of the binary boolean operator. Use one of the boolean function identifiers defined here: FALSE, NOR, NOTA_AND_B, NOTA, A_AND_NOTB, NOTB, XOR, NAND, AND, XNOR, B, NOTA_OR_B, A, A_OR_NOTB, OR, or TRUE. See the above discussion on the specification of boolean operators for how this function is interpreted.

BooleanOperator

public BooleanOperator()
Construct a BooleanOperator that computes the OR function by default.

Method Detail

setLeftOperand

public void setLeftOperand(boolean leftOp)
Set the left operand.

Parameters:
leftOp - the value to use as the left operand in the boolean operation.

getLeftOperand

public boolean getLeftOperand()
Return the left operand of the boolean operation.

Returns:
the boolean left operand.

setRightOperand

public void setRightOperand(boolean rightOp)
Set the right operand.

Parameters:
rightOp - the value to use as the right operand in the boolean operation.

getRightOperand

public boolean getRightOperand()
Return the right operand of the boolean operation.

Returns:
the boolean right operand.

getResult

public boolean getResult()
Compute the result based on the left and right operands. This calls getResult(getLeftOperand(), getRightOperand())

Returns:
the boolean function of the two operands.

getResult

public boolean getResult(boolean a,
                         boolean b)
Compute the result based on the left and right operands a and b

Parameters:
a - the left operand to use in computing the result
b - the left operand to use in computing the result
Returns:
the boolean function of the two operands a and b

firePropertyChanges

protected void firePropertyChanges(java.lang.String propertyName,
                                   boolean oldValue,
                                   boolean newValue,
                                   boolean oldResult)
Fires a property change for the named boolean property, then optionally fires a property change for the result property. Note that the result does not always changes when the left or right operands change.

Parameters:
propertyName - the name of the property which has changed. This is one of "leftOperand" or "rightOperand"
oldValue - the old value of the property.
newValue - the new value of the property. If oldValue != newValue, then a property change event is fired for propertyName
oldResult - the previous result property, before this left or right property was changed. This is passed to maybeFireResult(boolean)

maybeFireResult

protected void maybeFireResult(boolean oldResult)
If the current getResult() differs from oldResult, fire a property change event for "result". Other methods which change elements of this BooleanOperator, such as the leftOperand or rightOperand or function should save the old getResult(), make the change, then call maybeFireResult which will conditionally fire a property change for the result property.

Parameters:
oldResult - a previous result, captured before some other change to this BooleanOperator.

setFunction

public void setFunction(int functionID)
Set the boolean function this BooleanOperator uses to compute a result. See BooleanOperator functions for a list of valid values for the function ID.

Parameters:
functionID - the new boolean function ID.

getFunction

public int getFunction()
Return the value of the function property.

Returns:
the value of the function property.

hashCode

public int hashCode()
Return the hase code for use in hash tables.

Overrides:
hashCode in class java.lang.Object
Returns:
the has code. For BooleanOperator, this is the function.
See Also:
getFunction()

equals

public boolean equals(BooleanOperator other)
Compare this operator to another BooleanOperator.

Returns:
true if and only if the two operators have the same function
See Also:
getFunction()

equals

public boolean equals(java.lang.Object object)
Compare this operator to another BooleanOperator

Overrides:
equals in class java.lang.Object
Returns:
true if and only if object is a BooleanOperator and equals((BooleanOperator) object) is true.
See Also:
equals(com.sas.lang.BooleanOperator)

toString

public java.lang.String toString(boolean logicalName)
Return the string representation of this operator.

Parameters:
logicalName - If true, return a string such as "a&b" which describes the Java expression this BooleanOperator computes, in terms of boolean operators a and b. If false, return a string of four true/false names, such as {true,false,false,false}, representing the values {getValue(true,true),getValue(true,false),getValue(false,true),getValue(true,true)}
Returns:
the string representation of this operator.

toString

public java.lang.String toString()
Return the string representation of this operator.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this operator. This returns toString(true);
See Also:
toString(boolean)



Copyright © 2009 SAS Institute Inc. All Rights Reserved.