AnyValue

Cross-language implementation of a dynamic object that can hold a value of any type. It also provides methods to convert the stored value to different types.

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.

public constructor(value: any = null)

  • value: any - (optional) value to initialize this object.

Fields

value

The value stored by this object.

public value: any

Instance methods

clone

Creates a binary clone of this object.

public clone(): any

  • returns: any - a clone of this object.

equals

Compares this object value to specified specified value. When direct comparison gives negative results it tries to compare values as strings.

public equals(obj: any): boolean

  • obj: any - the value to be compared with.
  • returns: boolean - true when objects are equal and false otherwise.

equalsAsType

Compares this object value to specified specified value. When direct comparison gives negative results it converts values to type specified by type code and compare them again.
See TypeConverter.toType

public equalsAsType/(type: TypeCode, obj: any): boolean

  • type: TypeCode - the value to be compared with.
  • obj: Any - the args to be compared with.
  • returns: any - true when objects are equal and false otherwise.

getAsArray

Converts object value into an AnyArray or returns empty AnyArray if conversion is not possible.
See AnyValueArray.fromValue

public getAsArray(): AnyValueArray

  • returns: AnyValueArray - AnyArray value or empty AnyArray if conversion is not supported.

getAsBoolean

Converts object value into a boolean or returns false if conversion is not possible.

public getAsBoolean(): boolean

  • returns: boolean - string value or false if conversion is not supported.

getAsBooleanWithDefault

Converts object value into a boolean or returns default value if conversion is not possible.
See BooleanConverter.toBooleanWithDefault

public getAsBooleanWithDefault(defaultValue: boolean): boolean

  • defaultValue: boolean - the default value.
  • returns: boolean - boolean value or default if conversion is not supported.

getAsDateTime

Converts object value into a Date or returns current date if conversion is not possible.

public getAsDateTime(): Date

  • returns: Date - Date value or current date if conversion is not supported.

getAsDateTimeWithDefault

Converts object value into a Date or returns default value if conversion is not possible.
See DateTimeConverter.toDateTimeWithDefault

public getAsDateTimeWithDefault(defaultValue: Date): Date

  • defaultValue: Date - the default value.
  • returns: Date - Date value or default if conversion is not supported.

getAsDouble

Converts object value into a double or returns 0 if conversion is not possible.

public getAsDouble(): number

  • returns: number - double value or 0 if conversion is not supported.

getAsDoubleWithDefault

Converts object value into a double or returns default value if conversion is not possible.
See DoubleConverter.toDoubleWithDefault

public getAsDoubleWithDefault(defaultValue: number): number

  • defaultValue: number - the default value.
  • returns: number - double value or default if conversion is not supported.

getAsFloat

Converts object value into a float or returns 0 if conversion is not possible.

public getAsFloat(): number

  • returns: number - float value or 0 if conversion is not supported.

getAsFloatWithDefault

Converts object value into a float or returns default value if conversion is not possible.
See FloatConverter.toFloatWithDefault

public getAsFloatWithDefault(defaultValue: number): number

  • defaultValue: number - the default value.
  • returns: number - float value or default if conversion is not supported.

getAsInteger

Converts object value into an integer or returns 0 if conversion is not possible.

public getAsInteger(): number

  • returns: number - integer value or 0 if conversion is not supported.

getAsIntegerWithDefault

Converts object value into a integer or returns default value if conversion is not possible.
See IntegerConverter.toIntegerWithDefault

public getAsIntegerWithDefault(defaultValue: number): number

  • defaultValue: number - the default value.
  • returns: number - integer value or default if conversion is not supported.

getAsLong

Converts object value into a long or returns 0 if conversion is not possible.

public getAsLong(): number

  • returns: number - long value or 0 if conversion is not supported.

getAsLongWithDefault

Converts object value into a long or returns default value if conversion is not possible.
See LongConverter.toLongWithDefault

