Package com.arcadedb.query.sql.executor
Class MultiValue
- java.lang.Object
-
- com.arcadedb.query.sql.executor.MultiValue
-
public class MultiValue extends Object
Handles Multi-value types such as Arrays, Collections and Maps. It recognizes special Arcade collections.- Author:
- Luca Garulli (l.garulli--(at)--gmail.com)
-
-
Constructor Summary
Constructors Constructor Description MultiValue()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
add(Object iObject, Object iToAdd)
Utility function that add a value to the main object.static Object[]
array(Object iValue)
static <T> T[]
array(Object iValue, Class<? extends T> iClass)
static <T> T[]
array(Object iValue, Class<? extends T> iClass, Callable<Object,Object> iCallback)
static boolean
contains(Object iObject, Object iItem)
static Object
convert(Object iObject, Callable<Object,Object> iCallback)
static boolean
equals(Collection<Object> col1, Collection<Object> col2)
static Object
getFirstValue(Object iObject)
Returns the first item of the Multi-value object (array, collection or map)static Object
getLastValue(Object iObject)
Returns the last item of the Multi-value object (array, collection or map)static Iterable<Object>
getMultiValueIterable(Object iObject)
Returns an Iterable<Object> object to browse the multi-value instance (array, collection or map).static Iterable<Object>
getMultiValueIterable(Object iObject, boolean iForceConvertRecord)
Returns an Iterable<Object> object to browse the multi-value instance (array, collection or map).static Iterator<Object>
getMultiValueIterator(Object iObject)
Returns an Iterator<Object> object to browse the multi-value instance (array, collection or map)static Iterator<Object>
getMultiValueIterator(Object iObject, boolean iForceConvertRecord)
Returns an Iterator<Object> object to browse the multi-value instance (array, collection or map)static <T> List<T>
getSingletonList(T item)
static int
getSize(Object iObject)
Returns the size of the multi-value objectstatic Object
getValue(Object iObject, int iIndex)
Returns the iIndex item of the Multi-value object (array, collection or map)static int
indexOf(Object iObject, Object iItem)
static boolean
isIterable(Object iObject)
static boolean
isMultiValue(Class<?> iType)
Checks if a class is a multi-value type.static boolean
isMultiValue(Object iObject)
Checks if the object is a multi-value type.static Object
remove(Object iObject, Object iToRemove, boolean iAllOccurrences)
Utility function that remove a value from the main object.protected static void
removeFromOCollection(Object iObject, Collection<Object> coll, Object iToRemove, boolean iAllOccurrences)
static void
setValue(Object iObject, Object iValue, int iIndex)
Sets the value of the Multi-value object (array or collection) at iIndexstatic Object
toSet(Object o)
static String
toString(Object iObject)
Returns a stringified version of the multi-value object.
-
-
-
Method Detail
-
isMultiValue
public static boolean isMultiValue(Class<?> iType)
Checks if a class is a multi-value type.- Parameters:
iType
- Class to check- Returns:
- true if it's an array, a collection or a map, otherwise false
-
isMultiValue
public static boolean isMultiValue(Object iObject)
Checks if the object is a multi-value type.- Parameters:
iObject
- Object to check- Returns:
- true if it's an array, a collection or a map, otherwise false
-
isIterable
public static boolean isIterable(Object iObject)
-
getSize
public static int getSize(Object iObject)
Returns the size of the multi-value object- Parameters:
iObject
- Multi-value object (array, collection or map)- Returns:
- the size of the multi value object
-
getFirstValue
public static Object getFirstValue(Object iObject)
Returns the first item of the Multi-value object (array, collection or map)- Parameters:
iObject
- Multi-value object (array, collection or map)- Returns:
- The first item if any
-
getLastValue
public static Object getLastValue(Object iObject)
Returns the last item of the Multi-value object (array, collection or map)- Parameters:
iObject
- Multi-value object (array, collection or map)- Returns:
- The last item if any
-
getValue
public static Object getValue(Object iObject, int iIndex)
Returns the iIndex item of the Multi-value object (array, collection or map)- Parameters:
iObject
- Multi-value object (array, collection or map)iIndex
- integer as the position requested- Returns:
- The first item if any
-
setValue
public static void setValue(Object iObject, Object iValue, int iIndex)
Sets the value of the Multi-value object (array or collection) at iIndex- Parameters:
iObject
- Multi-value object (array, collection)iValue
- The value to set at this specified index.iIndex
- integer as the position requested
-
getMultiValueIterable
public static Iterable<Object> getMultiValueIterable(Object iObject)
Returns an Iterable<Object> object to browse the multi-value instance (array, collection or map).- Parameters:
iObject
- Multi-value object (array, collection or map)
-
getMultiValueIterable
public static Iterable<Object> getMultiValueIterable(Object iObject, boolean iForceConvertRecord)
Returns an Iterable<Object> object to browse the multi-value instance (array, collection or map).- Parameters:
iObject
- Multi-value object (array, collection or map)iForceConvertRecord
- allow to force settings to convert RIDs to records while browsing.
-
getMultiValueIterator
public static Iterator<Object> getMultiValueIterator(Object iObject, boolean iForceConvertRecord)
Returns an Iterator<Object> object to browse the multi-value instance (array, collection or map)- Parameters:
iObject
- Multi-value object (array, collection or map)iForceConvertRecord
- allow to force settings to convert RIDs to records while browsing.
-
getMultiValueIterator
public static Iterator<Object> getMultiValueIterator(Object iObject)
Returns an Iterator<Object> object to browse the multi-value instance (array, collection or map)- Parameters:
iObject
- Multi-value object (array, collection or map)
-
toString
public static String toString(Object iObject)
Returns a stringified version of the multi-value object.- Parameters:
iObject
- Multi-value object (array, collection or map)- Returns:
- a stringified version of the multi-value object.
-
add
public static Object add(Object iObject, Object iToAdd)
Utility function that add a value to the main object. It takes care about collections/array and single values.- Parameters:
iObject
- MultiValue where to add value(s)iToAdd
- Single value, array of values or collections of values. Map are not supported.- Returns:
-
remove
public static Object remove(Object iObject, Object iToRemove, boolean iAllOccurrences)
Utility function that remove a value from the main object. It takes care about collections/array and single values.- Parameters:
iObject
- MultiValue where to add value(s)iToRemove
- Single value, array of values or collections of values. Map are not supported.iAllOccurrences
- True if the all occurrences must be removed or false of only the first one (Like java.util.Collection.remove())- Returns:
-
removeFromOCollection
protected static void removeFromOCollection(Object iObject, Collection<Object> coll, Object iToRemove, boolean iAllOccurrences)
-
array
public static <T> T[] array(Object iValue, Class<? extends T> iClass, Callable<Object,Object> iCallback)
-
equals
public static boolean equals(Collection<Object> col1, Collection<Object> col2)
-
getSingletonList
public static <T> List<T> getSingletonList(T item)
-
-