pip_services3_commons.data.AnyValueArray module
pip_services3_commons.data.AnyValueArray
AnyValueArray implementation
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
-
class
pip_services3_commons.data.AnyValueArray.
AnyValueArray
(values: Sequence[Any] = None) Bases:
list
,pip_services3_commons.data.ICloneable.ICloneable
Cross-language implementation of dynamic object array what can hold values of any type. The stored values can be converted to different types using variety of accessor methods.
Example:
value1 = AnyValueArray([1, "123.456", "2018-01-01"]) value1.get_as_boolean(0) # Result: true value1.get_as_integer(1) # Result: 123 value1.get_as_float(1) # Result: 123.456 value1.get_as_datetime(2) # Result: datetime.datetime(2018,0,1)
-
appends
(elements: List[Any]) Appends new elements to this array.
- Parameters
elements – a list of elements to be added.
-
clear
() Clears this array by removing all its elements.
-
clone
() → Any Creates a binary clone of this object.
- Returns
a clone of this object.
-
contains
(value: Any) → bool Checks if this array contains a args. The check uses direct comparison between elements and the specified args.
- Parameters
value – a args to be checked
- Returns
true if this array contains the args or false otherwise.
-
contains_as_type
(value_type: pip_services3_commons.convert.TypeCode.TypeCode, value: Any) → bool Checks if this array contains a args. The check before comparison converts elements and the args to type specified by type code.
- Parameters
value_type – a type code that defines a type to convert values before comparison
value – a args to be checked
- Returns
true if this array contains the args or false otherwise.
-
static
from_string
(values: str, separator: str, remove_duplicates: bool = False) → pip_services3_commons.data.AnyValueArray.AnyValueArray Splits specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.
- Parameters
values – a string args to be split and assigned to AnyValueArray
separator – a separator to split the string
remove_duplicates – (optional) true to remove duplicated elements
- Returns
a newly created AnyValueArray.
-
static
from_value
(value: Any) → pip_services3_commons.data.AnyValueArray.AnyValueArray Converts specified args into
AnyValueArray
.- Parameters
value – args to be converted
- Returns
a newly created
AnyValueArray
.
-
static
from_values
(*values: Any) → pip_services3_commons.data.AnyValueArray.AnyValueArray Creates a new
AnyValueArray
from a list of values- Parameters
values – a list of values to initialize the created
AnyValueArray
- Returns
a newly created
AnyValueArray
.
-
get
(index: int) → Any Gets an array element specified by its index.
- Parameters
index – an index of the element to get.
- Returns
the value of the array element.
-
get_as_array
(index: int) → pip_services3_commons.data.AnyValueArray.AnyValueArray Converts array element into an
AnyValueArray
or returns emptyAnyValueArray
if conversion is not possible.- Parameters
index – an index of element to get.
- Returns
AnyValueArray
args of the element or emptyAnyValueArray
if conversion is not supported.
-
get_as_array_with_default
(index: int, default_value: pip_services3_commons.data.AnyValueArray.AnyValueArray) → pip_services3_commons.data.AnyValueArray.AnyValueArray Converts array element into an AnyValueArray or returns default value if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default value
- Returns
AnyValueArray value of the element or default value if conversion is not supported.
-
get_as_boolean
(index: int) → bool Converts array element into a boolean or returns false if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
boolean args ot the element or false if conversion is not supported.
-
get_as_boolean_with_default
(index: int, default_value: bool) → bool Converts array element into a boolean or returns default args if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default args
- Returns
boolean args ot the element or default args if conversion is not supported.
-
get_as_datetime
(index: int) → datetime.datetime Converts array element into a Date or returns the current date if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
Date args ot the element or the current date if conversion is not supported.
-
get_as_datetime_with_default
(index: int, default_value: datetime.datetime) → datetime.datetime Converts array element into a Date or returns default args if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default args
- Returns
Date args ot the element or default args if conversion is not supported.
-
get_as_double
(index: int) → float Converts array element into a double or returns 0 if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
double value ot the element or 0 if conversion is not supported.
-
get_as_double_with_default
(index: int, default_value: float) → float Converts array element into a double or returns default value if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default value
- Returns
double value ot the element or default value if conversion is not supported.
-
get_as_float
(index: int) → float Converts array element into a float or returns 0 if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
float args ot the element or 0 if conversion is not supported.
-
get_as_float_with_default
(index: int, default_value: float) → float Converts array element into a float or returns default args if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default args
- Returns
float args ot the element or default args if conversion is not supported.
-
get_as_integer
(index) → int Converts array element into an integer or returns 0 if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
integer args ot the element or 0 if conversion is not supported.
-
get_as_integer_with_default
(index: int, default_value: int) → int Converts array element into an integer or returns default args if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default args
- Returns
integer args ot the element or default args if conversion is not supported.
-
get_as_map
(index: int) → pip_services3_commons.data.AnyValueMap.AnyValueMap Converts array element into an
AnyValueMap
or returns emptyAnyValueMap
if conversion is not possible.- Parameters
index – an index of element to get.
- Returns
AnyValueMap
args of the element or emptyAnyValueMap
if conversion is not supported.
-
get_as_map_with_default
(index: int, default_value: pip_services3_commons.data.AnyValueMap.AnyValueMap) → pip_services3_commons.data.AnyValueMap.AnyValueMap Converts array element into an AnyValueMap or returns default value if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default value
- Returns
AnyValueMap value of the element or default value if conversion is not supported.
-
get_as_nullable_array
(index: int) → Optional[pip_services3_commons.data.AnyValueArray.AnyValueArray, None] Converts array element into an AnyValueArray or returns null if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
AnyValueArray value of the element or null if conversion is not supported.
-
get_as_nullable_boolean
(index: int) → Optional[bool, None] Converts array element into a boolean or returns None if conversion is not possible
- Parameters
index – an index of element to get.
- Returns
boolean args of the element or None if conversion is not supported.
-
get_as_nullable_datetime
(index: int) → Optional[datetime.datetime, None] Converts array element into a Date or returns None if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
Date args of the element or None if conversion is not supported.
-
get_as_nullable_double
(index: int) → float Converts array element into a double or returns null if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
double value of the element or null if conversion is not supported.
-
get_as_nullable_float
(index: int) → Optional[float, None] Converts array element into a float or returns None if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
float args of the element or None if conversion is not supported.
-
get_as_nullable_integer
(index: int) → Optional[int, None] Converts array element into an integer or returns None if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
integer args of the element or None if conversion is not supported.
-
get_as_nullable_map
(index: int) → Optional[pip_services3_commons.data.AnyValueMap.AnyValueMap, None] Converts array element into an AnyValueMap or returns null if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
AnyValueMap value of the element or null if conversion is not supported.
-
get_as_nullable_string
(index: int) → Optional[str, None] Converts array element into a string or returns None if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
string args of the element or None if conversion is not supported.
-
get_as_nullable_type
(value_type: pip_services3_commons.convert.TypeCode.TypeCode, index: int) → Any Converts array element into a args defined by specied typecode. If conversion is not possible it returns None.
- Parameters
value_type – the TypeCode that defined the type of the result
index – an index of element to get.
- Returns
element args defined by the typecode or None if conversion is not supported.
-
get_as_object
(index: int = None) → Any Gets the args stored in array element without any conversions. When element index is not defined it returns the entire array args.
- Parameters
index – (optional) an index of the element to get
- Returns
the element args or args of the array when index is not defined.
-
get_as_string
(index: int) → str Converts array element into a string or returns “” if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
string args ot the element or “” if conversion is not supported.
-
get_as_string_with_default
(index: int, default_value: str) → str Converts array element into a string or returns default args if conversion is not possible.
- Parameters
index – an index of element to get.
default_value – the default args
- Returns
string args ot the element or default args if conversion is not supported.
-
get_as_type
(value_type: pip_services3_commons.convert.TypeCode.TypeCode, index: int) → Any Converts array element into a args defined by specied typecode. If conversion is not possible it returns default args for the specified type.
- Parameters
value_type – the TypeCode that defined the type of the result
index – an index of element to get.
- Returns
element args defined by the typecode or default if conversion is not supported.
-
get_as_type_with_default
(value_type: pip_services3_commons.convert.TypeCode.TypeCode, index: int, default_value: Any) → Any Converts array element into a args defined by specied typecode. If conversion is not possible it returns default args.
- Parameters
value_type – the TypeCode that defined the type of the result
index – an index of element to get.
default_value – the default args
- Returns
element args defined by the typecode or default args if conversion is not supported.
-
get_as_value
(index: int) → AnyValue Converts array element into an AnyValue or returns an empty AnyValue if conversion is not possible.
- Parameters
index – an index of element to get.
- Returns
AnyValue args of the element or empty AnyValue if conversion is not supported.
-
put
(index: int, value: Any) Puts a new value into array element specified by its index.
- Parameters
index – a new value for array element.
value – an index of the element to put.
- Returns
the value of the array element.
-
remove
(index: int) Removes an array element specified by its index
- Parameters
index – an index of the element to remove.
-
set_as_array
(values: List[Any]) Sets a new values to array element
- Parameters
values – values to set
-
set_as_object
(index: int = None, value: Any = None) Sets a new args to array element specified by its index. When the index is not defined, it resets the entire array args. This method has double purpose because method overrides are not supported in JavaScript.
- Parameters
index – (optional) an index of the element to set
value – a new element or array args.
-