public class int64 extends NumberType
unknown
value representation and the core comparison logic.
All Progress language features related to integer/decimal data types are implemented in the
MathOps
class (except comparison logic which is in CompareOps
. All Progress
integer/decimal features are supported including all functionality that can be accessed
via operators and built-in Progress functions.
It acts as storage for all internal intermediary results of arithmetic operations.
The implementation uses 64-bit signed integer storage.
As this is the base class for integer
it shares the common code and data.
Modifier and Type | Class and Description |
---|---|
private static class |
int64.ContextContainer
Simple container that stores and returns a context-local instance of the global work area.
|
private static class |
int64.WorkArea
Stores global data relating to the state of the current context.
|
NumberType.FormatSpec
Modifier and Type | Field and Description |
---|---|
private static java.math.BigDecimal |
LOWER_BOUND
Smallest big decimal value that can be assigned.
|
protected static int |
SECS_IN_A_DAY
Number of seconds in a day (leap minutes aren't considered).
|
protected static int |
SECS_IN_A_MIN
Number of seconds in a minute.
|
protected static int |
SECS_IN_AN_HOUR
Number of seconds in an hour.
|
private boolean |
unknown
Stores the state of whether or not this instance represents the
unknown value ,
independent of the state of this integer's value. |
private static java.math.BigDecimal |
UPPER_BOUND
Largest big decimal value that can be assigned.
|
private long |
value
Stores the value of this instance.
|
private static int64.ContextContainer |
work
Stores context-local state variables.
|
FORMAT_DEC_SEP, FORMAT_GROUP_SEP, SIGN_CR, SIGN_DB, SIGN_DR, SIGN_LEFT_MINUS, SIGN_LEFT_PLUS, SIGN_NONE, SIGN_PAREN, SIGN_PAREN_EMBED, SIGN_RIGHT_MINUS, SIGN_RIGHT_PLUS
Constructor and Description |
---|
int64()
Default constructor which creates an instance representing the
unknown value . |
int64(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.
|
int64(boolean value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
int64(java.lang.Boolean value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
int64(character value)
Constructs an instance after converting the string representation
of a number into an integer.
|
int64(date value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
int64(java.util.Date value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
int64(decimal value)
Constructs an instance after casting the parameter into the internal representation of this
class.
|
int64(double value)
Constructs an instance after casting the parameter into the internal
representation of this class.
|
int64(int64 value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
int64(integer value)
Constructs an instance after casting the parameter into the internal representation of this
class.
|
int64(logical value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
int64(long value)
Constructs an instance after casting the parameter into the internal
representation of this class.
|
int64(java.lang.Number value)
Constructs an instance after copying the parameter's data into the
internal representation of this class.
|
int64(java.lang.String value)
Constructs an instance after converting the string representation
of a number into an integer.
|
Modifier and Type | Method and Description |
---|---|
void |
assign(BaseDataType value)
Sets the state (data and unknown value) of this instance based on the state of the passed
instance.
|
void |
assign(double value)
Sets the state (data and unknown value) of this instance based on the
state of the passed data.
|
void |
assign(long value)
Sets the state (data) of this instance based on the given data.
|
void |
assign(NumberType value)
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.
|
java.lang.String |
buildDefaultFormat()
Dynamically builds the default format string for this given number type
which honors the given group and decimal separators.
|
java.lang.String |
buildExportFormat()
Returns the export format string for this given number type which
honors the given group and decimal separators.
|
protected boolean |
checkBounds(long value)
Checks if
value can be assigned to this data type. |
int |
compareTo(java.lang.Object obj)
Compares this instance with the specified instance and returns -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.
|
void |
decrement()
Decrements the value of this instance by 1.
|
double |
doubleValue()
Returns the value of this instance as a
double . |
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.
|
int64 |
getBitsWorker(double pos,
double len)
Worker method for getBits, this returns the number of bits from the
given position as an
integer . |
long |
getValue()
Returns the value of this instance as an
long . |
int |
hashCode()
Hash code implementation which is consistent with
BaseDataType.equals(java.lang.Object) . |
void |
increment()
Increments the value of this instance by 1.
|
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 . |
int |
intValue()
Returns the value of this instance as an
int . |
boolean |
isUnknown()
Determines if this instance represents the
unknown value . |
long |
longValue()
Returns the value of this instance as a
long . |
int64 |
maximum(int64 i)
Returns the larger of the current or passed-in instance.
|
static int64 |
maximum(NumberType... list)
Returns the largest instance from the list.
|
int64 |
minimum(int64 i)
Returns the smaller of the current or passed-in instance.
|
static int64 |
minimum(NumberType... list)
Returns the smallest instance from the list.
|
java.lang.String |
obtainDefaultFormat()
Returns the default format string for this given number type (which
honors the given group and decimal separators), building that format
and caching it if this is the first call in this context.
|
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
void |
setBitsWorker(double data,
double pos,
double len)
Worker method for setBits, this copies the bit representation of an
integer to a location with a given number of bits within the current integer variable.
|
void |
setUnknown()
Sets the state of this instance's
unknown value state to true . |
void |
setValue(boolean newVal)
Set the value of this instance as an
boolean . |
void |
setValue(logical newVal)
Set the value of this instance as an
logical . |
void |
setValue(long newVal)
Set the value of this instance as an
long . |
void |
setValue(NumberType newVal)
Set the value after casting the parameter into the internal representation of this class.
|
protected void |
setValue(java.lang.String value)
Set the value of this instance from the given numeric value.
|
java.math.BigDecimal |
toBigDecimal()
Returns the value of this instance as a
BigDecimal . |
java.lang.Integer |
toJavaIntegerType()
Return the current value as a Java Integer wrapper.
|
java.lang.Long |
toJavaLongType()
Return the current value as a Java Long wrapper.
|
java.lang.String |
toString()
Creates a string representation of the instance data using the default
Progress 4GL format of '->,>>>,>>9'.
|
java.lang.String |
toString(java.lang.String fmt)
Creates a string representation of the instance data using the user
specified format string (Progress 4GL compatible) or if no such
string is provided, the default format of '->,>>>,>>9'.
|
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.
|
defaultFormatString, generateSimpleFormat, getBits, getBits, getBits, getBits, getDecimalSeparator, getDecimalSeparatorIndex, getDefaultFormat, getDigitsLeft, getDigitsRight, getEmbedIndex, getExportFormat, getGroupSeparator, getNumericDecimalPoint, getNumericFormat, getNumericSeparator, getNumGroupSeparators, getUserLeft, getUserRight, getValueTextLength, isDigitChar, isFormatChar, overrideDefaultSeparators, parseDecimal, parseDecimal, parseDecimal, parseDecimal, parseDouble, parseDouble, parseFormat, setBits, setBits, setBits, setBits, setBits, setBits, setBits, setNumericFormat, setNumericFormat, setNumericFormat, setNumericFormat, setNumericFormat, setNumericFormat, setNumericFormat, subscript, toString, toString
calcFormatLength, deepCopy, elementsOfType, formatLength, generateDefault, generateUnknown, getTypeName, incompatibleTypesOnConversion, initializeDefaultExtent, isUnknownValue, maximum, minimum, notUnknownValue, sameType
changed, checkUndoable, checkUndoable, checkUndoable, getTransLevel, isGlobal, isUndoable, markUndoable, popBlock, rollback, setGlobal
protected static final int SECS_IN_A_MIN
protected static final int SECS_IN_AN_HOUR
protected static final int SECS_IN_A_DAY
private static final java.math.BigDecimal LOWER_BOUND
private static final java.math.BigDecimal UPPER_BOUND
private static int64.ContextContainer work
private long value
unknown
flag is true
.private boolean unknown
unknown value
,
independent of the state of this integer's value.public int64()
unknown value
.public int64(BaseDataType value)
assign(BaseDataType)
).value
- The value to be used for this instance.public int64(long value)
It is not possible to yield an unknown value
from this
constructor without calling the method setUnknown()
separate.
value
- The value to be used for this instance.public int64(double value)
value
- The value to be used for this instance.public int64(boolean value)
When the parameter is true
the resulting integer value
will be 1. Otherwise the value is 0.
value
- The value to be used for this instance.public int64(int64 value)
If the parameter's represents the unknown value
, this
instance will also represent the unknown value
.
value
- The value to be used for this instance.public int64(integer value)
If the parameter's represents the unknown value
, this instance will also
represent the unknown value
.
value
- The value to be used for this instance.public int64(decimal value)
If the parameter's represents the unknown value
, this instance will also
represent the unknown value
.
value
- The value to be used for this instance.public int64(logical value)
If the parameter's represents the unknown value
, this
instance will also represent the unknown value
.
When the parameter is true
the resulting integer value
will be 1. Otherwise the value is 0.
value
- The value to be used for this instance.public int64(java.lang.String value)
value
- The value to be used for this instance.public int64(character value)
If the parameter is unknown value
the resulting integer is
the unknown value
.
value
- The value to be used for this instance.public int64(date value)
If the parameter's represents the unknown value
, this
instance will also represent the unknown value
.
value
- The value to be used for this instance.public int64(java.lang.Number value)
If the parameter is null
, this instance will represent
the unknown value
.
value
- The value to be used for this instance.public int64(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 int64(java.util.Date value)
If the parameter is null
, this instance will represent
the unknown value
.
value
- The value to be used for this instance.public static int64 maximum(NumberType... list)
null
values.list
- The list of decimals and/or integers to check.unknown value
if any entries in the list are
unknown or null
if an empty list is passed.public static int64 minimum(NumberType... list)
null
values.list
- The list of decimals and/or integers to check.unknown value
if any entries in the list are
unknown or null
if an empty list is passed.public java.lang.String buildDefaultFormat()
buildDefaultFormat
in class NumberType
public java.lang.String obtainDefaultFormat()
obtainDefaultFormat
in class NumberType
public java.lang.String buildExportFormat()
buildExportFormat
in class NumberType
null
.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 long longValue() throws java.lang.NullPointerException
long
. No loss of
precision will occur in this conversion.
This method will fail if the instance represents the
unknown value
.
longValue
in class NumberType
long
.java.lang.NullPointerException
- If this instance represents the unknown value
.public int intValue() throws java.lang.NullPointerException
int
. Loss of
precision may occur in this conversion if number exceeds int limits
This method will fail if the instance represents the unknown value
.
intValue
in class NumberType
int
.java.lang.NullPointerException
- If this instance represents the unknown value
.public double doubleValue()
double
. Some loss
of precision may occur in this conversion. Use toBigDecimal()
if keeping the precision is the concern.
If this instance represents the unknown value
, the
returned double
will be set to NaN
.
doubleValue
in class NumberType
double
.public java.math.BigDecimal toBigDecimal()
BigDecimal
. No loss
of precision will occur in this conversion.
If this instance represents the unknown value
, the
return value will be null
.
toBigDecimal
in class NumberType
BigDecimal
instance, see above for details.public void increment()
If this instance represents the unknown value
, nothing is done.
increment
in class NumberType
public void decrement()
If this instance represents the unknown value
, nothing is done.
decrement
in class NumberType
public boolean isUnknown()
unknown value
.isUnknown
in class BaseDataType
true
if this instance is set to the unknown value
.public void setUnknown()
unknown value
state to true
.setUnknown
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 long getValue()
long
. No loss
of precision will occur in this conversion. This is the same as the longValue()
.
If this instance represents the unknown value
, the
returned long
is not valid!
long
.public void assign(BaseDataType value)
If the value is not of type NumberType
, the following automatic type
conversion will occur:
unknown
values (or literal) will set this object to unknown
NumberType
values will be assigned using usual conversion
handle
will use the hashCode()
method to obtain an integer.
The reverse operation is not valid and this should only be used for viewing
handle values.
date
will convert to the number of dates passed from 4GL day 0.
logical
. true
values will convert to 1 while
false
are converted to 0.
character
and longchar
. The conversion implies parsing the
string assuming the number is written in base 10.
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.public void assign(NumberType value)
value
- The instance from which to copy state.public void assign(long value)
value
- The data from which to copy state.public void assign(double value)
value
- The data from which to copy state. NaN
will
force this instance to unknown value.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 int64 maximum(int64 i)
i
- The instance to compare against.public int64 minimum(int64 i)
i
- The instance to compare against.public java.lang.String toString()
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()
toStringExport
in class BaseDataType
public java.lang.String toString(java.lang.String fmt)
toString
in class BaseDataType
fmt
- The Progress 4GL format string or null
if the default format is
to be used.public int64 getBitsWorker(double pos, double len)
integer
.getBitsWorker
in class NumberType
pos
- The 1-based index position to set, must be > 0.len
- The number of bytes to take into consideration when performing the operation.integer
.public void setBitsWorker(double data, double pos, double len)
setBitsWorker
in class NumberType
data
- The bit representation of an integer to be copied.pos
- The 1-based index position to set, must be > 0.len
- The number of bytes to take into consideration when performing the operation.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 void setValue(java.lang.String value)
value
- The value to be represented in this instance.public void setValue(long newVal) throws ErrorConditionException
long
. No loss of precision will occur in
this conversion. This also sets the unknown value
state for this instance to
false
.newVal
- The value to be represented in this instance.ErrorConditionException
- Thrown if the value
do not fit within this data-type.public void setValue(boolean newVal)
boolean
.
When the parameter is true
the resulting integer value will be 1.
Otherwise the value is 0.newVal
- The value to be represented in this instance.public void setValue(logical newVal)
logical
.
If the parameter's represents the unknown value
, this instance will also
represent the unknown value
.
When the parameter is true
the resulting integer value will be 1.
Otherwise the value is 0.
newVal
- The value to be represented in this instance.public void setValue(NumberType newVal) throws ErrorConditionException
newVal
- The value to be represented in this instance.ErrorConditionException
- Thrown if the value
do not fit within this data-type.public java.lang.Long toJavaLongType()
null
if unknown.public java.lang.Integer toJavaIntegerType()
null
if unknown.protected boolean checkBounds(long value) throws ErrorConditionException
value
can be assigned to this data type. This is important for
integer
objects where the values must fit into 32 bit storage bounds.value
- The valueErrorConditionException
- Thrown if the value
do not fit within this data-type.protected BaseDataType instantiateDefaultExtent()
instantiateDefaultExtent
in class BaseDataType