public class logical extends BaseDataType
AND
, OR
and NOT
operators are implemented in this class (they are
unique to logicals) and all other logical operators are implemented in
the CompareOps
class.
The only reason this class exists is to provide an object that represents
3 possible states: true
, false
and the
unknown value
. This is the only difference between the
Progress 4GL logical data type and the Java primitive boolean
.
While a java.lang.Boolean
could be used and set to
null
to indicate the unknown value
, this
approach has the significant drawback of requiring unwrapping everywhere
and in addition, null
checks are required wherever the
data is unwrapped. This would require a very nasty bit of refactoring for
most expressions, which is made unnecessary by this class which represents
the tri-state of a logical using only internal means. Since all operators
have been implemented as method calls and these methods are aware of the
unknown value
, the resulting expressions are clean and
as close to the original level of expressiveness as possible.
Format string related processing is handled in this class, see method
toString(String)
.
The following is the mapping of Progress language features to the corresponding feature in this class:
not operatornot(boolean)
and_not(com.goldencode.p2j.util.logical)
and operatorand(boolean, boolean)
and_and(boolean, boolean)
or operatoror(boolean, boolean)
and_or(boolean, boolean)
= or EQ operatorCompareOps.isEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
<> or NE operatorCompareOps.isNotEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
> or GT operatorCompareOps.isGreaterThan(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
>= or GE operatorCompareOps.isGreaterThanOrEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
< or LT operatorCompareOps.isLessThan(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
<= or LE operatorCompareOps.isLessThanOrEqual(com.goldencode.p2j.util.BaseDataType, com.goldencode.p2j.util.BaseDataType)
maximum functionCompareOps.maximum(BaseDataType[])
minimum functionCompareOps.minimum(BaseDataType[])
OR Operator Truth Table Left Right Result --------- --------- --------- true true true false true true unknown true true true false true false false false unknown false unknown true unknown true false unknown unknown unknown unknown unknown
AND Operator Truth Table Left Right Result --------- --------- --------- true true true false true false unknown true unknown true false false false false false unknown false false true unknown unknown false unknown false unknown unknown unknown
NOT Operator Truth Table Operand Result --------- --------- true false false true unknown unknown
There are convenience versions of each operator that directly return
boolean
values such that unwrapping is not needed. These
are named the same as the operator methods above except there is no
'Operator' appended. For example, the not operator is not(boolean)
.
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
defaultFormat
The default format string.
|
private boolean |
unknown
Stores the state of whether or not this instance represents the
unknown value , independent of the state of this logical's
value as true or false . |
private boolean |
value
Stores the state of this logical as
true or
false , independent of the state of whether or not this
instance represents the unknown value . |
Constructor and Description |
---|
logical()
Default constructor, creates an instance that represents the unknown
value.
|
logical(BaseDataType value)
This is a special c'tor which should be used only when converting the
value returned by a function or method with polymorphic return type into the
expected type (i.e.
|
logical(boolean value)
Constructs an instance that has the
boolean value passed
in and which does not represent the unknown value . |
logical(java.lang.Boolean value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
logical(character value)
Converts the given string into a logical value.
|
logical(character value,
java.lang.String fmt)
Converts the given string into a logical value.
|
logical(logical value)
Constructs an instance that has the
boolean value and
unknown value that exactly matches that of the passed-in
instance. |
logical(java.lang.String value)
Converts the given string into a logical value.
|
logical(java.lang.String value,
java.lang.String fmt)
Converts the given string into a logical value.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
_and(boolean op1,
boolean op2)
Implements the
AND logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_and(boolean op1,
logical op2)
Implements the
AND logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_and(boolean op1,
LogicalOp op2)
Implements the
AND logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_and(logical op1,
boolean op2)
Implements the
AND logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_and(logical op1,
logical op2)
Implements the
AND logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_and(logical op1,
LogicalOp op2)
Implements the
AND logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_not(logical op)
Implements the
NOT logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_or(boolean op1,
boolean op2)
Implements the
OR logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_or(boolean op1,
logical op2)
Implements the
OR logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_or(boolean op1,
LogicalOp op2)
Implements the
OR logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_or(logical op1,
boolean op2)
Implements the
OR logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_or(logical op1,
logical op2)
Implements the
OR logical operator with the convenience
of converting the result to a primitive boolean . |
static boolean |
_or(logical op1,
LogicalOp op2)
Implements the
OR logical operator with the convenience
of converting the result to a primitive boolean . |
static logical |
and(boolean op1,
boolean op2)
Implements the
AND logical operator (just a convenience
method for the Java logical AND). |
static logical |
and(boolean op1,
logical op2)
Implements the
AND logical operator with proper processing
of the unknown value . |
static logical |
and(boolean op1,
LogicalOp op2)
Implements the
AND logical operator with proper processing
of the unknown value . |
static logical |
and(logical op1,
boolean op2)
Implements the
AND logical operator with proper processing
of the unknown value . |
static logical |
and(logical op1,
logical op2)
Implements the
AND logical operator with proper processing
of the unknown value . |
static logical |
and(logical op1,
LogicalOp op2)
Implements the
AND logical operator with proper processing
of the unknown value . |
void |
assign(BaseDataType value)
Sets the state (data and unknown value) of this instance based on the
state of the passed instance.
|
void |
assign(BaseDataType value,
boolean force)
Sets the state (data and unknown value) of this instance based on the
state of the passed instance.
|
void |
assign(boolean value)
Sets the state (data) of this instance based on the given value.
|
void |
assign(logical value)
Sets the state (data and unknown value) of this instance based on the
state of the passed instance.
|
void |
assign(logical value,
boolean force)
Sets the state (data and unknown value) of this instance based on the
state of the passed instance.
|
void |
assign(Undoable value)
Sets the state (data and unknown value) of this instance based on the
state of the passed instance.
|
boolean |
booleanValue()
Accesses the state of this instance's
boolean value. |
int |
compareTo(java.lang.Object obj)
Compares this instance with the specified instance and returns a -1
if this instance is less than the specified, 0 if the two instances
are equal and 1 if this instance is greater than the specified
instance.
|
private logical |
convertString(java.lang.String val)
Helper to convert a text value into a logical value with ERROR
processing SUPPRESSED.
|
java.lang.String |
defaultFormatString()
Return the default display format string for this type.
|
BaseDataType |
duplicate()
Does the same as standard
clone() method but returns an
instance of BaseDataType and doesn't throw the
CloneNotSupportedException . |
boolean |
equals(java.lang.Object o)
An equality test which handles the most common cases with the least
amount of overhead.
|
int |
formatLength(java.lang.String fmt)
Calculate the length of a formatted value (the text form of the value)
using this format string.
|
static java.lang.Boolean |
fromString(java.lang.String val,
java.lang.String fmt)
Check if the given value matches the received format.
|
boolean |
getValue()
Accesses the state of this instance's
boolean value
independently of the state of whether this instance represents the
unknown value . |
int |
hashCode()
Hash code implementation which is consistent with
BaseDataType.equals(java.lang.Object) . |
BaseDataType |
instantiateDefault()
Creates a new instance of the same type that represents the
default initialized value.
|
protected BaseDataType |
instantiateDefaultExtent()
Get the default initialization for an extent variable of this type.
|
BaseDataType |
instantiateUnknown()
Creates a new instance of the same type that represents the
unknown value . |
boolean |
isUnknown()
Determines if this instance represents the
unknown value . |
static logical |
maximum(logical... list)
Returns the largest instance (
false is smaller than
true ) from the list. |
logical |
maximum(logical l)
Returns the larger (
false is smaller than
true ) of the current or passed-in instance. |
static int |
maximumStringSize(java.lang.String fmt)
Determines the largest possible string length that can match either of
the specified values in a valid format string.
|
static logical |
minimum(logical... list)
Returns the smallest instance (
false is smaller than
true ) from the list. |
logical |
minimum(logical l)
Returns the smaller (
false is smaller than
true ) of the current or passed-in instance. |
static logical |
not(boolean op)
Implements the
NOT logical operator using the Java logical
NOT. |
static logical |
not(logical op)
Implements the
NOT logical operator with proper processing
of the unknown value . |
static logical |
or(boolean op1,
boolean op2)
Implements the
OR logical operator using the Java logical
OR. |
static logical |
or(boolean op1,
logical op2)
Implements the
OR logical operator with proper processing
of the unknown value . |
static logical |
or(boolean op1,
LogicalOp op2)
Implements the
OR logical operator with proper processing
of the unknown value . |
static logical |
or(logical op1,
boolean op2)
Implements the
OR logical operator with proper processing
of the unknown value . |
static logical |
or(logical op1,
logical op2)
Implements the
OR logical operator with proper processing
of the unknown value . |
static logical |
or(logical op1,
LogicalOp op2)
Implements the
OR logical operator with proper processing
of the unknown value . |
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
void |
setUnknown()
Sets the state of this instance's
unknown value flag to
true . |
void |
setValue(boolean value)
Sets the state of this instance's
boolean value
independently of the state of whether this instance represents the
unknown value . |
static java.lang.String[] |
splitFormat(java.lang.String fmt)
Split a valid logical format string in a safe way that handles all
possible edge cases.
|
java.lang.Boolean |
toJavaType()
Return the current value as a Java wrapper.
|
java.lang.String |
toString()
Creates a string representation of the instance data using the default
Progress 4GL format of 'yes/no'.
|
java.lang.String |
toString(java.lang.String fmt)
Creates a string representation of the instance data using the user-
specified Progress 4GL format string.
|
java.lang.String |
toStringExport()
Creates a string representation of the instance data using the 'export'
format.
|
java.lang.String |
toStringMessage()
Creates a string representation of the instance data in a form that is
compatible with the
MESSAGE language statement. |
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
calcFormatLength, deepCopy, elementsOfType, generateDefault, generateUnknown, getTypeName, incompatibleTypesOnConversion, initializeDefaultExtent, isUnknownValue, maximum, minimum, notUnknownValue, sameType
changed, checkUndoable, checkUndoable, checkUndoable, getTransLevel, isGlobal, isUndoable, markUndoable, popBlock, rollback, setGlobal
private static final java.lang.String defaultFormat
private boolean value
true
or
false
, independent of the state of whether or not this
instance represents the unknown value
.private boolean unknown
unknown value
, independent of the state of this logical's
value as true
or false
.public logical()
public logical(BaseDataType value)
assign(BaseDataType,boolean)
).value
- The value to be used for this instance.public logical(boolean value)
boolean
value passed
in and which does not represent the unknown value
.value
- The logical value of the resulting instance.public logical(logical value)
boolean
value and
unknown value
that exactly matches that of the passed-in
instance.value
- The logical and unknown value of the resulting instance.public logical(java.lang.String value)
unknown value
and the strings 'yes' and 'true' (and
any abbreviations thereof) are considered true
and
any other input is considered false
.value
- The text representation of the logical value.public logical(character value)
unknown value
and the strings 'yes' and 'true' (and
any abbreviations thereof) are considered true
and
any other input is considered false
.value
- The text representation of the logical value.public logical(character value, java.lang.String fmt)
unknown value
and the strings 'yes' and 'true' (and
any abbreviations thereof) are considered true
and
any other input is considered false
.
Parses the string using default formats 'yes/no' and 'true/false' and the passed in format string. Any any abbreviations of the above formats are also considered as a match. TODO: when a LOGICAL argument is passed as OUTPUT parameter to a procedure the implicit conversion will fails without reason. The following message is displayed: [** Input value: should be yes/no. (87)] When the argument is passes to a INPUT-OUTPUT parameter, everything is fine.
value
- The text representation of the logical value.fmt
- The format string to use.public logical(java.lang.String value, java.lang.String fmt) throws ErrorConditionException
unknown value
. Parses the string using default
formats 'yes/no' and 'true/false' and the passed in format string. Any
any abbreviations of the above formats are also considered as a match.value
- The text representation of the logical value.fmt
- The format string to use.ErrorConditionException
- If no match is found.public logical(java.lang.Boolean value)
If the parameter is null
, this instance will represent
the unknown value
.
value
- The value to be used for this instance.public static java.lang.Boolean fromString(java.lang.String val, java.lang.String fmt)
The default formats of "yes/no" and "true/false" are always considered and will match in preference to an explicitly provided format string. This means that any conflict with the explicitly provided format string will match one of the default formats first (in preference).
Matching is done on a case-insensitive basis.
Interestingly, any matching subset of valid match text will match. This means that an
exact match or an unambiguous abbreviated match to a format string of the form 'XXX/YYY'
will make x, X, xx, XX, xxx, XXX all resolve to true
and y, Y, yy, YY, yyy,
YYY all resolve to false
. This optional abbreviation support works for
matches to both the default formats AND to explicitly provided custom formats.
The default formats have an additional "trash matching" behavior. When specifying yes, no,
true or false, the string can contain any trash so long as the trash is following a space
character. This means a yes . bogus text.
matches a yes
in a
default format. This same ridiculous trick does not work for explicit custom formats.
All of the above behavior is indeed how the 4GL does it. No, it doesn't make any sense.
At conversion time, all enclosing quote characters should already have been removed from both input parameters. It is expected that this is always already the case with runtime strings.
val
- The value to be checked.fmt
- The format; if null
, the defaultFormat
will be used.null
if the value does not match the format. Otherwise, the value's
true
or false
state.public static logical maximum(logical... list)
false
is smaller than
true
) from the list. This list may not include
null
values.list
- The list of logicals to check.unknown value
if any
entries in the list are unknown or null
if
an empty list is passed.public static logical minimum(logical... list)
false
is smaller than
true
) from the list. This list may not include
null
values.list
- The list of decimals to check.unknown value
if any
entries in the list are unknown or null
if
an empty list is passed.public static boolean _not(logical op)
NOT
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.op
- The operand.public static logical not(boolean op)
NOT
logical operator using the Java logical
NOT.op
- The operand.public static logical not(logical op)
NOT
logical operator with proper processing
of the unknown value
. In particular, if the operand
is unknown, then unknown value
is returned.
If the operand is not unknown
, the boolean value will
be negated and returned using the Java logical NOT.
op
- The operand.public static boolean _and(boolean op1, boolean op2)
AND
logical operator with the convenience
of converting the result to a primitive boolean
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _and(logical op1, boolean op2)
AND
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _and(boolean op1, logical op2)
AND
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _and(logical op1, logical op2)
AND
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _and(boolean op1, LogicalOp op2)
AND
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static boolean _and(logical op1, LogicalOp op2)
AND
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static logical and(boolean op1, boolean op2)
AND
logical operator (just a convenience
method for the Java logical AND).op1
- The left operand.op2
- The right operand.public static logical and(boolean op1, logical op2)
AND
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is true
and
false
is returned if the other operand is
false
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical AND.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static logical and(logical op1, boolean op2)
AND
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is true
and
false
is returned if the other operand is
false
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical AND.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static logical and(logical op1, logical op2)
AND
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is true
and
false
is returned if the other operand is
false
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical AND.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static logical and(boolean op1, LogicalOp op2)
AND
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is true
and
false
is returned if the other operand is
false
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical AND.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static logical and(logical op1, LogicalOp op2)
AND
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is true
and
false
is returned if the other operand is
false
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical AND.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static boolean _or(boolean op1, boolean op2)
OR
logical operator with the convenience
of converting the result to a primitive boolean
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _or(logical op1, boolean op2)
OR
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _or(boolean op1, logical op2)
OR
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _or(logical op1, logical op2)
OR
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static boolean _or(boolean op1, LogicalOp op2)
OR
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static boolean _or(logical op1, LogicalOp op2)
OR
logical operator with the convenience
of converting the result to a primitive boolean
. If the
result is the unknown value
, this will be converted to a
false
.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static logical or(boolean op1, boolean op2)
OR
logical operator using the Java logical
OR.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static logical or(boolean op1, logical op2)
OR
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is false
and
true
is returned if the other operand is
true
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical OR.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static logical or(logical op1, boolean op2)
OR
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is false
and
true
is returned if the other operand is
true
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical OR.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static logical or(logical op1, logical op2)
OR
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is false
and
true
is returned if the other operand is
true
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical OR.
Warning: this form requires that both operand expressions are evaluated in the context of the caller. It does not maintain the standard semantic of a logical operator where the right operand is not evaluated unless the left operand requires it.
op1
- The left operand.op2
- The right operand.public static logical or(boolean op1, LogicalOp op2)
OR
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is false
and
true
is returned if the other operand is
true
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical OR.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static logical or(logical op1, LogicalOp op2)
OR
logical operator with proper processing
of the unknown value
.
If one operand is unknown
, then unknown
is returned if the other operand is false
and
true
is returned if the other operand is
true
. If both operands are unknown
, then
unknown
is returned.
If no operand is unknown
, the boolean values of each
logical are tested using the Java logical OR.
This form of the method allows the original semantic of the operator to be maintained. In particular, the expression defining the right operand will not be evaluated unless the left operand does not fail the logical test.
op1
- The left operand.op2
- The right operand.public static java.lang.String[] splitFormat(java.lang.String fmt) throws ErrorConditionException
null
format string is invalid
true
value
false
true
representation and the right side is the false
fmt
- Format to split.true
value
and the second element is the false
value.ErrorConditionException
public static int maximumStringSize(java.lang.String fmt)
fmt
- A valid format string for the logical
type.public int formatLength(java.lang.String fmt)
formatLength
in class BaseDataType
fmt
- The format string.public boolean equals(java.lang.Object o)
This implementation is consistent with hashCode()
.
equals
in class BaseDataType
o
- The instance to compare against.true
if the objects compare equivalently; false
if they do not,
or if the parameter is not a BaseDataType
instance.BaseDataType.equals(java.lang.Object)
public int hashCode()
BaseDataType.equals(java.lang.Object)
.hashCode
in class BaseDataType
public BaseDataType instantiateUnknown()
unknown value
.instantiateUnknown
in class BaseDataType
unknown value
.public BaseDataType instantiateDefault()
instantiateDefault
in class BaseDataType
public BaseDataType duplicate()
clone()
method but returns an
instance of BaseDataType
and doesn't throw the
CloneNotSupportedException
.duplicate
in class BaseDataType
public boolean booleanValue()
boolean
value. If
this instance represents the unknown value
, then this
method will return false
even if the internal state is
true
!boolean
value or
false
if this instance represents the
unknown value
.public boolean isUnknown()
unknown value
.isUnknown
in class BaseDataType
true
if this instance is set to the
unknown value
.public void setUnknown()
unknown value
flag to
true
.
Warning: a separate call is needed to ensure that the data of this instance is set to the correct value.
setUnknown
in class BaseDataType
public boolean getValue()
boolean
value
independently of the state of whether this instance represents the
unknown value
. If this instance represents the
unknown value
, the returned boolean
is
not valid!boolean
value.public void setValue(boolean value)
boolean
value
independently of the state of whether this instance represents the
unknown value
. This also sets the
unknown value
state for this instance to
false
.value
- The state to set this instance's boolean
value.public void assign(BaseDataType value, boolean force)
If the value is not of type logical
, the following automatic type
conversions will occur:
This variant is meant to handle the cases of built-in functions and methods in the 4GL which have polymorphic return types (e.g. DYNAMIC-FUNCTION()). This should NOT be used for non-polymorphic assignments.
assign
in class BaseDataType
value
- The instance from which to copy state.force
- Flag to indicate if a pending error should be ignored (see
ErrorManager.isPendingError()
and the assignment
forced regardless. Note that normal assignment silently
exits with no change if there is a pending error. If this
flag is true
, that check is bypassed and the
assignment will always be done.public void assign(logical value, boolean force)
value
- The instance from which to copy state.force
- Flag to indicate if a pending error should be ignored (see
ErrorManager.isPendingError()
and the assignment
forced regardless. Note that normal assignment silently
exits with no change if there is a pending error. If this
flag is true
, that check is bypassed and the
assignment will always be done.public void assign(boolean value)
This is a "no operation" in the case where silent error mode is active
AND an error has occurred in the current processing since the opening
call to ErrorManager.silentErrorEnable()
. This protection is
needed to ensure that the state of this instance does not change in
this case. This will not affect undo because that only occurs when
silent error mode is disabled.
value
- The data from which to copy state.public void assign(logical value)
This is a "no operation" in the case where silent error mode is active
AND an error has occurred in the current processing since the opening
call to ErrorManager.silentErrorEnable()
. This protection is
needed to ensure that the state of this instance does not change in
this case. This will not affect undo because that only occurs when
silent error mode is disabled.
value
- The instance from which to copy state.public void assign(BaseDataType value)
assign
in class BaseDataType
value
- The instance from which to copy state.public void assign(Undoable value)
value
- The instance from which to copy state.public int compareTo(java.lang.Object obj)
Comparable
interface.
The algorithm will fail to give meaningful results in the case where one tries to sort against other objects that do not represent compatible values.
obj
- The instance to compare against.obj
.public logical maximum(logical l)
false
is smaller than
true
) of the current or passed-in instance.l
- The instance to compare against.public logical minimum(logical l)
false
is smaller than
true
) of the current or passed-in instance.l
- The instance to compare against.public java.lang.Boolean toJavaType()
null
if unknown.public java.lang.String toString()
unknown value
, a '?' will be returned.toString
in class java.lang.Object
public java.lang.String toStringMessage()
MESSAGE
language statement. If the
instance represents the unknown value
, a '?' will be
returned.toStringMessage
in class BaseDataType
public java.lang.String toStringExport()
unknown value
, a '?' will be returned.toStringExport
in class BaseDataType
public java.lang.String toString(java.lang.String fmt) throws ErrorConditionException
null
, then a default format string of 'yes/no' will be
used. Please note that due to the implementation, it is faster
to use a null
format string than to explicitly encode
'yes/no'. If the instance represents the unknown value
,
a '?' will be returned.
The format string must be in the form of 'xxx/yyy' where xxx is the
text for a true
and yyy is the text for a
false
value. For example, one might want a 'true/false'
to be used instead of the default. The user cannot override the '?'
returned for the unknown value
.
toString
in class BaseDataType
fmt
- The Progress 4GL format string for a logical data type.ErrorConditionException
public java.lang.String defaultFormatString()
defaultFormatString
in class BaseDataType
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
in
- The input source from which fields will be restored.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If payload can't be instantiated.public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
out
- The output destination to which fields will be saved.java.io.IOException
- In case of I/O errors.protected BaseDataType instantiateDefaultExtent()
instantiateDefaultExtent
in class BaseDataType
private logical convertString(java.lang.String val)
val
- The value to attempt to convert. If it does not match the
string "yes" or "no", then an error would normally occur.
This error will be suppressed, but the resulting failure
will be detected.null
on any failure.