public getAsLongWithDefault(defaultValue: number): number

  • defaultValue: number - the default value.
  • returns: number - long value or default if conversion is not supported.

getAsMap

Converts object value into AnyMap or returns empty AnyMap if conversion is not possible.
See AnyValueMap.fromValue

public getAsMap(): AnyValueMap

  • returns: AnyValueMap - AnyMap value or empty AnyMap if conversion is not supported.

getAsNullableBoolean

Converts object value into a boolean or returns null if conversion is not possible.
See BooleanConverter.toNullableBoolean

public getAsNullableBoolean(): boolean

  • returns: boolean - boolean value or null if conversion is not supported.

getAsNullableDateTime

Converts object value into a Date or returns null if conversion is not possible.
See DateTimeConverter.toNullableDateTime

public getAsNullableDateTime(): Date

  • returns: Date - Date value or null if conversion is not supported.

getAsNullableDouble

Converts object value into a double or returns null if conversion is not possible.
See DoubleConverter.toNullableDouble

public getAsNullableDouble(): number

  • returns: number - double value or null if conversion is not supported.

getAsNullableFloat

Converts object value into a float or returns null if conversion is not possible.
See FloatConverter.toNullableFloat

public getAsNullableFloat(): number

  • returns: number - float value or null if conversion is not supported.

getAsNullableInteger

Converts object value into an integer or returns null if conversion is not possible.
See IntegerConverter.toNullableInteger

public getAsNullableInteger(): number

  • returns: number - integer value or null if conversion is not supported.

getAsNullableLong

Converts object value into a long or returns null if conversion is not possible.
See LongConverter.toNullableLong

public getAsNullableLong(): number

  • returns: number - long value or null if conversion is not supported.

getAsNullableString

Converts object value into a string or returns null if conversion is not possible.
See StringConverter.toNullableString

public getAsNullableString(): string

  • returns: string - string value or null if conversion is not supported.

getAsNullableType

Converts object value into a value defined by specied typecode. If conversion is not possible it returns null.
See TypeConverter.toNullableType

public getAsNullableType<T>(type: TypeCode): T

  • type: TypeCode - the TypeCode that defined the type of the result
  • returns: T - value defined by the typecode or null if conversion is not supported.

getAsObject

Gets the value stored in this object without any conversions

public getAsObject(): any

  • returns: any - the object value.

getAsString

Converts object value into a string or returns "" if conversion is not possible.

public getAsString(): string

  • returns: string - string value or "" if conversion is not supported.

getAsStringWithDefault

Converts object value into a string or returns default value if conversion is not possible.

public getAsStringWithDefault(defaultValue: string): string

  • defaultValue: string - the default value.
  • returns: string - string value or default if conversion is not supported.

getAsType

Converts object value into a value defined by specied typecode. If conversion is not possible it returns default value for the specified type.

public getAsType<T>(typeCode: TypeCode): T

  • typeCode: TypeCode - the TypeCode that defined the type of the result
  • returns: string - value defined by the typecode or type default value if conversion is not supported.

getAsTypeWithDefault

Converts object value into a value defined by specied typecode. If conversion is not possible it returns default value.

public getAsTypeWithDefault<T>(typeCode: TypeCode, defaultValue: T): T

  • typeCode: TypeCode - the TypeCode that defined the type of the result
  • defaultValue: T - the default value
  • returns: T - value defined by the typecode or type default value if conversion is not supported.

getTypeCode

Gets type code for the value stored in this object.
See TypeConverter.toTypeCode

public getTypeCode(): TypeCode

  • returns: TypeCode - type code of the object value.

hashCode

Gets an object hash code which can be used to optimize storing and searching.
See TypeConverter.toTypeCode

public hashCode(): number

  • returns: number - an object hash code.

setAsObject

Sets a new value for this object

public setAsObject(value: any): void

  • value: any - the new object value.

toString

Gets a string representation of the object.
See StringConverter.toString

public toString(): string

  • returns: string - a 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