public abstract class BaseDataType extends LazyUndoable implements java.lang.Comparable, java.io.Externalizable
Each subclass should implement Comparable
but is only
required to implement compareTo()
as the equals()
method is implemented in this class.
Note: As result, classes from this hierarchy cannot be used as keys for normal
java associative collections because of collisions caused by objects (Ex: an unknown
integer
and an unknown logical
are considered equals in P4GL so only one
unknown can be the key in such collection). If such collection is required, use a special one
like IdentityHashMap
.
All processing relies upon the implementation of the following methods in each concrete subclass:
boolean isUnknown() void setUnknown(boolean) int compareTo(Object) - this comes from the Comparable interface BaseDataType instantiateUnknown() BaseDataType duplicate() void assign(Undoable) - this comes from the Undoable interface void assign(BaseDataType) String toString() String toStringMessage() String toStringExport() String defaultFormatString()
Constructor and Description |
---|
BaseDataType()
Default constructor (only used for de-serialization).
|
Modifier and Type | Method and Description |
---|---|
abstract void |
assign(BaseDataType value)
Sets the state (data and unknown value) of this instance based on the state of the passed
instance.
|
static int |
calcFormatLength(java.lang.String fmt,
java.lang.Class cls)
Calculate the length of a formatted value (the text form of the value)
using this format string.
|
Undoable |
deepCopy()
This is a form of a copy constructor that makes a deep copy of the
current instance and returns this copy as a new instance of the same
class.
|
abstract java.lang.String |
defaultFormatString()
Return the default display format string for this type.
|
abstract BaseDataType |
duplicate()
Does the same as standard
clone() method but returns an
instance of BaseDataType and doesn't throw the
CloneNotSupportedException . |
static boolean |
elementsOfType(java.lang.Class<? extends BaseDataType> cls,
BaseDataType... args)
Check list of BaseType of arguments and return
true if all BaseTypes are specific
type. |
boolean |
equals(java.lang.Object obj)
Determines if this instance and the given instance are equivalent.
|
int |
formatLength(java.lang.String fmt)
Calculate the length of a formatted value (the text form of the value)
using this format string.
|
static BaseDataType |
generateDefault(java.lang.Class cls)
Creates a new instance of the given type that represents the
default initialized value for that type.
|
static BaseDataType |
generateUnknown(java.lang.Class cls)
Creates a new instance of the given type that represents the
unknown value . |
java.lang.String |
getTypeName()
Returns the legacy type name of the sub-class as the type was known in
the 4GL.
|
abstract int |
hashCode()
The default implementation of this method provided by
Object is overridden here with an abstract method to force
subclasses to provide a concrete implementation which is consistent with
this class' implementation of equals(java.lang.Object) . |
protected void |
incompatibleTypesOnConversion()
Display error message in case of incompatible types for a POLY conversion.
|
protected static void |
initializeDefaultExtent(BaseDataType[] var)
Initialize the given array with the default value, based on the following table
(the rules are from variable_definition.rules):
|
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.
|
abstract BaseDataType |
instantiateUnknown()
Creates a new instance of the same type that represents the
unknown value . |
abstract boolean |
isUnknown()
Reports if this instance represents the
unknown value . |
logical |
isUnknownValue()
Reports if this instance represents the
unknown value . |
BaseDataType |
maximum(BaseDataType b)
Returns the largest instance.
|
BaseDataType |
minimum(BaseDataType b)
Returns the smallest instance.
|
logical |
notUnknownValue()
Reports if this instance represents some known value.
|
protected static boolean |
sameType(java.lang.Object source,
java.lang.Object target)
Check if the types of the specified objects match.
|
abstract void |
setUnknown()
Sets the state of this instance's
unknown value flag or
state to true . |
abstract java.lang.String |
toString(java.lang.String fmt)
Creates a string representation of the instance data using the given
format string.
|
abstract java.lang.String |
toStringExport()
Creates a string representation of the instance data using the 'export'
format.
|
abstract java.lang.String |
toStringMessage()
Creates a string representation of the instance data in a form that is
compatible with the
MESSAGE language statement. |
changed, checkUndoable, checkUndoable, checkUndoable, getTransLevel, isGlobal, isUndoable, markUndoable, popBlock, rollback, setGlobal
public BaseDataType()
public static BaseDataType generateUnknown(java.lang.Class cls)
unknown value
.unknown value
.public static BaseDataType generateDefault(java.lang.Class cls)
public static int calcFormatLength(java.lang.String fmt, java.lang.Class cls)
fmt
- The format string.public static boolean elementsOfType(java.lang.Class<? extends BaseDataType> cls, BaseDataType... args)
true
if all BaseTypes are specific
type.cls
- Specific BaseDataType class witch will be checked to the arguments.args
- list of BaseType instances.true
if all BaseTypes are character.protected static boolean sameType(java.lang.Object source, java.lang.Object target)
In case of extent vars, the size of each var must be the same, and both must be extent.
source
- The reference variable.target
- The candidate variable, which must match.true
if the type of these two variables matches.protected static void initializeDefaultExtent(BaseDataType[] var)
integer new integer(0) int64 new int64(0) decimal new decimal(0) character new character("") logical new logical(false) longchar new longchar("") date new date() datetime new datetime() datetime-tz new datetimetz() raw new raw() memptr new memptr() recid new recid()
var
- The extent variable which needs to be initialized.public int formatLength(java.lang.String fmt)
fmt
- The format string.public boolean equals(java.lang.Object obj)
BaseDataType
is compared with this instance; objects of other types cause this test
to return false
.
Note: Unknown values form different classes from this hierarchy are
considered equals in P4GL, even if they have different types (Ex: an unknown integer
and an unknown logical
.
Note: Classes from this hierarchy cannot be used as keys for normal
java associative collections because of collisions caused by objects (Ex: only one
unknown can be the key in such collection). If such collection is required, use a special
one like IdentityHashMap
.
equals
in class java.lang.Object
obj
- 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.public abstract int hashCode()
Object
is overridden here with an abstract method to force
subclasses to provide a concrete implementation which is consistent with
this class' implementation of equals(java.lang.Object)
.hashCode
in class java.lang.Object
public BaseDataType maximum(BaseDataType b)
b
- The instance to compare against.public BaseDataType minimum(BaseDataType b)
b
- The instance to compare against.public Undoable deepCopy()
public java.lang.String getTypeName()
public logical isUnknownValue()
unknown value
.true
if this instance is set to the
unknown value
.public logical notUnknownValue()
true
if this instance is not set to the
unknown value
.public BaseDataType instantiateDefault()
public abstract void assign(BaseDataType value)
If the value is not of the same type, some form of automatic type conversion may occur, or an error will be raised.
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.
value
- The instance from which to copy state.public abstract boolean isUnknown()
unknown value
.true
if this instance is set to the
unknown value
.public abstract void setUnknown()
unknown value
flag or
state to true
.
Warning: the data stored in this instance may be invalid after calling this method.
public abstract BaseDataType duplicate()
clone()
method but returns an
instance of BaseDataType
and doesn't throw the
CloneNotSupportedException
.public abstract BaseDataType instantiateUnknown()
unknown value
.unknown value
.public abstract java.lang.String toString(java.lang.String fmt)
unknown value
, a '?' will be returned.fmt
- The format string to use.public abstract java.lang.String toStringMessage()
MESSAGE
language statement. If the
instance represents the unknown value
, a '?' will be
returned.public abstract java.lang.String toStringExport()
unknown value
, a
'?' will be returned.public abstract java.lang.String defaultFormatString()
protected BaseDataType instantiateDefaultExtent()
protected void incompatibleTypesOnConversion()