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()
Modifier and Type | Class and Description |
---|---|
static class |
BaseDataType.Type
Enum class describing all 4GL wrapper types.
|
(package private) static class |
BaseDataType.WrapperHandler
An invocation handler dedicated for BDT proxy.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
LOG
Logger
|
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.
|
void |
assign(jobject<?> value)
Convert the specified Java value to a legacy BDT instance, and assign it to this instance.
|
void |
assign(java.lang.Object value)
Assign the given value to the current 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.
|
static BaseDataType |
createProxy(BaseDataType value)
Create base data type proxy of the same data type as the provided value.
|
static BaseDataType |
createProxy(BaseDataType value,
java.lang.Class<? extends BaseDataType> clazz)
Create base data type proxy of a specified data type.
|
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.
|
BaseDataType |
fallback()
Retrieve the real value in a proxy data type.
|
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.Class<? extends BaseDataType> |
fromTypeName(java.lang.String typeName)
Resolve the BDT sub-class from the specified 4GL type name.
|
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 . |
(package private) java.util.function.Supplier<AbstractParameter> |
getAssigner()
Get the assigner supplier which will be used to register this instance as a parameter.
|
int |
getSize()
Obtain the length (in bytes) of this BDT will use when serialized.
|
abstract BaseDataType.Type |
getType()
Get the type
|
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()
Throws error message in case of incompatible types for a POLY conversion.
|
void |
initialize(BaseDataType value)
Convenient method to initialize a base data type.
|
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 . |
protected void |
invalidInitializer(java.lang.String text)
Display error message in case of an invalid initializer for the given type.
|
static boolean |
isAllKnown(BaseDataType... values)
The method returns
true if all the supplied values are "known", i.e. |
static boolean |
isAllKnown(BaseDataType value)
The method returns
true if all the supplied values are "known", i.e. |
(package private) boolean |
isAssignDirect()
Check if this instance can be assigned directly, without boundary checks.
|
protected boolean |
isIncompatibleTypesOnConversion(BaseDataType value)
Returns true if dynamic data type conversion should not be attempted,
it can also throws in case of incompatible types for a POLY conversion.
|
static boolean |
isProxy(BaseDataType value)
Check if a BDT is a proxy or a real 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. |
BaseDataType |
val()
Retrieve the real value.
|
static BaseDataTypeVariable |
variable(BaseDataType var)
Mark this BDT instance as a 4GL-declared variable - it will be wrapped in a
BaseDataTypeVariable instance. |
changed, checkUndoable, checkUndoable, checkUndoable, getTransLevel, isGlobal, isUndoable, markUndoable, popBlock, rollback, setGlobal
public BaseDataType()
public static BaseDataTypeVariable variable(BaseDataType var)
BaseDataTypeVariable
instance.var
- The reference to be marked as a variable.public static java.lang.Class<? extends BaseDataType> fromTypeName(java.lang.String typeName)
This type name must be un-abbreviated and standardized (if multiple aliases exists).
typeName
- The type name.null
if the type is unknown.public static BaseDataType generateUnknown(java.lang.Class<?> cls)
unknown value
.cls
- instance classunknown value
.public static BaseDataType generateDefault(java.lang.Class<?> cls)
cls
- instance classpublic static int calcFormatLength(java.lang.String fmt, java.lang.Class<?> cls)
fmt
- The format string.cls
- instance classpublic 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 static boolean isAllKnown(BaseDataType... values)
true
if all the supplied values are "known", i.e. none of the
values is null
or unknown (isUnknown()
).values
- The values to check.public static boolean isAllKnown(BaseDataType value)
true
if all the supplied values are "known", i.e. none of the
values is null
or unknown (isUnknown()
).value
- The values to check.public static BaseDataType createProxy(BaseDataType value)
value
- The value which should be wrapped with the proxy.public static BaseDataType createProxy(BaseDataType value, java.lang.Class<? extends BaseDataType> clazz)
value
- The value which should be wrapped with the proxy.clazz
- The data type of the proxy.public static boolean isProxy(BaseDataType value)
value
- The BDT to be checkedtrue
if the provided value is a proxypublic void initialize(BaseDataType value)
value
- The value to assign to this type.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 abstract BaseDataType.Type getType()
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 void assign(jobject<?> value)
value
- The instance holding a Java type, compatible with BDT native types.public void assign(java.lang.Object value)
value
- The current value. This is considered POLY, as it may be passed by DYNAMIC-INVOKE
or other POLY functions for which their returned data type is unknown at conversion
time.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()
public int getSize()
public BaseDataType val()
public BaseDataType fallback()
boolean isAssignDirect()
This API should be overridden by specific BDT sub-classes, and is currently used in CALL's OUTPUT/INPUT-OUTPUT parameter case, where data needs to be copied directly.
false
.java.util.function.Supplier<AbstractParameter> getAssigner()
protected BaseDataType instantiateDefaultExtent()
protected void incompatibleTypesOnConversion()
ErrorConditionException
- Always.protected boolean isIncompatibleTypesOnConversion(BaseDataType value)
ErrorConditionException
- If dynamic conversion of input value is not supported.protected void invalidInitializer(java.lang.String text)
text
- The string initializer for display in the error.ErrorConditionException
- Always.