Class 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 Detail

      • MultiValue

        public MultiValue()
    • 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)
      • contains

        public static boolean contains​(Object iObject,
                                       Object iItem)
      • indexOf

        public static int indexOf​(Object iObject,
                                  Object iItem)
      • getSingletonList

        public static <T> List<T> getSingletonList​(T item)