Implements: ICloneable
Description
The AnyValue class provides a cross-language implementation of a dynamic object that can hold a value of any type. In addition, it provides methods to convert the stored value to different types, such as string or integer.
Constructors
Creates a new instance of the object and assigns its value.
publicconstructor(value: any = null)
- value: any - (optional) value to initialize this object.
Fields
Instance methods
clone
Creates a binary clone of this object.
publicclone(): any
- returns: any - clone of this object.
equals
Compares this object’s value to a specified specified value. When a direct comparison gives a negative result it tries to compare the values as strings.
publicequals(obj: any): boolean
- obj: any - value to be compared with.
- returns: boolean - true when objects are equal and false otherwise.
equalsAsType
Compares this object’s value to a specified value.
When direct comparison gives a negative result it converts the
values to a type specified by the type code and compares them again.
See TypeConverter.toType
publicequalsAsType/(type: TypeCode, obj: any): boolean
- type: TypeCode - value to be compared with.
- obj: Any - args to be compared with.
- returns: any - true when the objects are equal and false otherwise.
getAsArray
Converts the object’s value into an AnyArray or returns an empty AnyArray if the conversion is not possible.
See AnyValueArray.fromValue
publicgetAsArray(): AnyValueArray
- returns: AnyValueArray - AnyArray value or empty AnyArray if the conversion is not supported.
getAsBoolean
Converts an object’s value into a boolean or returns false if the conversion is not possible.
publicgetAsBoolean(): boolean
- returns: boolean - string value or false if the conversion is not supported.
getAsBooleanWithDefault
Converts an object’s value into a boolean or returns a given default value if the conversion is not possible.
See BooleanConverter.toBooleanWithDefault
publicgetAsBooleanWithDefault(defaultValue: boolean): boolean
- defaultValue: boolean - default value.
- returns: boolean - boolean value or given default if the conversion is not supported.
getAsDateTime
Converts an object’s value into Date or returns the current date if the conversion is not possible.
publicgetAsDateTime(): Date
- returns: Date - Date value or current date if the conversion is not supported.
getAsDateTimeWithDefault
Converts an object’s value into Date or returns a given default value if the conversion is not possible.
See DateTimeConverter.toDateTimeWithDefault
publicgetAsDateTimeWithDefault(defaultValue: Date): Date
- defaultValue: Date - default value.
- returns: Date - Date value or given default if the conversion is not supported.
getAsDouble
Converts an object’s value into a double or returns 0 if the conversion is not possible.
publicgetAsDouble(): number
- returns: number - double value or 0 if the conversion is not supported.
getAsDoubleWithDefault
Converts an object’s value into a double or returns a default value if the conversion is not possible.
See DoubleConverter.toDoubleWithDefault
publicgetAsDoubleWithDefault(defaultValue: number): number
- defaultValue: number - default value.
- returns: number - double value or default if the conversion is not supported.
getAsFloat
Converts an object’s value into a float or returns 0 if the conversion is not possible.
publicgetAsFloat(): number
- returns: number - float value or 0 if the conversion is not supported.
getAsFloatWithDefault
Converts an object’s value into a float or returns a given default value if the conversion is not possible.
See FloatConverter.toFloatWithDefault
publicgetAsFloatWithDefault(defaultValue: number): number
- defaultValue: number - default value.
- returns: number - float value or default if the conversion is not supported.
getAsInteger
Converts an object’s value into an integer or returns 0 if the conversion is not possible.
publicgetAsInteger(): number
- returns: number - integer value or 0 if the conversion is not supported.
getAsIntegerWithDefault
Converts an object’s value into an integer or returns a given default value if conversion is not possible.
See IntegerConverter.toIntegerWithDefault
publicgetAsIntegerWithDefault(defaultValue: number): number
- defaultValue: number - default value.
- returns: number - integer value or default if the conversion is not supported.
getAsLong
Converts an object’s value into a long or returns 0 if the conversion is not possible.
publicgetAsLong(): number
- returns: number - long value or 0 if the conversion is not supported.
getAsLongWithDefault
Converts an object’s value into a long or returns a given default value if the conversion is not possible.
See LongConverter.toLongWithDefault
publicgetAsLongWithDefault(defaultValue: number): number
- defaultValue: number - default value.
- returns: number - long value or given default if the conversion is not supported.
getAsMap
Converts an object’s value into AnyMap or returns an empty AnyMap object if the conversion is not possible.
See AnyValueMap.fromValue
publicgetAsMap(): AnyValueMap
- returns: AnyValueMap - AnyMap value or empty AnyMap if the conversion is not supported.
getAsNullableBoolean
Converts an object’s value into a boolean or returns null if the conversion is not possible.
See BooleanConverter.toNullableBoolean
publicgetAsNullableBoolean(): boolean
- returns: boolean - boolean value or null if the conversion is not supported.
getAsNullableDateTime
Converts an object’s value into Date or returns null if the conversion is not possible.
See DateTimeConverter.toNullableDateTime
publicgetAsNullableDateTime(): Date
- returns: Date - Date value or null if the conversion is not supported.
getAsNullableDouble
Converts an object’s value into a double or returns null if the conversion is not possible.
See DoubleConverter.toNullableDouble
publicgetAsNullableDouble(): number
- returns: number - double value or null if the conversion is not supported.
getAsNullableFloat
Converts an object’s value into a float or returns null if the conversion is not possible.
See FloatConverter.toNullableFloat
publicgetAsNullableFloat(): number
- returns: number - float value or null if the conversion is not supported.
getAsNullableInteger
Converts an object’s value into an integer or returns null if the conversion is not possible.
See IntegerConverter.toNullableInteger
publicgetAsNullableInteger(): number
- returns: number - integer value or null if the conversion is not supported.
getAsNullableLong
Converts an object’s value into a long or returns null if the conversion is not possible.
See LongConverter.toNullableLong
publicgetAsNullableLong(): number
- returns: number - long value or null if the conversion is not supported.
getAsNullableString
Converts an object’s value into a string or returns null if the conversion is not possible.
See StringConverter.toNullableString
publicgetAsNullableString(): string
- returns: string - string value or null if the conversion is not supported.
getAsNullableType
Converts an object’s value into a value defined by a specified typecode.
If conversion is not possible it returns null.
See TypeConverter.toNullableType
publicgetAsNullableType<T>(type: TypeCode): T
- type: TypeCode - TypeCode that defined the type of the result
- returns: T - value defined by the typecode or null if the conversion is not supported.
getAsObject
Gets the value stored in this object without any conversion.
publicgetAsObject(): any
- returns: any - object value.
getAsString
Converts an object’s value into a string or returns "" if the conversion is not possible.
publicgetAsString(): string
- returns: string - string value or "" if the conversion is not supported.
getAsStringWithDefault
Converts an object’s value into a string or returns a given default value if the conversion is not possible.
publicgetAsStringWithDefault(defaultValue: string): string
- defaultValue: string - default value.
- returns: string - string value or given default if the conversion is not supported.
getAsType
Converts an object’s value into a value defined by a specifieded typecode. If conversion is not possible, it returns the default value for the specified type.
publicgetAsType<T>(typeCode: TypeCode): T
- typeCode: TypeCode - TypeCode that defines the type of the result
- returns: string - value defined by the typecode or type default value if the conversion is not supported.
getAsTypeWithDefault
Converts an object’s value into a value defined by a specified typecode. If conversion is not possible, it returns the given default value.
publicgetAsTypeWithDefault<T>(typeCode: TypeCode, defaultValue: T): T
- typeCode: TypeCode - TypeCode that defines the type of the result
- defaultValue: T - default value
- returns: T - value defined by the typecode or given default value if the conversion is not supported.
getTypeCode
Gets the type’s code for the value stored in this object.
See TypeConverter.toTypeCode
publicgetTypeCode(): TypeCode
- returns: TypeCode - type’s code of the object’s value.
hashCode
Gets an object hash code which can be used to optimize storing and searching.
See TypeConverter.toTypeCode
publichashCode(): number
- returns: number - object hash code.
setAsObject
Sets a new value for this object.
publicsetAsObject(value: any): void
- value: any - new object value.
toString
Gets a string representation of the object.
See StringConverter.toString
publictoString(): string
- returns: string - string representation of the object.
Examples
let value1 = new AnyValue("123.456");
value1.getAsInteger(); // Result: 123
value1.getAsString(); // Result: "123.456"
value1.getAsFloat(); // Result: 123.456
See also
-
StringConverter
-
TypeConverter
-
BooleanConverter
-
IntegerConverter
-
LongConverter
-
DoubleConverter
-
FloatConverter
-
DateTimeConverter
-
ICloneable