Package org.pipservices3.commons.data
Class AnyValueArray
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<Object>
,Collection<Object>
,List<Object>
,RandomAccess
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 ###
AnyValueArray value1 = new AnyValueArray(new Object[]{1, "123.456", "2018-01-01"});
value1.getAsBoolean(0); // Result: true
value1.getAsInteger(1); // Result: 123
value1.getAsFloat(1); // Result: 123.456
value1.getAsDateTime(2); // Result: new Date(2018,0,1)
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionAnyValueArray
(Iterable<?> values) Creates a new instance of the array and assigns its value.AnyValueArray
(Object[] values) Creates a new instance of the array and assigns its value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Appends new elements to this array.void
Appends new elements to this array.clone()
Creates a binary clone of this object.boolean
Checks if this array contains a value.<T> boolean
containsAsType
(Class<T> type, Object value) Checks if this array contains a value.static AnyValueArray
fromString
(String values, String separator) Splits specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.static AnyValueArray
fromString
(String values, String separator, boolean removeDuplicates) Splits specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.static AnyValueArray
Converts specified value into AnyValueArray.static AnyValueArray
fromValues
(Object... values) Creates a new AnyValueArray from a list of valuesgetAsArray
(int index) Converts array element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.getAsArrayWithDefault
(int index, AnyValueArray defaultValue) Converts array element into an AnyValueArray or returns default value if conversion is not possible.getAsBoolean
(int index) Converts array element into a boolean or returns false if conversion is not possible.boolean
getAsBooleanWithDefault
(int index, boolean defaultValue) Converts array element into a boolean or returns default value if conversion is not possible.getAsDateTime
(int index) Converts array element into a Date or returns the current date if conversion is not possible.getAsDateTimeWithDefault
(int index, ZonedDateTime defaultValue) Converts array element into a Date or returns default value if conversion is not possible.double
getAsDouble
(int index) Converts array element into a double or returns 0 if conversion is not possible.double
getAsDoubleWithDefault
(int index, double defaultValue) Converts array element into a double or returns default value if conversion is not possible.getAsDuration
(int index) getAsDurationWithDefault
(int index, Duration defaultValue) <T extends Enum<T>>
T<T extends Enum<T>>
TgetAsEnumWithDefault
(Class<T> type, int index, T defaultValue) float
getAsFloat
(int index) Converts array element into a float or returns 0 if conversion is not possible.float
getAsFloatWithDefault
(int index, float defaultValue) Converts array element into a float or returns default value if conversion is not possible.int
getAsInteger
(int index) Converts array element into an integer or returns 0 if conversion is not possible.int
getAsIntegerWithDefault
(int index, int defaultValue) Converts array element into an integer or returns default value if conversion is not possible.long
getAsLong
(int index) Converts array element into a long or returns 0 if conversion is not possible.long
getAsLongWithDefault
(int index, long defaultValue) Converts array element into a long or returns default value if conversion is not possible.getAsMap
(int index) Converts array element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.getAsMapWithDefault
(int index, AnyValueMap defaultValue) Converts array element into an AnyValueMap or returns default value if conversion is not possible.getAsNullableArray
(int index) Converts array element into an AnyValueArray or returns null if conversion is not possible.getAsNullableBoolean
(int index) Converts array element into a boolean or returns null if conversion is not possible.getAsNullableDateTime
(int index) Converts array element into a Date or returns null if conversion is not possible.getAsNullableDouble
(int index) Converts array element into a double or returns null if conversion is not possible.getAsNullableDuration
(int index) <T extends Enum<T>>
TgetAsNullableEnum
(Class<T> type, int index) getAsNullableFloat
(int index) Converts array element into a float or returns null if conversion is not possible.getAsNullableInteger
(int index) Converts array element into an integer or returns null if conversion is not possible.getAsNullableLong
(int index) Converts array element into a long or returns null if conversion is not possible.getAsNullableMap
(int index) Converts array element into an AnyValueMap or returns null if conversion is not possible.getAsNullableString
(int index) Converts array element into a string or returns null if conversion is not possible.<T> T
getAsNullableType
(Class<T> type, int index) Converts array element into a value defined by specied typecode.Gets the value stored in this array element without any conversionsgetAsObject
(int index) Gets an array element specified by its index.getAsString
(int index) Converts array element into a string or returns "" if conversion is not possible.getAsStringWithDefault
(int index, String defaultValue) Converts array element into a string or returns default value if conversion is not possible.<T> T
Converts array element into a value defined by specied typecode.<T> T
getAsTypeWithDefault
(Class<T> type, int index, T defaultValue) Converts array element into a value defined by specied typecode.getAsValue
(int index) Converts array element into an AnyValue or returns an empty AnyValue if conversion is not possible.void
Puts a new value into array element specified by its index.void
setAsObject
(int index, Object value) Sets a new value into array element specified by its index.toString()
Gets a string representation of the object.Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
containsAll
-
Constructor Details
-
AnyValueArray
public AnyValueArray() -
AnyValueArray
Creates a new instance of the array and assigns its value.- Parameters:
values
- (optional) values to initialize this array.
-
AnyValueArray
Creates a new instance of the array and assigns its value.- Parameters:
values
- (optional) values to initialize this array.
-
-
Method Details
-
getAsObject
Gets the value stored in this array element without any conversions- Returns:
- the value of the array element.
-
put
Puts a new value into array element specified by its index.- Parameters:
index
- an index of the element to put.value
- a new value for array element.
-
append
Appends new elements to this array.- Parameters:
elements
- a list of elements to be added.
-
append
Appends new elements to this array.- Parameters:
elements
- a list of elements to be added.
-
getAsObject
Gets an array element specified by its index.- Parameters:
index
- an index of the element to get.- Returns:
- the value of the array element.
-
setAsObject
Sets a new value into array element specified by its index.- Parameters:
index
- an index of the element to put.value
- a new value for array element.
-
getAsNullableString
Converts array element into a string or returns null if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- string value of the element or null if conversion is not supported.
- See Also:
-
getAsString
Converts array element into a string or returns "" if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- string value ot the element or "" if conversion is not supported.
- See Also:
-
getAsStringWithDefault
Converts array element into a string or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- string value ot the element or default value if conversion is not supported.
- See Also:
-
getAsNullableBoolean
Converts array element into a boolean or returns null if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- boolean value of the element or null if conversion is not supported.
- See Also:
-
getAsBoolean
Converts array element into a boolean or returns false if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- boolean value ot the element or false if conversion is not supported.
- See Also:
-
getAsBooleanWithDefault
public boolean getAsBooleanWithDefault(int index, boolean defaultValue) Converts array element into a boolean or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- boolean value ot the element or default value if conversion is not supported.
- See Also:
-
getAsNullableInteger
Converts array element into an integer or returns null if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- integer value of the element or null if conversion is not supported.
- See Also:
-
getAsInteger
public int getAsInteger(int index) Converts array element into an integer or returns 0 if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- integer value ot the element or 0 if conversion is not supported.
- See Also:
-
getAsIntegerWithDefault
public int getAsIntegerWithDefault(int index, int defaultValue) Converts array element into an integer or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- integer value ot the element or default value if conversion is not supported.
- See Also:
-
getAsNullableLong
Converts array element into a long or returns null if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- long value of the element or null if conversion is not supported.
- See Also:
-
getAsLong
public long getAsLong(int index) Converts array element into a long or returns 0 if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- long value ot the element or 0 if conversion is not supported.
- See Also:
-
getAsLongWithDefault
public long getAsLongWithDefault(int index, long defaultValue) Converts array element into a long or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- long value ot the element or default value if conversion is not supported.
- See Also:
-
getAsNullableFloat
Converts array element into a float or returns null if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- float value of the element or null if conversion is not supported.
- See Also:
-
getAsFloat
public float getAsFloat(int index) Converts array element into a float or returns 0 if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- float value ot the element or 0 if conversion is not supported.
- See Also:
-
getAsFloatWithDefault
public float getAsFloatWithDefault(int index, float defaultValue) Converts array element into a float or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- float value ot the element or default value if conversion is not supported.
- See Also:
-
getAsNullableDouble
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.
- See Also:
-
getAsDouble
public double getAsDouble(int index) 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.
- See Also:
-
getAsDoubleWithDefault
public double getAsDoubleWithDefault(int index, double defaultValue) Converts array element into a double or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- double value ot the element or default value if conversion is not supported.
- See Also:
-
getAsNullableDateTime
Converts array element into a Date or returns null if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- ZonedDateTime value of the element or null if conversion is not supported.
- See Also:
-
getAsDateTime
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:
- ZonedDateTime value ot the element or the current date if conversion is not supported.
- See Also:
-
getAsDateTimeWithDefault
Converts array element into a Date or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- ZonedDateTime value ot the element or default value if conversion is not supported.
- See Also:
-
getAsNullableDuration
-
getAsDuration
-
getAsDurationWithDefault
-
getAsNullableEnum
-
getAsEnum
-
getAsEnumWithDefault
-
getAsNullableType
Converts array element into a value defined by specied typecode. If conversion is not possible it returns null.- Parameters:
type
- the Class type that defined the type of the resultindex
- an index of element to get.- Returns:
- element value defined by the typecode or null if conversion is not supported.
- See Also:
-
getAsType
Converts array element into a value defined by specied typecode. If conversion is not possible it returns default value for the specified type.- Parameters:
type
- the Class type that defined the type of the resultindex
- an index of element to get.- Returns:
- element value defined by the typecode or default if conversion is not supported.
- See Also:
-
getAsTypeWithDefault
Converts array element into a value defined by specied typecode. If conversion is not possible it returns default value.- Parameters:
type
- the Class type that defined the type of the resultindex
- an index of element to get.defaultValue
- the default value- Returns:
- element value defined by the typecode or default value if conversion is not supported.
- See Also:
-
getAsValue
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 value of the element or empty AnyValue if conversion is not supported.
- See Also:
-
getAsNullableArray
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.
- See Also:
-
getAsArray
Converts array element into an AnyValueArray or returns empty AnyValueArray if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- AnyValueArray value of the element or empty AnyValueArray if conversion is not supported.
- See Also:
-
getAsArrayWithDefault
Converts array element into an AnyValueArray or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- AnyValueArray value of the element or default value if conversion is not supported.
- See Also:
-
getAsNullableMap
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.
- See Also:
-
getAsMap
Converts array element into an AnyValueMap or returns empty AnyValueMap if conversion is not possible.- Parameters:
index
- an index of element to get.- Returns:
- AnyValueMap value of the element or empty AnyValueMap if conversion is not supported.
- See Also:
-
getAsMapWithDefault
Converts array element into an AnyValueMap or returns default value if conversion is not possible.- Parameters:
index
- an index of element to get.defaultValue
- the default value- Returns:
- AnyValueMap value of the element or default value if conversion is not supported.
- See Also:
-
contains
Checks if this array contains a value. The check uses direct comparison between elements and the specified value. -
containsAsType
Checks if this array contains a value. The check before comparison converts elements and the value to type specified by type code.- Parameters:
type
- a Class type that defines a type to convert values before comparisonvalue
- a value to be checked- Returns:
- true if this array contains the value or false otherwise.
- See Also:
-
clone
Creates a binary clone of this object. -
toString
Gets a string representation of the object. The result is a comma-separated list of string representations of individual elements as "value1,value2,value3"- Overrides:
toString
in classAbstractCollection<Object>
- Returns:
- a string representation of the object.
- See Also:
-
fromValues
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.
-
fromValue
Converts specified value into AnyValueArray.- Parameters:
value
- value to be converted- Returns:
- a newly created AnyValueArray.
- See Also:
-
fromString
Splits specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.- Parameters:
values
- a string value to be split and assigned to AnyValueArrayseparator
- a separator to split the stringremoveDuplicates
- (optional) true to remove duplicated elements- Returns:
- a newly created AnyValueArray.
-
fromString
Splits specified string into elements using a separator and assigns the elements to a newly created AnyValueArray.- Parameters:
values
- a string value to be split and assigned to AnyValueArrayseparator
- a separator to split the string- Returns:
- a newly created AnyValueArray.
-