Class ObjectUtil


  • public abstract class ObjectUtil
    extends Object
    • Constructor Detail

      • ObjectUtil

        public ObjectUtil()
    • Method Detail

      • swapArray

        public static void swapArray​(Object[] array,
                                     int index1,
                                     int index2)
        Swap the Object array
        Parameters:
        array -
        index1 -
        index2 -
      • reverseArray

        public static void reverseArray​(Object[] array)
        Reverse the Object array;
        Parameters:
        array -
      • sortArray

        public static void sortArray​(Object[] array,
                                     boolean isDesc)
        Sorting the Object array;
        Parameters:
        array -
      • removeElement

        public static Object[] removeElement​(Object[] array,
                                             String property,
                                             String val)
        Remove the all element that match the specified element from Object array.
        Parameters:
        array - Object array.
        property - and val will be match then it to be removed
        Returns:
        array after removing element.
      • removeElement

        public static Object[] removeElement​(Object[] array,
                                             Object element)
        Remove the all element that match the specified element from Object array.
        Parameters:
        array - Object array.
        element - to be removed
        Returns:
        array after removing element.
      • swapIntArray

        public static void swapIntArray​(int[] array,
                                        int index1,
                                        int index2)
        Swap the Integer array value
        Parameters:
        array -
        index1 -
        index2 -
      • reverseIntArray

        public static void reverseIntArray​(int[] array)
        Reverse the integer array;
        Parameters:
        array -
      • max

        public static Number max​(Number[] array)
        Return maximum value from array.
        Parameters:
        array -
        Returns:
        maximum value
      • min

        public static Number min​(Number[] array)
        Return minimum value from array.
        Parameters:
        array -
        Returns:
        minimum value
      • removeElement

        public static Number[] removeElement​(Number[] array,
                                             Number element)
        Remove the all element that match the specified element from integer array.
        Parameters:
        array - integer array.
        element - to be removed
        Returns:
        array after removing element.
      • sortIntegerArray

        public static void sortIntegerArray​(int[] array)
        Sort the array using bubble sort.
        Parameters:
        array -
      • dynArray

        public static String[] dynArray​(int size,
                                        String[] array)
        Parameters:
        size -
        array -
        Returns:
      • contains

        public static boolean contains​(Object[] _array,
                                       Object _object)
        Searches the given array for the given object (which can be null) by calling equals() on each item.
        Parameters:
        _array - - array of Objects to be searched
        _object - - object to search
        Returns:
        true if the array contains the _object, false otherwise
      • lastIndexOfObjectIdenticalTo

        public static int lastIndexOfObjectIdenticalTo​(Object[] _array,
                                                       Object _object)
        Searches the given array for the given object backwards and returns the index of the last slot containing that object. 'null' values are allowed.
        Parameters:
        _array - - an array of objects
        _object - - the object to be searched for (or null)
        Returns:
        the last index of object in the array, or -1 if it wasn't found
      • lastIndexOfObjectEqualTo

        public static int lastIndexOfObjectEqualTo​(Object[] _array,
                                                   Object _object)
        Searches the given array for the given object backwards and returns the index of the last slot containing that object. 'null' values are allowed.
        Parameters:
        _array - - an array of objects
        _object - - the object to be searched for (or null)
        Returns:
        the last index of object in the array, or -1 if it wasn't found
      • batchToList

        public static List<?> batchToList​(List<?> _list,
                                          int _batchSize)
        This methods takes a list and separates it into a set of batches.

        Example: batchToList(source, 2):

           source: ( 1, 2, 3, 4, 5 )
           result: ( ( 1, 2 ), ( 3, 4 ), ( 5 ) )
         
        Parameters:
        _list - - the list which should be split
        _batchSize - - the size of a batch
        Returns:
        a list of lists containing the objects
      • batchToList

        public static List batchToList​(Object[] _array,
                                       int _batchSize)
        This methods takes an array and separates it into a set of batches.

        Example: batchToList(source, 2):

           source: [ 1, 2, 3, 4, 5 ]
           result: ( ( 1, 2 ), ( 3, 4 ), ( 5 ) )
         
        Parameters:
        _array - - the array which should be split
        _batchSize - - the size of a batch
        Returns:
        a list of lists containing the objects
      • getPropertyValue

        public static <T> List<T> getPropertyValue​(Collection<?> _objects,
                                                   String _key)
        Iterates over all objects in the list, retrieves the value for the given key and stores it into a new list in the same order. This method is slightly faster than using getPropertyValue, which of course can also be used for simple keys.

        Example:

         List projectIds = valuesForKeys(projects, "logID");
         

        The returned List should be considered immutable.

        Parameters:
        _objects - the objects to retrieve the values from
        _key - the key of the values to be retrieved
        Returns:
        a list containing the values for the given key
        See Also:
        getPropertyValue()
      • getPropertyValue

        public static <T> List<T> getPropertyValue​(List<Object> _objects,
                                                   String _path)
        Iterates over all objects in the list, retrieves the value for the given key path and stores it into a new list in the same order.

        Example:

         List ownerIds = getPropertyValue(projects, "owner.id");
         

        The returned List should be considered immutable.

        Parameters:
        _objects - the objects to retrieve the values from
        _path - the keypath of the values to be retrieved
        Returns:
        a list containing the values for the given key
        See Also:
        valuesForKey()
      • valuesForKey

        public static Object[] valuesForKey​(Object[] _objects,
                                            String _key)
        Iterates over all objects in the array, retrieves the value for the given key and stores it into a new array in the same order. This method is slightly faster than using getPropertyValue, which of course can also be used for simple keys.

        Example:

         Object[] projectIds = valuesForKeys(projects, "logID");
         
        Parameters:
        _objects - the objects to retrieve the values from
        _key - the key of the values to be retrieved
        Returns:
        an array containing the values for the given key
        See Also:
        getPropertyValue()
      • getPropertyValue

        public static Object[] getPropertyValue​(Object[] _objects,
                                                String _path)
        Iterates over all objects in the array, retrieves the value for the given key path and stores it into a new array in the same order.

        Example:

         Object[] ownerIds = getPropertyValue(projects, "owner.id");
         
        Parameters:
        _objects - the objects to retrieve the values from
        _path - the keypath of the values to be retrieved
        Returns:
        an array containing the values for the given key
        See Also:
        valuesForKey()
      • groupByKeyPath

        public static HashMap<Object,​List<Object>> groupByKeyPath​(Collection<?> _objects,
                                                                        String _keyPath)
        This method walks over a collection and groups the contained object based on the value of some keypath. Example:
         Map groupedByEntity = groupByKeyPath(myObjects, "entity.name")
         
        This will iterate over the given objects and group them by the entity, a result could look like:
         { Person = [ xyz, def ]; Team = [ abc, def ]; }
         
        Parameters:
        _objects - - objects which should be grouped by the given keypath
        _keyPath - - the criteria to group on
        Returns:
        a Map which contains the group values at the keys
      • groupByKey

        public static HashMap<Object,​List<Object>> groupByKey​(Collection<?> _objects,
                                                                    String _key)
        This method walks over a collection and groups the contained object based on the value of some key. Example:
         Map groupedByCity = groupByKey(myObjects, "city")
         
        This will iterate over the given objects and group them by the city, a result could look like:
         {  Magdeburg = [
             { city = Madgeburg; name = "SWM"; },
             { city = Magdeburg; name = "Skyrix AG"; }
           ];
           Dortmund = [ ... ]; }
         

        This method currently calls groupByKeyPath() with the given key as the keypath.

        Parameters:
        _objects - objects which should be grouped by the given key
        _key - the criteria to group on (eg 'city' or 'lastname')
        Returns:
        a Map which contains the group values at the keys
      • groupByKeyPathes

        public static Map groupByKeyPathes​(Collection _objects,
                                           String[] _keyPathes)
        This method groups a collection based on a set of criterias. Eg given those keys: [ city, zip ] a result could look like:
         {
          Magdeburg = {
            39104 = [ { name = Skyrix; ...}, { name = TLG; ...} ];
            39122 = [ { name = Telekom; ...} ];
          };
          Berlin = {
            10233 = ...
            23882 = ...
          };
         }
         
        Note that only the last object in the tree is a List, all the parent groups are Maps.

        Parameters:
        _objects - the objects to be grouped
        _keyPathes - the keypathes to group the objects on
        Returns:
        a Map of Maps or Lists representing the grouping-tree
      • extractRecordFromArray

        public static HashMap extractRecordFromArray​(Object[] _array,
                                                     Object[] _keys,
                                                     int[] _keyIndices,
                                                     Format[] _keyFormats,
                                                     boolean _excludeNulls)
        Extracts a Map from an array of values.

        Using the _keyIndices array you can use one value of the _array multiple times, eg:

           array   = [ 'Donald', '1954-12-12' ]
           keys    = [ 'name', 'birthdayAsText', 'birthdayAsDate' ]
           indices = [ 0, 1, 1 ]
           formats = [ null, null, new SimpleDateFormat() ]
         
        Results in:
           { name           = Donald;
             birthdayAsText = '1954-12-12';
             birthdayAsDate = <CalendarDate: 1954-12-12>; }
         
        And another simple example:
           extractRecordFromArray(new Object[] { 'Donald', '1954-12-12' ] });
         
        Results in:
           { 0 = Donald; 1 = '1954-12-12'; }
         

        If no keys are specified, numeric Integer keys are generated (0,1,2,3,...).

        If a format throws a ParseException, the exception is stored in the slot.

        Parameters:
        _array - - array of values
        _keys - - array of Map keys to generate
        _keyIndices - - if null, _keys and _array indices must match
        _keyFormats - - value Format objects, when null, use value as-is
        _excludeNulls - - whether null values should be added
        Returns:
        a Map constructed according to the specification
      • extractRecordsFromArrays

        public static List<Map> extractRecordsFromArrays​(Object[][] _array,
                                                         Object[] _keys,
                                                         int[] _keyIndices,
                                                         Format[] _keyFormats,
                                                         boolean _excludeNulls)
        Extracts a List of Maps from an two-dimensional array of values. This is useful for converting parsed CSV files to a set of records.

        Using the _keyIndices array you can use one value of the _array multiple times, eg:

           array   = [ [ 'Donald', '1954-12-12' ] ]
           keys    = [ 'name', 'birthdayAsText', 'birthdayAsDate' ]
           indices = [ 0, 1, 1 ]
           formats = [ null, null, new SimpleDateFormat() ]
         
        Results in:
           [ { name           = Donald;
               birthdayAsText = '1954-12-12';
               birthdayAsDate = <CalendarDate: 1954-12-12>; } ]
         

        If no keys are specified, numeric Integer keys are generated (0,1,2,3,...).

        Parameters:
        _array - - an array of arrays of values
        _keys - - array of Map keys to generate
        _keyIndices - - if null, _keys and _array indices must match
        _keyFormats - - value Format objects, when null, use value as-is
        _excludeNulls - - whether null values should be added
        Returns:
        a List of Maps constructed according to the specification
      • asList

        public static List<?> asList​(Object _array)
        Converts Collections and primitive arrays to List's. If the object already is a List, its returned directly.
        Parameters:
        _array - - an arbitary Java array (eg int[], Object[]), or Collection
        Returns:
        a List containing the object items
      • arrayByAppending

        public static <T> T[] arrayByAppending​(T[] _array,
                                               T _element)
        If _array is not null, returns a copy of array which has one more element than _array, _element being the last element in this array (even if _element is null). If _array is null but _element isn't null, returns an array consisting just of _element. If both _array and _element are null, returns null.
        Parameters:
        _array - - a Java array or null (see above)
        _element - - a Java object of same type as _array or null (see above)
        Returns:
        an extended array or null (see above)
      • arrayByAppending

        public static <T> T[] arrayByAppending​(T[] _array,
                                               T _element,
                                               boolean createGenericArray)
      • arrayByRemovingFirst

        public static <T> T[] arrayByRemovingFirst​(T[] _array)
      • intValuesForObjects

        public static int[] intValuesForObjects​(Object[] _values)
        Converts an array of objects into an array of int's. If a slot is a Number object, this will store the intValue() of the number. If its a String object, the String is parsed using Integer.parseInt(). If a NumberFormatException occures, we store 0. For other objects we invoke UObject.intValue() to determine the 'int' representation of the object.
        Parameters:
        _values - - an array of objects to convert to integers
        Returns:
        an array of int's
      • listForCount

        public static List<Number> listForCount​(int _count)
        Returns a List which contains a sequence of Integer objects.

        Example:

         List<Number> a = listForCount(10);
         
        This will return the List "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]".
        Parameters:
        _count - - number of items in the List
        Returns:
        a List
      • count

        public int count​(Collection<?> collectionObj)

        To calculate size of the specified collection.

        Parameters:
        collectionObj - of which size is to be known
        Returns:
        size of the specified collection.
        Since:
        Brijframework 1.0
      • compareCollectionSize

        public static boolean compareCollectionSize​(Collection<?> coll1,
                                                    Collection<?> coll2)
      • listDifference

        public static <T> List<T> listDifference​(Class<T> objectClass,
                                                 List<?> list1,
                                                 List<?> list2)
      • getMultiValuesFormCollection

        public Map<?,​?> getMultiValuesFormCollection​(Collection<?> list,
                                                           String property)
        this method get List of values for property of object
        Parameters:
        Collection -
        Returns:
        Map
      • setPropertiesFromCollection

        public static void setPropertiesFromCollection​(Collection<?> list,
                                                       Map<String,​Object> map)
      • textToCollectionNoWhiteSpace

        public static Collection<?> textToCollectionNoWhiteSpace​(String buffer,
                                                                 String delim)
      • textToCollection

        public static Collection<?> textToCollection​(String buffer)
      • mapToCollection

        public static Collection<?> mapToCollection​(Map<?,​?> map)
      • getPropertiesFromMap

        public static Map<String,​Object> getPropertiesFromMap​(Map<?,​?> map,
                                                                    Object[] properties)
        this method get Map of values of objects
        Parameters:
        Map - , Object[]
        Returns:
        Map
      • setPropertiesFromMap

        public static void setPropertiesFromMap​(Map<String,​Object> origMap,
                                                Map<String,​Object> map)
        this method get Map of values of objects
        Parameters:
        origMap - ,map
      • updateObjectFromMap

        public void updateObjectFromMap​(Object object,
                                        Map<String,​Object> map,
                                        boolean skipNullValues)
      • updateObjectGraphFromMap

        public void updateObjectGraphFromMap​(Object object,
                                             Map<?,​?> _map)
      • arrayByAddingObjAtZeroIndex

        public Object[] arrayByAddingObjAtZeroIndex​(Object object,
                                                    Object... paramObjects)
      • getPartVectorForString

        public static Vector<Object> getPartVectorForString​(String str,
                                                            int parts)
      • hashToBytes

        public static byte[] hashToBytes​(Hashtable<?,​?> hash)
      • convertStringtoArray

        public static Vector<Object> convertStringtoArray​(String buffer)
      • convertStringtoArray1

        public static Vector<Object> convertStringtoArray1​(String buffer)
      • convertStringToVectorNoWhiteSpace

        public static Vector<Object> convertStringToVectorNoWhiteSpace​(String buffer,
                                                                       String delim)
      • convertHashtoVector

        public static Vector convertHashtoVector​(Hashtable h)
      • ConvertVectorToStringArray

        public static String[] ConvertVectorToStringArray​(Vector lines)
      • ConvertStringArrayToVector

        public static Vector ConvertStringArrayToVector​(String[] lines)
      • getIntFromHash

        public static int getIntFromHash​(Map hash,
                                         String key,
                                         boolean isMandatory,
                                         int min,
                                         int max,
                                         int defaultValue)
      • getDoubleFromHash

        public static double getDoubleFromHash​(Map hash,
                                               String key,
                                               boolean isMandatory,
                                               double min,
                                               double max,
                                               double defaultValue)
      • getBooleanFromHash

        public static boolean getBooleanFromHash​(Map hash,
                                                 String key,
                                                 boolean isMandatory,
                                                 boolean defaultValue)
      • getUncommentedValue

        public static String getUncommentedValue​(String str)
      • getVectorFromHash

        public static Vector getVectorFromHash​(Map hash,
                                               String key,
                                               boolean isMandatory,
                                               Vector defaultValue)
      • sort

        public static void sort​(List _beanObjects,
                                String key,
                                boolean isReverse)
      • listForArray

        public static ArrayList<String> listForArray​(String[] stringArray)

        This method is used to convert string Array into FNArrayList

        Parameters:
        stringArray - array of strings.
        Returns:
        FNArrayList
        Since:
        Foundation 1.0
      • listForArray

        public static List<String> listForArray​(List<String[]> listOfStringArray)

        This method is used to convert FNArrayList containing string Array into FNArrayList.

        Parameters:
        listOfStringArray - FNArrayList containing Array of strings .
        Returns:
        FNArrayList
        Since:
        Foundation 1.0
      • getCharSeparatedText

        public static String getCharSeparatedText​(Iterable iterable,
                                                  String c)
      • isEmpty

        public static boolean isEmpty​(Object[] _array)
      • isEmpty

        public static boolean isEmpty​(Collection<?> _collection)
      • isEmpty

        public static boolean isEmpty​(Map<?,​?> _map)
      • main

        public static void main​(String[] args)