|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.lang.BooleanOperator
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:
and1 and and2
textField1.valid to and1.leftOperand
textField2.valid to and1.rightOperand
and1.result to and2.leftOperand
textField3.valid to and2.rightOperand
and2.result to submit.enabled
not1
enabled property of button2 to the leftOperand
of the not1 operator.
result
property of the not1 operator
to the enabled property of button1.
not2 and create a second pair of links:
button1.enabled
sends its value to not2.leftOperand and
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 trueThus, 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:
| Function ID | Computes | Binary 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 |
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.
| 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. |
| Field Detail |
|---|
public static final int FALSE
BooleanOperator(int) constructor.
public static final int NOR
BooleanOperator(int) constructor.
public static final int NOTA_AND_B
BooleanOperator(int) constructor.
public static final int NOTA
BooleanOperator(int) constructor.
public static final int A_AND_NOTB
BooleanOperator(int) constructor.
public static final int NOTB
BooleanOperator(int) constructor.
public static final int NAND
BooleanOperator(int) constructor.
public static final int XOR
BooleanOperator(int) constructor.
public static final int AND
BooleanOperator(int) constructor.
public static final int XNOR
BooleanOperator(int) constructor.
public static final int B
BooleanOperator(int) constructor.
public static final int NOTA_OR_B
BooleanOperator(int) constructor.
public static final int A
BooleanOperator(int) constructor.
public static final int A_OR_NOTB
BooleanOperator(int) constructor.
public static final int OR
BooleanOperator(int) constructor.
public static final int TRUE
BooleanOperator(int) constructor.
public static final int NOT
BooleanOperator(int) constructor.
This is the negation function. It is an alias for NOTA.
| Constructor Detail |
|---|
public BooleanOperator(int function)
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.public BooleanOperator()
| Method Detail |
|---|
public void setLeftOperand(boolean leftOp)
leftOp - the value to use as the left operand in the boolean operation.public boolean getLeftOperand()
public void setRightOperand(boolean rightOp)
rightOp - the value to use as the right operand in the boolean operation.public boolean getRightOperand()
public boolean getResult()
getResult(getLeftOperand(), getRightOperand())
public boolean getResult(boolean a,
boolean b)
a - the left operand to use in computing the resultb - the left operand to use in computing the result
protected void firePropertyChanges(java.lang.String propertyName,
boolean oldValue,
boolean newValue,
boolean oldResult)
result property. Note that
the result does not always changes when the left or
right operands change.
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 propertyNameoldResult - the previous result property, before this
left or right property was changed. This is passed to maybeFireResult(boolean)protected void maybeFireResult(boolean oldResult)
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.
oldResult - a previous result, captured before some other
change to this BooleanOperator.public void setFunction(int functionID)
functionID - the new boolean function ID.public int getFunction()
public int hashCode()
hashCode in class java.lang.ObjectgetFunction()public boolean equals(BooleanOperator other)
getFunction()public boolean equals(java.lang.Object object)
equals in class java.lang.Objectequals((BooleanOperator) object) is true.equals(com.sas.lang.BooleanOperator)public java.lang.String toString(boolean logicalName)
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)}
public java.lang.String toString()
toString in class java.lang.ObjecttoString(boolean)
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||