Project Wonder 5.0

er.extensions.foundation
Class ERXArrayUtilities

java.lang.Object
  extended by er.extensions.foundation.ERXArrayUtilities

public class ERXArrayUtilities
extends Object

Collection of NSArray utilities.


Nested Class Summary
static class ERXArrayUtilities.AvgNonNullOperator
          Define an NSArray.Operator for the key avgNonNull.

This allows for key value paths like:
myArray.valueForKey("@avgNonNull.payment.amount"); myArray.valueForKey("payment.@avgNonNull.amount"); myArray.valueForKey("payment.amount.@avgNonNull"); which will sum up all values for the key amount and divide by the number of nun-null entries.
static class ERXArrayUtilities.FetchSpecOperator
          Define an NSArray.Operator for the key fetchSpec.

This allows for key value paths like:

myArray.valueForKey("@fetchSpec.fetchUsers");

Which in this case would return myArray filtered and sorted by the EOFetchSpecification named "fetchUsers" which must be a model-based fetchspec in the first object's entity.
static class ERXArrayUtilities.FlattenOperator
          Define an NSArray.Operator for the key flatten.

This allows for key value paths like:

myArray.valueForKey("@flatten.someOtherPath");

Which in this case would return myArray flattened if myArray is an NSArray of NSArrays (of NSArrays etc) before continuing to process someOtherPath.
static class ERXArrayUtilities.IsEmptyOperator
          Define an NSArray.Operator for the key isEmpty.

This allows for key value paths like:

myArray.valueForKey("@isEmpty");

Which in this case would return true if the myArray.count() == 0, or false if it is not.
static class ERXArrayUtilities.LimitOperator
          Define an NSArray.Operator for the key limit, which is similar to subarrayWithRange except it is always from 0 to the limit value.
static class ERXArrayUtilities.MedianOperator
          Define an NSArray.Operator for the key median.

This allows for key value paths like:
myArray.valueForKey("@median.payment.amount"); myArray.valueForKey("payment.@median.amount"); myArray.valueForKey("payment.amount.@median"); which return the median of the array elements at the given key path.
static class ERXArrayUtilities.ObjectAtIndexOperator
          Define an NSArray.Operator for the key objectAtIndex.

This allows for key value paths like:

myArray.valueForKey("@objectAtIndex.3.firstName");

static class ERXArrayUtilities.RemoveNullValuesOperator
          Define an NSArray.Operator for the key removeNullValues.

This allows for key value paths like:

myArray.valueForKeyPath("@removeNullValues.someOtherPath");

Which in this case would remove the occurrences of NSKeyValueCoding.Null from myArray before continuing to process someOtherPath.
static class ERXArrayUtilities.ReverseOperator
          Define an NSArray.Operator for the key reverse.

This allows for key value paths like:

myArray.valueForKey("@reverse.someOtherPath");

which would reverse the order of the array myArray before continuing to process someOtherPath.
static class ERXArrayUtilities.SortOperator
          Define an NSArray.Operator for the key sort.

This allows for key value paths like:
myArray.valueForKey("@sort.firstName"); myArray.valueForKey("@sort.lastName,firstName.length"); Which in the first case would return myArray sorted ascending by first name and the second case by lastName and then by the length() of the firstName.
static class ERXArrayUtilities.StandardDeviationOperator
          Define an NSArray.Operator for the key stdDev and popStdDev.

This allows for key value paths like:
myArray.valueForKey("@stdDev.payment.amount"); myArray.valueForKey("payment.@stdDev.amount"); myArray.valueForKey("payment.amount.@stdDev"); All three of these examples will return the same value, which in this case is the standard deviation of the amounts.
static class ERXArrayUtilities.SubarrayWithRangeOperator
          Define an NSArray.Operator for the key subarrayWithRange.

This allows for key value paths like:

myArray.valueForKeyPath("@subarrayWithRange.20-3.someOtherPath");

Which in this case would return the three objects from myArray, starting at the index of 20, before continuing to process someOtherPath.
static class ERXArrayUtilities.UniqueOperator
          Define an NSArray.Operator for the key unique.

This allows for key value paths like:

myArray.valueForKeyPath("@unique.someOtherPath");

Which in this case would return only those objects which are unique in myArray before continuing to process someOtherPath.
 
Field Summary
static String NULL_GROUPING_KEY
          Holds the null grouping key for use when grouping objects based on a key that might return null and nulls are allowed
 
Constructor Summary
ERXArrayUtilities()
           
 
Method Summary
static
<T> void
addObjectsFromArrayWithoutDuplicates(NSMutableArray<T> a1, NSArray<? extends T> a2)
          Adds all of the non-duplicate elements from the second array to the mutable array.
static
<T> NSArray<T>
arrayByAddingObjectsFromArrayWithoutDuplicates(NSArray<? extends T> a1, NSArray<? extends T> a2)
          Creates an array preserving order by adding all of the non-duplicate values from the second array to the first.
static
<T> NSArray<T>
arrayByRemovingFirstObject(NSArray<T> array)
          Creates an array that has all of the objects of the parameter array without the first object.
static
<T> NSArray<T>
arrayBySelectingInstancesOfClass(NSArray<?> array, Class<T> aClass)
          Prunes an array for only instances of the given class.
static
<T> boolean
arrayContainsAnyObjectFromArray(NSArray<? extends T> array, NSArray<? extends T> objects)
          Function to determine if an array contains any of the elements of another array.
static
<T> boolean
arrayContainsArray(NSArray<? extends T> array, NSArray<? extends T> objects)
          Function to determine if an array contains all of the elements of another array.
static NSArray<?> arrayForKeysPath(NSArray<?> array, NSArray<String> keys)
          Returns an array of dictionaries containing the key/value pairs for the given paths.
static NSArray arrayFromPropertyList(String name, NSBundle bundle)
          Creates an NSArray from a resource associated with a given bundle that is in property list format.
static
<T,K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByKeyPath(NSArray<T> objects, ERXKey<K> keyPath, boolean includeNulls, ERXKey<V> valueKeyPath)
          Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary.
static
<T,K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByKeyPath(NSArray<T> objects, ERXKey<K> keyPath, K nullGroupingKey, ERXKey<V> valueKeyPath)
          Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary.
static
<T,K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByKeyPath(NSArray<T> objects, String keyPath, boolean includeNulls, String valueKeyPath)
          Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary.
static
<K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByKeyPath(NSArray<V> objects, ERXKey<K> keyPath)
          Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary.
static
<K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByKeyPath(NSArray<V> objects, String keyPath)
          Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary.
static NSDictionary arrayGroupedByKeyPath(NSArray objects, String keyPath, Object nullGroupingKey, String valueKeyPath)
          Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary.
static
<T,K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByToManyKeyPath(NSArray<T> objects, ERXKey<K> keyPath, K nullGroupingKey, ERXKey<V> valueKeyPath)
          Typesafe variant of arrayGroupedByToManyKeyPath.
static
<K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByToManyKeyPath(NSArray<V> objects, ERXKey<K> keyPath, boolean includeNulls)
          Typesafe variant of arrayGroupedByToManyKeyPath.
static
<K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByToManyKeyPath(NSArray<V> objects, ERXKey<K> keyPath, K nullGroupingKey)
          Typesafe variant of arrayGroupedByToManyKeyPath.
static
<K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByToManyKeyPath(NSArray<V> objects, String keyPath, boolean includeNulls)
          Groups an array of objects by a given to-many key path, where every single item in the to-many will put the object in the corresponding group.
static
<K,V> NSDictionary<K,NSArray<V>>
arrayGroupedByToManyKeyPath(NSArray<V> objects, String keyPath, K nullGroupingKey)
          Groups an array of objects by a given to-many key path, where every single item in the to-many will put the object in the corresponding group.
static NSDictionary arrayGroupedByToManyKeyPath(NSArray objects, String keyPath, Object nullGroupingKey, String valueKeyPath)
          Groups an array of objects by a given to-many key path, where every single item in the to-many will put the object in the corresponding group.
static boolean arrayIsNullOrEmpty(NSArray<?> aNSArray)
           Check if an NSArray is null or Empty
static
<T> NSArray<T>
arrayMinusArray(NSArray<T> main, NSArray<?> minus)
          Subtracts the contents of one array from another.
static
<T> NSArray<T>
arrayMinusObject(NSArray<T> main, Object object)
          Subtracts a single object from an array.
static
<T> boolean
arraysAreIdenticalSets(NSArray<? super T> a1, NSArray<? super T> a2)
          Simple comparison method to see if two array objects are identical sets.
static String arrayToLogstring(NSArray<String> aNSArray)
           To create oneLine Log for an NSArray<String>
static
<T> NSArray<T>
arrayWithObjectsAtIndexesSwapped(NSArray<T> array, int indexOfObject1, int indexOfObject2)
          Swaps the two objects at the given indexes in the given NSArray and returns a new NSArray.
static
<T> NSArray<T>
arrayWithObjectsSwapped(NSArray<T> array, Object object1, Object object2)
          Swaps the two given Objects in the given NSArray and returns a new NSArray.
static
<T> NSArray<T>
arrayWithoutDuplicateKeyValue(NSArray<T> objects, String key)
          Filters out duplicates of an array of objects based on the value of the given key path off of those objects.
static
<T> NSArray<T>
arrayWithoutDuplicates(NSArray<T> anArray)
          Filters out all of the duplicate objects in a given array.
Preserves the order now.
static
<T> NSArray<NSArray<T>>
batchedArrayWithSize(NSArray<T> array, int batchSize)
          Batches an NSArray into sub-arrays of the given size.
static
<T> NSArray<T>
deepClone(NSArray<T> array, boolean onlyCollections)
          Returns a deep clone of the given array.
static
<T> NSSet<T>
deepClone(NSSet<T> set, boolean onlyCollections)
          Returns a deep clone of the given set.
static
<K,T> NSDictionary<K,T>
dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array, String keyPath)
          Calls dictionaryOfObjectsIndexedByKeyPathThrowOnCollision() passing false for throwOnCollision.
static
<K,T> NSDictionary<K,T>
dictionaryOfObjectsIndexedByKeyPathThrowOnCollision(NSArray<T> array, String keyPath, boolean throwOnCollision)
          Given an array of objects, returns a dictionary mapping the value by performing valueForKeyPath on each object in the array to the object in the array.
static
<T> NSArray<T>
distinct(NSArray<T> array)
          Shorter name for arrayWithoutDuplicates, which I always forget the name of.
static boolean enumerationHasMatchWithQualifierEvaluation(Enumeration<?> enumeration, EOQualifierEvaluation qualifier)
          Filters any kinds of collections that implements Enumeration interface such as NSArray, NSSet, Vector and Hashtable using the EOQualifierEvaluation interface.
static
<T> NSArray<T>
filteredArrayWithEntityFetchSpecification(NSArray<T> array, String entity, String fetchSpec)
          Filters a given array with a named fetch specification.
static
<T> NSArray<T>
filteredArrayWithEntityFetchSpecification(NSArray<T> array, String entity, String fetchSpec, NSDictionary<String,?> bindings)
          Filters a given array with a named fetch specification and bindings.
static
<T> NSArray<T>
filteredArrayWithFetchSpecificationNamedEntityNamed(NSArray<T> array, String fetchSpec, String entity)
          Deprecated. use filteredArrayWithEntityFetchSpecification(NSArray, String, String, NSDictionary)
static
<T> NSArray<T>
filteredArrayWithFetchSpecificationNamedEntityNamedBindings(NSArray<T> array, String fetchSpec, String entity, NSDictionary<String,?> bindings)
          Deprecated. use filteredArrayWithEntityFetchSpecification(NSArray, String, String, NSDictionary)
static
<T> NSArray<T>
filteredArrayWithQualifierEvaluation(Enumeration<T> enumeration, EOQualifierEvaluation qualifier)
          Filters any kinds of collections that implements Enumeration interface such as NSArray, NSSet, Vector and Hashtable using the EOQualifierEvaluation interface.
static
<T> NSArray<T>
filteredArrayWithQualifierEvaluation(Iterator<T> iterator, EOQualifierEvaluation qualifier)
          Filters any kind of collections that implements Iterator interface such as ArrayList, HashMap, SortedSet and TreeSet using the EOQualifierEvaluation interface.
static
<T> NSArray<T>
filteredArrayWithQualifierEvaluation(NSArray<T> array, EOQualifierEvaluation qualifier)
          Filters an array using the EOQualifierEvaluation interface.
static
<T> T
firstObject(NSArray<T> array)
          Returns the first object of the array.
static
<T> T
firstObjectWithValueForKeyPath(NSArray<T> array, Object value, String keyPath)
          Finds the first object in the array with a given value for a given key path.
static NSArray flatten(NSArray<?> originalArray)
          Recursively flattens an array of arrays and individual objects into a single array of elements.

For example:
NSArray foos; //Assume exists
NSArray bars = (NSArray)foos.valueForKey("toBars"); In this case if foos contained five elements then the array bars will contain five arrays each corresponding to what aFoo.toBars would return.
static NSArray flatten(NSArray<?> originalArray, boolean filterDuplicates)
          Recursively flattens an array of arrays and individual objects into a single array of elements.

For example:
NSArray foos; //Assume exists
NSArray bars = (NSArray)foos.valueForKey("toBars"); In this case if foos contained five elements then the array bars will contain five arrays each corresponding to what aFoo.toBars would return.
static String friendlyDisplayForKeyPath(NSArray<?> list, String attribute, String nullArrayDisplay, String separator, String finalSeparator)
          Displays a list of attributes off of objects in a 'friendly' manner.
static int indexOfFirstObjectWithValueForKeyPath(NSArray<?> array, Object value, String keyPath)
          Finds the index of the first object in the array with a given value for a given keypath.
static
<T> int
indexOfObjectUsingEqualator(NSArray<T> array, T object, ERXEqualator equalator)
          Locates an object within an array using a custom equality check provided as an ERXEqualator.
static void initialize()
          Will register new NSArray operators sort, sortAsc, sortDesc, sortInsensitiveAsc, sortInsensitiveDesc, unique, flatten, reverse, limit, and fetchSpec
static
<T> NSArray<T>
intersectingElements(NSArray<? extends T> array1, NSArray<? extends T> array2)
          Intersects the elements of two arrays.
static boolean iteratorHasMatchWithQualifierEvaluation(Iterator<?> iterator, EOQualifierEvaluation qualifier)
          Filters any kinds of collections that implements Iterator interface such as NSArray, NSSet, Vector and Hashtable using the EOQualifierEvaluation interface.
static Number median(NSArray<?> array, String keypath)
          Calculates the median value of an array.
static String[] objectArrayCastToStringArray(Object[] o)
          Converts an Object array to a String array by casting each element.
static String objectArraysToString(NSArray<Object[][]> array)
          pretty prints a NSArray of two dimensional Object array which is ugly when using toString
static String objectArrayToString(Object[] o)
          pretty prints an Object array which is ugly when using toString
static String objectArrayToString(Object[][] array)
          pretty prints a two dimensional Object array which is ugly when using toString
static
<T> NSArray<T>
objectsWithValueForKeyPath(NSArray<T> array, Object valueToLookFor, String keyPath)
          Walks over an array and returns an array of objects from that array that have a particular value for a particular key path.
static
<T> NSArray<T>
removeNullValues(NSArray<T> array)
          Removes all occurrences of NSKeyValueCoding.NullValue in the provided array
static
<T> NSArray<T>
removeNullValues(NSArray<T> target, NSArray<T> array)
          Removes all occurrences of NSKeyValueCoding.NullValue in the provided array
static
<T> NSArray<T>
removeNullValuesFromEnd(NSArray<T> array)
          removes all occurencies of NSKeyValueCoding.Null from the end of the array
static
<T> NSArray<T>
reverse(NSArray<T> array)
          Reverses the elements of an array
static
<T> void
safeAddObject(NSMutableArray<T> array, T object)
          Adds the object to the mutable array if the object is not null.
static
<T> NSSet<T>
setFromArray(NSArray<T> array)
          Simply utility method to create a concrete set object from an array.
static
<T> void
shiftObjectLeft(NSMutableArray<T> array, T object)
          shifts a given object in an array one value to the left (index--).
static
<T> void
shiftObjectRight(NSMutableArray<T> array, T object)
          shifts a given object in an array one value to the right (index++).
static void sortArrayWithKey(NSMutableArray<?> array, String key)
          Sorts a given mutable array with a key in place.
static void sortArrayWithKey(NSMutableArray<?> array, String key, NSSelector selector)
          Sorts a given mutable array with a key in place.
static
<T> NSArray<T>
sortedArraySortedWithKey(NSArray<T> array, String key)
          Sorts a given array with a key in ascending fashion.
static
<T> NSArray<T>
sortedArraySortedWithKey(NSArray<T> array, String key, NSSelector selector)
          Sorts a given array with a key in ascending fashion.
static
<T> NSArray<T>
sortedArraySortedWithKeys(NSArray<T> array, NSArray<String> keys, NSSelector selector)
          Sorts a given array with a set of keys according to the given selector.
static
<T> NSArray<T>
sortedArrayUsingComparator(NSArray<T> array, NSComparator comparator)
          Just like the method NSArray#sortedArrayUsingComparator(NSComparator), except it catches the NSComparator.ComparisonException and, if thrown, it wraps it in a runtime exception.
static
<T> NSMutableArray<T>
sortedMutableArraySortedWithKey(NSArray<T> array, String key)
          Sorts a given array with a key in ascending fashion and returns a mutable clone of the result.
static NSSelector sortSelectorWithKey(String key)
          The qualifiers EOSortOrdering.CompareAscending and friends are actually 'special' and processed in a different/faster way when sorting than a selector that would be created by: new NSSelector("compareAscending", ObjectClassArray) This method eases the pain on creating those selectors from a string.
static Number stdDev(NSArray<?> array, String keypath, boolean isPopulation)
          Finds the standard deviation of the numeric values found in the array at the specified keypath.
static
<T> void
swapObjectsAtIndexesInArray(NSMutableArray<T> array, int indexOfA, int indexOfB)
          Swaps two objects at the given indexes in an array inplace
static
<T> void
swapObjectsInArray(NSMutableArray<T> array, T a, T b)
          Swaps two objects a and b in an array inplace
static
<T> void
swapObjectWithObjectAtIndexInArray(NSMutableArray<T> array, T a, int indexOfB)
          Swaps the object a with the object at the given index
static String[] toStringArray(NSArray<?> a)
           
static NSArray valuesForKeyPaths(Object array, NSArray<String> paths)
          Performs multiple key-value coding calls against an array or an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_GROUPING_KEY

public static final String NULL_GROUPING_KEY
Holds the null grouping key for use when grouping objects based on a key that might return null and nulls are allowed

See Also:
Constant Field Values
Constructor Detail

ERXArrayUtilities

public ERXArrayUtilities()
Method Detail

setFromArray

public static <T> NSSet<T> setFromArray(NSArray<T> array)
Simply utility method to create a concrete set object from an array.

Parameters:
array - of elements
Returns:
set created from given array

sortSelectorWithKey

public static NSSelector sortSelectorWithKey(String key)
The qualifiers EOSortOrdering.CompareAscending and friends are actually 'special' and processed in a different/faster way when sorting than a selector that would be created by: new NSSelector("compareAscending", ObjectClassArray) This method eases the pain on creating those selectors from a string.

Parameters:
key - sort key
Returns:
selector for the given sort ordering key or null

arrayGroupedByKeyPath

public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(NSArray<V> objects,
                                                                     ERXKey<K> keyPath)
Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary. If passed a null array, null is returned. If passed a null keyPath, an empty dictionary is returned. This is a typesafe variant of arrayGroupedByKeyPath(NSArray objects, String keyPath).

See arrayGroupedByKeyPath(NSArray objects, String keyPath) for examples.

This method calls arrayGroupedByKeyPath(NSArray objects, String keyPath, Object nullGroupingKey, String valueKeyPath) with includeNulls set to true and valueKeyPath set to null.

Parameters:
objects - array of objects to be grouped
keyPath - path into objects used to group the objects
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have that value. Objects for which the key path returns null will be grouped with the key NULL_GROUPING_KEY

arrayGroupedByKeyPath

public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(NSArray<V> objects,
                                                                     String keyPath)
Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary. If passed a null array, null is returned. If passed a null keyPath, an empty dictionary is returned.

If one starts with:

( { lastName = "Barker"; firstName = "Bob"; favoriteColor = "blue"; },
{ firstName = "Bob"; favoriteColor = "red"; },
{ lastName = "Further"; firstName = "Frank"; favoriteColor = "green"; } )
and one calls arrayGroupedByKeyPath(objects, "firstName"), one gets:
{ "Bob" = ( { lastName = "Barker"; firstName = "Bob"; favoriteColor = "blue"; }, { firstName = "Bob"; favoriteColor = "red"; } );
"Frank" = ( { lastName = "Further"; firstName = "Frank"; favoriteColor = "green"; } ); }

If one calls arrayGroupedByKeyPath(objects, "lastName"), one gets:
{ "Bob" = ( { lastName = "Barker"; firstName = "Bob"; favoriteColor = "blue"; } );
"Frank" = ( { lastName = "Further"; firstName = "Frank"; favoriteColor = "green"; } );
"**** NULL GROUPING KEY ****" = ( { firstName = "Bob"; favoriteColor = "red"; } ); }

This method calls arrayGroupedByKeyPath(objects, keyPath, includeNulls, valueKeyPath) with includeNulls set to true and valueKeyPath set to null.

Parameters:
objects - array of objects to be grouped
keyPath - path into objects used to group the objects
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have that value. Objects for which the key path returns null will be grouped with the key NULL_GROUPING_KEY

arrayGroupedByKeyPath

public static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(NSArray<T> objects,
                                                                       ERXKey<K> keyPath,
                                                                       boolean includeNulls,
                                                                       ERXKey<V> valueKeyPath)
Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary. If passed a null array, null is returned. If passed a null keyPath, an empty dictionary is returned. If valueKeyPath is not null, then the grouped arrays each have valueForKey called with valueKeyPath and the grouped arrays are replaced with the results of those calls. This is a typesafe variant of arrayGroupedByKeyPath(NSArray objects, String keyPath, boolean includeNulls, String valueKeyPath).

See arrayGroupedByKeyPath(NSArray objects, String keyPath, boolean includeNulls, String valueKeyPath) for examples.

Parameters:
objects - array of objects to be grouped
keyPath - path into objects used to group the objects
includeNulls - determines if keyPaths that resolve to null are included in the resulting dictionary
valueKeyPath - used to call valueForKey on the arrays in the results dictionary, with the results of those calls each replacing the corresponding array in the results dictionary.
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have that value. Objects for which the key path returns null will be grouped with the key NULL_GROUPING_KEY

arrayGroupedByKeyPath

public static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(NSArray<T> objects,
                                                                       String keyPath,
                                                                       boolean includeNulls,
                                                                       String valueKeyPath)
Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary. If passed a null array, null is returned. If passed a null keyPath, an empty dictionary is returned. If valueKeyPath is not null, then the grouped arrays each have valueForKey called with valueKeyPath and the grouped arrays are replaced with the results of those calls.

If one starts with:

( { lastName = "Barker"; firstName = "Bob"; favoriteColor = "blue"; },
{ firstName = "Bob"; favoriteColor = "red"; },
{ lastName = "Further"; firstName = "Frank"; favoriteColor = "green"; } )
and one calls arrayGroupedByKeyPath(objects, "firstName", true, "favoriteColor"), one gets:
{Frank = ("green"); Bob = ("blue", "red");
If one calls arrayGroupedByKeyPath(objects, "lastName", false, "favoriteColor"), one gets:
{Further = ("green"); Barker = ("blue"); }

If one calls arrayGroupedByKeyPath(objects, "lastName", true, "favoriteColor"), one gets:
{Further = ("green"); Barker = ("blue"); "**** NULL GROUPING KEY ****" = ("red"); }

Parameters:
objects - array of objects to be grouped
keyPath - path into objects used to group the objects
includeNulls - determines if keyPaths that resolve to null are included in the resulting dictionary
valueKeyPath - used to call valueForKey on the arrays in the results dictionary, with the results of those calls each replacing the corresponding array in the results dictionary.
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have that value. Objects for which the key path returns null will be grouped with the key NULL_GROUPING_KEY

arrayGroupedByKeyPath

public static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(NSArray<T> objects,
                                                                       ERXKey<K> keyPath,
                                                                       K nullGroupingKey,
                                                                       ERXKey<V> valueKeyPath)
Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary. If passed a null array, null is returned. If passed a null keyPath, an empty dictionary is returned. If valueKeyPath is not null, then the grouped arrays each have valueForKey called with valueKeyPath and the grouped arrays are replaced with the results of those calls. This is a typesafe variant of arrayGroupedByKeyPath(NSArray objects, String keyPath, Object nullGroupingKey, String valueKeyPath).

See arrayGroupedByKeyPath(NSArray objects, String keyPath, Object nullGroupingKey, String valueKeyPath) for examples.

Parameters:
objects - array of objects to be grouped
keyPath - path into objects used to group the objects
nullGroupingKey - used as the key in the results dictionary for the array of objects for which the valueForKey with keyPath result is null.
valueKeyPath - used to call valueForKey on the arrays in the results dictionary, with the results of those calls each replacing the corresponding array in the results dictionary.
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have that value. Objects for which the key path returns null will be grouped with the key NULL_GROUPING_KEY

arrayGroupedByKeyPath

public static NSDictionary arrayGroupedByKeyPath(NSArray objects,
                                                 String keyPath,
                                                 Object nullGroupingKey,
                                                 String valueKeyPath)
Starting with an array of KeyValueCoding-compliant objects and a keyPath, this method calls valueForKey on each object in the array and groups the contents of the array, using the result of the valueForKey call as a key in a dictionary. If passed a null array, null is returned. If passed a null keyPath, an empty dictionary is returned. If valueKeyPath is not null, then the grouped arrays each have valueForKey called with valueKeyPath and the grouped arrays are replaced with the results of that call.

If one starts with:

( { lastName = "Barker"; firstName = "Bob"; favoriteColor = "blue"; },
{ firstName = "Bob"; favoriteColor = "red"; },
{ lastName = "Further"; firstName = "Frank"; favoriteColor = "green"; } )
and one calls arrayGroupedByKeyPath(objects, "firstName", null, "favoriteColor"), one gets:
{Frank = ("green"); Bob = ("blue", "red");
If one calls arrayGroupedByKeyPath(objects, "lastName", "extra", "favoriteColor"), one gets:
{Further = ("green"); Barker = ("blue"); "extra" = ("red"); }
If one calls arrayGroupedByKeyPath(objects, "lastName", null, "favoriteColor"), one gets:
{Further = ("green"); Barker = ("blue"); "**** NULL GROUPING KEY ****" = ("red"); }

Parameters:
objects - array of objects to be grouped
keyPath - path into objects used to group the objects
nullGroupingKey - used as the key in the results dictionary for the array of objects for which the valueForKey with keyPath result is null.
valueKeyPath - used to call valueForKey on the arrays in the results dictionary, with the results of those calls each replacing the corresponding array in the results dictionary.
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have that value. Objects for which the key path returns null will be grouped with the key NULL_GROUPING_KEY

arrayGroupedByToManyKeyPath

public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(NSArray<V> objects,
                                                                           ERXKey<K> keyPath,
                                                                           boolean includeNulls)
Typesafe variant of arrayGroupedByToManyKeyPath.

Parameters:
objects - the objects to be grouped
keyPath - the key to group by
includeNulls - determins if the keypaths that resolve to null should be allowed in the group
Returns:
the resulting dictionary

arrayGroupedByToManyKeyPath

public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(NSArray<V> objects,
                                                                           String keyPath,
                                                                           boolean includeNulls)
Groups an array of objects by a given to-many key path, where every single item in the to-many will put the object in the corresponding group. A typical example is an array of users with a roles relationship. The result to calling arrayGroupedByToManyKeyPath(users, "roles.name") would be "admin" = (user1, user2); "editor" = (user3);.... The dictionary that is returned contains keys that correspond to the grouped keys values. This means that the object pointed to by the key path must be a cloneable object. For instance using the key path 'users' would not work because enterprise objects are not cloneable. Instead you might choose to use the key path 'users.name' of 'users.primaryKey', if your enterprise objects support this see ERXGenericRecord if interested.

Parameters:
objects - array of objects to be grouped
keyPath - path used to group the objects.
includeNulls - determines if keyPaths that resolve to null should be allowed into the group.
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have the grouped characteristic. Note that if the key path returns null then one of the keys will be the static ivar NULL_GROUPING_KEY

arrayGroupedByToManyKeyPath

public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(NSArray<V> objects,
                                                                           ERXKey<K> keyPath,
                                                                           K nullGroupingKey)
Typesafe variant of arrayGroupedByToManyKeyPath.

Parameters:
objects - array of objects to be grouped
keyPath - path used to group the objects.
nullGroupingKey - if not-null, determines if keyPaths that resolve to null should be allowed into the group; if so, this key is used for them
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have the grouped characteristic. Note that if the key path returns null then one of the keys will be the static ivar NULL_GROUPING_KEY

arrayGroupedByToManyKeyPath

public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(NSArray<V> objects,
                                                                           String keyPath,
                                                                           K nullGroupingKey)
Groups an array of objects by a given to-many key path, where every single item in the to-many will put the object in the corresponding group. The dictionary that is returned contains keys that correspond to the grouped keys values. This means that the object pointed to by the key path must be a cloneable object. For instance using the key path 'users' would not work because enterprise objects are not cloneable. Instead you might choose to use the key path 'users.name' of 'users.primaryKey', if your enterprise objects support this see ERXGenericRecord if interested.

Parameters:
objects - array of objects to be grouped
keyPath - path used to group the objects.
nullGroupingKey - if not-null, determines if keyPaths that resolve to null should be allowed into the group; if so, this key is used for them
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have the grouped characteristic. Note that if the key path returns null then one of the keys will be the static ivar NULL_GROUPING_KEY

arrayGroupedByToManyKeyPath

public static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(NSArray<T> objects,
                                                                             ERXKey<K> keyPath,
                                                                             K nullGroupingKey,
                                                                             ERXKey<V> valueKeyPath)
Typesafe variant of arrayGroupedByToManyKeyPath.

Parameters:
objects - array of objects to be grouped
keyPath - path used to group the objects.
nullGroupingKey - if not-null, determines if keyPaths that resolve to null should be allowed into the group; if so, this key is used for them
valueKeyPath - allows the grouped objects in the result to be derived from objects (by evaluating valueKeyPath), instead of being members of the objects collection. Objects that evaluate valueKeyPath to null have no value included in the result
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have the grouped characteristic. Note that if the key path returns null then one of the keys will be the static ivar NULL_GROUPING_KEY

arrayGroupedByToManyKeyPath

public static NSDictionary arrayGroupedByToManyKeyPath(NSArray objects,
                                                       String keyPath,
                                                       Object nullGroupingKey,
                                                       String valueKeyPath)
Groups an array of objects by a given to-many key path, where every single item in the to-many will put the object in the corresponding group. The dictionary that is returned contains keys that correspond to the grouped keys values. This means that the object pointed to by the key path must be a cloneable object. For instance using the key path 'users' would not work because enterprise objects are not cloneable. Instead you might choose to use the key path 'users.name' of 'users.primaryKey', if your enterprise objects support this see ERXGenericRecord if interested.

Parameters:
objects - array of objects to be grouped
keyPath - path used to group the objects.
nullGroupingKey - if not-null, determines if keyPaths that resolve to null should be allowed into the group; if so, this key is used for them
valueKeyPath - allows the grouped objects in the result to be derived from objects (by evaluating valueKeyPath), instead of being members of the objects collection. Objects that evaluate valueKeyPath to null have no value included in the result
Returns:
a dictionary where the keys are the grouped values and the objects are arrays of the objects that have the grouped characteristic. Note that if the key path returns null then one of the keys will be the static ivar NULL_GROUPING_KEY

arraysAreIdenticalSets

public static <T> boolean arraysAreIdenticalSets(NSArray<? super T> a1,
                                                 NSArray<? super T> a2)
Simple comparison method to see if two array objects are identical sets.

Parameters:
a1 - first array
a2 - second array
Returns:
result of comparison

filteredArrayWithQualifierEvaluation

public static <T> NSArray<T> filteredArrayWithQualifierEvaluation(NSArray<T> array,
                                                                  EOQualifierEvaluation qualifier)
Filters an array using the EOQualifierEvaluation interface.

Parameters:
array - to be filtered
qualifier - to do the filtering
Returns:
array of filtered results.

filteredArrayWithQualifierEvaluation

public static <T> NSArray<T> filteredArrayWithQualifierEvaluation(Enumeration<T> enumeration,
                                                                  EOQualifierEvaluation qualifier)
Filters any kinds of collections that implements Enumeration interface such as NSArray, NSSet, Vector and Hashtable using the EOQualifierEvaluation interface.

Parameters:
enumeration - to be filtered; to obtain an enumeration, use objectEnumerator() for the collections in com.webobjects.foundation package and use elements() for the Vector and Hashtable
qualifier - to do the filtering
Returns:
array of filtered results.

enumerationHasMatchWithQualifierEvaluation

public static boolean enumerationHasMatchWithQualifierEvaluation(Enumeration<?> enumeration,
                                                                 EOQualifierEvaluation qualifier)
Filters any kinds of collections that implements Enumeration interface such as NSArray, NSSet, Vector and Hashtable using the EOQualifierEvaluation interface.

Parameters:
enumeration - to be filtered; to obtain an enumeration, use objectEnumerator() for the collections in com.webobjects.foundation package and use elements() for the Vector and Hashtable
qualifier - to do the filtering
Returns:
true if there is at least one match

iteratorHasMatchWithQualifierEvaluation

public static boolean iteratorHasMatchWithQualifierEvaluation(Iterator<?> iterator,
                                                              EOQualifierEvaluation qualifier)
Filters any kinds of collections that implements Iterator interface such as NSArray, NSSet, Vector and Hashtable using the EOQualifierEvaluation interface.

Parameters:
iterator - to be filtered; to obtain an iterator, use iterator() for the java collections
qualifier - to do the filtering
Returns:
true if there is at least one match

filteredArrayWithQualifierEvaluation

public static <T> NSArray<T> filteredArrayWithQualifierEvaluation(Iterator<T> iterator,
                                                                  EOQualifierEvaluation qualifier)
Filters any kind of collections that implements Iterator interface such as ArrayList, HashMap, SortedSet and TreeSet using the EOQualifierEvaluation interface.

Parameters:
iterator - to be filtered; use iterator() to obtain an iterator from the collections
qualifier - to do the filtering
Returns:
array of filtered results.

arrayWithoutDuplicateKeyValue

public static <T> NSArray<T> arrayWithoutDuplicateKeyValue(NSArray<T> objects,
                                                           String key)
Filters out duplicates of an array of objects based on the value of the given key path off of those objects. Objects with a null value will be skipped, too.

Parameters:
objects - array of objects
key - keypath to be evaluated off of every object
Returns:
filter array of objects based on the value of a keypath.

arrayMinusArray

public static <T> NSArray<T> arrayMinusArray(NSArray<T> main,
                                             NSArray<?> minus)
Subtracts the contents of one array from another. The order of the array should be preseved.

Parameters:
main - array to have values removed from it.
minus - array of values to remove from the main array
Returns:
array after performing subtraction.

arrayMinusObject

public static <T> NSArray<T> arrayMinusObject(NSArray<T> main,
                                              Object object)
Subtracts a single object from an array.

Parameters:
main - array to have value removed from it.
object - to be removed
Returns:
array after performing subtraction.

arrayByAddingObjectsFromArrayWithoutDuplicates

public static <T> NSArray<T> arrayByAddingObjectsFromArrayWithoutDuplicates(NSArray<? extends T> a1,
                                                                            NSArray<? extends T> a2)
Creates an array preserving order by adding all of the non-duplicate values from the second array to the first.

Parameters:
a1 - first array
a2 - second array
Returns:
array containing all of the elements of the first array and all of the non-duplicate elements of the second array.

arrayByRemovingFirstObject

public static <T> NSArray<T> arrayByRemovingFirstObject(NSArray<T> array)
Creates an array that has all of the objects of the parameter array without the first object.

Parameters:
array - the array to use to create the result
Returns:
an array containing all objects but the first of the parameter array. if null is passed, null is returned. if the parameter array is empty, an empty array is returned.

safeAddObject

public static <T> void safeAddObject(NSMutableArray<T> array,
                                     T object)
Adds the object to the mutable array if the object is not null.

Parameters:
array - mutable array where non-null object will be added
object - to be added to array

addObjectsFromArrayWithoutDuplicates

public static <T> void addObjectsFromArrayWithoutDuplicates(NSMutableArray<T> a1,
                                                            NSArray<? extends T> a2)
Adds all of the non-duplicate elements from the second array to the mutable array.

Parameters:
a1 - mutable array where non-duplicate objects are added
a2 - array to be added to a1

flatten

public static NSArray flatten(NSArray<?> originalArray,
                              boolean filterDuplicates)
Recursively flattens an array of arrays and individual objects into a single array of elements.

For example:
NSArray foos; //Assume exists
NSArray bars = (NSArray)foos.valueForKey("toBars"); In this case if foos contained five elements then the array bars will contain five arrays each corresponding to what aFoo.toBars would return. To have the entire collection of bars in one single array you would call: NSArray allBars = flatten(bars)

Parameters:
originalArray - array to be flattened
filterDuplicates - determines if the duplicate values should be filtered
Returns:
an array containing all of the elements from all of the arrays contained within the array passed in. (Optionally, with duplicate elements filtered out)

flatten

public static NSArray flatten(NSArray<?> originalArray)
Recursively flattens an array of arrays and individual objects into a single array of elements.

For example:
NSArray foos; //Assume exists
NSArray bars = (NSArray)foos.valueForKey("toBars"); In this case if foos contained five elements then the array bars will contain five arrays each corresponding to what aFoo.toBars would return. To have the entire collection of bars in one single array you would call: NSArray allBars = flatten(bars)

Parameters:
originalArray - array to be flattened
Returns:
an array containing all of the elements from all of the arrays contained within the array passed in.

arrayFromPropertyList

public static NSArray arrayFromPropertyList(String name,
                                            NSBundle bundle)
Creates an NSArray from a resource associated with a given bundle that is in property list format.

Parameters:
name - name of the file or resource.
bundle - NSBundle to which the resource belongs.
Returns:
NSArray de-serialized from the property list.

valuesForKeyPaths

public static NSArray valuesForKeyPaths(Object array,
                                        NSArray<String> paths)
Performs multiple key-value coding calls against an array or an object.

Parameters:
array - collection or object to be acted upon.
paths - array of keypaths.
Returns:
for collections, returns an array containing an array of values for every keypath. For objects, returns an array containing a value for every keypath.

firstObject

public static <T> T firstObject(NSArray<T> array)
Returns the first object of the array. If the array is null or empty, null is returned.

Parameters:
array - the array to search.
Returns:
the first object in array. null if array is empty or if array is null.

indexOfFirstObjectWithValueForKeyPath

public static int indexOfFirstObjectWithValueForKeyPath(NSArray<?> array,
                                                        Object value,
                                                        String keyPath)
Finds the index of the first object in the array with a given value for a given keypath. Assumes that all objects in the array either are NSKeyValueCoding.NullValue or have the given keypath.

Parameters:
array - the array to search.
value - the value to look for.
keyPath - the keypath to use to compare to value.
Returns:
index of the first object with the qualification. -1 if none matches.

firstObjectWithValueForKeyPath

public static <T> T firstObjectWithValueForKeyPath(NSArray<T> array,
                                                   Object value,
                                                   String keyPath)
Finds the first object in the array with a given value for a given key path.

Parameters:
array - the array to search.
value - the value to look for.
keyPath - the keypath to use to compare to value.
Returns:
first object in the array with the qualification. null if none matches.

objectsWithValueForKeyPath

public static <T> NSArray<T> objectsWithValueForKeyPath(NSArray<T> array,
                                                        Object valueToLookFor,
                                                        String keyPath)
Walks over an array and returns an array of objects from that array that have a particular value for a particular key path. Treats null and NSKeyValueCoding.NullValue equivalently. Any NSKeyValueCoding.NullValue objects in the array are skipped. If array is null or empty, an empty array is returned.

Parameters:
array - array to search
valueToLookFor - value to look for
keyPath - key path to apply on each object on the array to compare against valueToLookFor
Returns:
an array of matching objects

indexOfObjectUsingEqualator

public static <T> int indexOfObjectUsingEqualator(NSArray<T> array,
                                                  T object,
                                                  ERXEqualator equalator)
Locates an object within an array using a custom equality check provided as an ERXEqualator. This is useful if you have an array of EOs and want to find a particular EO in it without regard to editing contexts.

Parameters:
array - the array to search.
object - the object to look for.
equalator - the equalator to use for performing the equality check between object and each object in the array.
Returns:
index of first occuring object in the array that is defined as equal by the equalator. -1 if no such object is found.

sortedMutableArraySortedWithKey

public static <T> NSMutableArray<T> sortedMutableArraySortedWithKey(NSArray<T> array,
                                                                    String key)
Sorts a given array with a key in ascending fashion and returns a mutable clone of the result.

Parameters:
array - array to be sorted.
key - sort key.
Returns:
mutable clone of sorted array.

sortedArraySortedWithKey

public static <T> NSArray<T> sortedArraySortedWithKey(NSArray<T> array,
                                                      String key)
Sorts a given array with a key in ascending fashion.

Parameters:
array - array to be sorted.
key - sort key.
Returns:
mutable clone of sorted array.

sortedArraySortedWithKey

public static <T> NSArray<T> sortedArraySortedWithKey(NSArray<T> array,
                                                      String key,
                                                      NSSelector selector)
Sorts a given array with a key in ascending fashion.

Parameters:
array - array to be sorted.
key - sort key.
selector - sort order selector to use, if null, then sort will be case insensitive ascending.
Returns:
sorted array.

sortedArraySortedWithKeys

public static <T> NSArray<T> sortedArraySortedWithKeys(NSArray<T> array,
                                                       NSArray<String> keys,
                                                       NSSelector selector)
Sorts a given array with a set of keys according to the given selector.

Parameters:
array - array to be sorted.
keys - sort keys
selector - sort order selector to use, if null, then sort will be case insensitive ascending.
Returns:
sorted array.

sortArrayWithKey

public static void sortArrayWithKey(NSMutableArray<?> array,
                                    String key)
Sorts a given mutable array with a key in place.

Parameters:
array - array to be sorted.
key - sort key.

sortArrayWithKey

public static void sortArrayWithKey(NSMutableArray<?> array,
                                    String key,
                                    NSSelector selector)
Sorts a given mutable array with a key in place.

Parameters:
array - array to be sorted.
key - sort key.
selector - sort order selector to use, if null, then sort will be ascending.

initialize

public static void initialize()
Will register new NSArray operators sort, sortAsc, sortDesc, sortInsensitiveAsc, sortInsensitiveDesc, unique, flatten, reverse, limit, and fetchSpec


median

public static Number median(NSArray<?> array,
                            String keypath)
Calculates the median value of an array. The median is the value for which half of the elements are above and half the elements are below. As such, an array sort is needed and this might be very costly depending of the size of the array.

Parameters:
array - array of objects
keypath - key path for the median
Returns:
the median value

stdDev

public static Number stdDev(NSArray<?> array,
                            String keypath,
                            boolean isPopulation)
Finds the standard deviation of the numeric values found in the array at the specified keypath. If the keypath is null or empty, then the array values are used instead. If the array has fewer than two objects, null is returned. If isPopulation is true, the population standard deviation is calculated. If isPopulation is false, the sample standard deviation is calculated. Use a true value for isPopulation if you know the values for an entire population and false if you are dealing with a sample.

Parameters:
array - an array of objects
keypath - a key path to a numeric value on each object
isPopulation -
Returns:
the standard deviation for the numeric values

distinct

public static <T> NSArray<T> distinct(NSArray<T> array)
Shorter name for arrayWithoutDuplicates, which I always forget the name of.

Type Parameters:
T - type of the array
Parameters:
array - the array to return distinct values from
Returns:
an array of distinct elements from the input array

arrayWithoutDuplicates

public static <T> NSArray<T> arrayWithoutDuplicates(NSArray<T> anArray)
Filters out all of the duplicate objects in a given array.
Preserves the order now.

Parameters:
anArray - to be filtered
Returns:
filtered array.

batchedArrayWithSize

public static <T> NSArray<NSArray<T>> batchedArrayWithSize(NSArray<T> array,
                                                           int batchSize)
Batches an NSArray into sub-arrays of the given size.

Parameters:
array - array to batch
batchSize - number of items in each batch
Returns:
NSArray of NSArrays, each with at most batchSize items

filteredArrayWithEntityFetchSpecification

public static <T> NSArray<T> filteredArrayWithEntityFetchSpecification(NSArray<T> array,
                                                                       String entity,
                                                                       String fetchSpec,
                                                                       NSDictionary<String,?> bindings)
Filters a given array with a named fetch specification and bindings.

Parameters:
array - array to be filtered.
fetchSpec - name of the EOQualifierEvaluation.
entity - name of the EOEntity to which the fetch specification is associated.
bindings - bindings dictionary for qualifier variable substitution.
Returns:
array filtered and sorted by the named fetch specification.

filteredArrayWithFetchSpecificationNamedEntityNamedBindings

@Deprecated
public static <T> NSArray<T> filteredArrayWithFetchSpecificationNamedEntityNamedBindings(NSArray<T> array,
                                                                                                    String fetchSpec,
                                                                                                    String entity,
                                                                                                    NSDictionary<String,?> bindings)
Deprecated. use filteredArrayWithEntityFetchSpecification(NSArray, String, String, NSDictionary)


filteredArrayWithFetchSpecificationNamedEntityNamed

@Deprecated
public static <T> NSArray<T> filteredArrayWithFetchSpecificationNamedEntityNamed(NSArray<T> array,
                                                                                            String fetchSpec,
                                                                                            String entity)
Deprecated. use filteredArrayWithEntityFetchSpecification(NSArray, String, String, NSDictionary)


filteredArrayWithEntityFetchSpecification

public static <T> NSArray<T> filteredArrayWithEntityFetchSpecification(NSArray<T> array,
                                                                       String entity,
                                                                       String fetchSpec)
Filters a given array with a named fetch specification.

Parameters:
array - array to be filtered.
fetchSpec - name of the EOQualifierEvaluation.
entity - name of the EOEntity to which the fetch specification is associated.
Returns:
array filtered and sorted by the named fetch specification.

shiftObjectLeft

public static <T> void shiftObjectLeft(NSMutableArray<T> array,
                                       T object)
shifts a given object in an array one value to the left (index--).

Parameters:
array - array to be modified.
object - the object that should be moved

shiftObjectRight

public static <T> void shiftObjectRight(NSMutableArray<T> array,
                                        T object)
shifts a given object in an array one value to the right (index++).

Parameters:
array - array to be modified.
object - the object that should be moved

arrayContainsAnyObjectFromArray

public static <T> boolean arrayContainsAnyObjectFromArray(NSArray<? extends T> array,
                                                          NSArray<? extends T> objects)
Function to determine if an array contains any of the elements of another array.

Parameters:
array - to test if it contains any of the objects
objects - array of objects to test if the first array contains any of
Returns:
if the first array contains any elements from the second array

arrayContainsArray

public static <T> boolean arrayContainsArray(NSArray<? extends T> array,
                                             NSArray<? extends T> objects)
Function to determine if an array contains all of the elements of another array.

Parameters:
array - to test if it contains all of the objects of another array
objects - array of objects to test if the first array contains all of
Returns:
if the first array contains all of the elements from the second array

intersectingElements

public static <T> NSArray<T> intersectingElements(NSArray<? extends T> array1,
                                                  NSArray<? extends T> array2)
Intersects the elements of two arrays. This has the effect of stripping out duplicates.

Parameters:
array1 - the first array
array2 - the second array
Returns:
the intersecting elements

reverse

public static <T> NSArray<T> reverse(NSArray<T> array)
Reverses the elements of an array

Parameters:
array - to be reversed
Returns:
reverse ordered array

friendlyDisplayForKeyPath

public static String friendlyDisplayForKeyPath(NSArray<?> list,
                                               String attribute,
                                               String nullArrayDisplay,
                                               String separator,
                                               String finalSeparator)
Displays a list of attributes off of objects in a 'friendly' manner.

For example, given an array containing three user objects and the attribute key "firstName", the result of calling this method would be the string: "Max, Anjo and Patrice".

Parameters:
list - of objects to be displayed in a friendly manner
attribute - key to be called on each object in the list
nullArrayDisplay - string to be returned if the list is null or empty
separator - string to be used for the first items
finalSeparator - used between the last items
Returns:
friendly display string

arrayForKeysPath

public static NSArray<?> arrayForKeysPath(NSArray<?> array,
                                          NSArray<String> keys)
Returns an array of dictionaries containing the key/value pairs for the given paths.

Parameters:
array - array of objects
keys - array of keys
Returns:
array of dictionaries containing values for the key paths

removeNullValues

public static <T> NSArray<T> removeNullValues(NSArray<T> array)
Removes all occurrences of NSKeyValueCoding.NullValue in the provided array

Parameters:
array - the array from which the NullValue should be removed
Returns:
a new NSArray with the same order than the original array but without NSKeyValueCoding.NullValue objects

removeNullValues

public static <T> NSArray<T> removeNullValues(NSArray<T> target,
                                              NSArray<T> array)
Removes all occurrences of NSKeyValueCoding.NullValue in the provided array

Parameters:
target - array to remove objects from
array - array of values
Returns:
a new NSArray with the same order than the original array but without NSKeyValueCoding.NullValue objects

objectArrayCastToStringArray

public static String[] objectArrayCastToStringArray(Object[] o)
Converts an Object array to a String array by casting each element. This is analogous to String[] myStringArray = (String[])myObjectArray; except that it creates a clone of the array.

Parameters:
o - an Object array containing String elements
Returns:
a String array containing the same elements

objectArrayToString

public static String objectArrayToString(Object[] o)
pretty prints an Object array which is ugly when using toString

Parameters:
o - the object which one wants to print as a String
Returns:
the String which can be used in lets say log.info("my array = "+ERXArrayUtilities.objectArrayToString(myArray));

objectArrayToString

public static String objectArrayToString(Object[][] array)
pretty prints a two dimensional Object array which is ugly when using toString

Parameters:
array - the object which one wants to print as a String
Returns:
the String which can be used in lets say log.info("my array = "+ERXArrayUtilities.objectArrayToString(myArray));

objectArraysToString

public static String objectArraysToString(NSArray<Object[][]> array)
pretty prints a NSArray of two dimensional Object array which is ugly when using toString

Parameters:
array - the object which one wants to print as a String
Returns:
the String which can be used in lets say log.info("my array = "+ERXArrayUtilities.objectArrayToString(myArray));

removeNullValuesFromEnd

public static <T> NSArray<T> removeNullValuesFromEnd(NSArray<T> array)
removes all occurencies of NSKeyValueCoding.Null from the end of the array

Parameters:
array - the array from which the values should be removed
Returns:
a new NSArray which does not have NSKeyValueCoding.Null instances at the end

toStringArray

public static String[] toStringArray(NSArray<?> a)

dictionaryOfObjectsIndexedByKeyPath

public static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array,
                                                                          String keyPath)
Calls dictionaryOfObjectsIndexedByKeyPathThrowOnCollision() passing false for throwOnCollision.

Parameters:
array - array to index
keyPath - keyPath to index. If any object returns null or NSKeyValueCoding.NullValue for this keyPath, the object is not put into the resulting dictionary.
Returns:
a dictionary indexing the given array. If array is null, an empty dictionary is returned.
See Also:
dictionaryOfObjectsIndexedByKeyPathThrowOnCollision(NSArray, String, boolean)

dictionaryOfObjectsIndexedByKeyPathThrowOnCollision

public static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPathThrowOnCollision(NSArray<T> array,
                                                                                          String keyPath,
                                                                                          boolean throwOnCollision)
Given an array of objects, returns a dictionary mapping the value by performing valueForKeyPath on each object in the array to the object in the array. This is similar in concept to but different in semantic from arrayGroupedByKeyPath(). That method is focused on multiple objects returning the same value for the keypath and, so, objects are grouped into arrays. That is not particularly useful when there aren't collisions in the array or when you don't care if there are collisions. For example, with a CreditCard EO object, one could rely on the paymentType.name value to be unique and thus you're more interested in being able to rapidly get to the EO. arrayGroupedByKeyPath() would require either flattening out the arrays or navigating to them every time.

Parameters:
array - array to index
keyPath - keyPath to index. If any object returns null or NSKeyValueCoding.NullValue for this keyPath, the object is not put into the resulting dictionary.
throwOnCollision - if true and two objects in the array have the same non-null (or non-NullValue) value for keyPath, an exception is thrown. If false, the last object in the array wins.
Returns:
a dictionary indexing the given array. If array is null, an empty dictionary is returned.

arrayBySelectingInstancesOfClass

public static <T> NSArray<T> arrayBySelectingInstancesOfClass(NSArray<?> array,
                                                              Class<T> aClass)
Prunes an array for only instances of the given class.

Parameters:
array - array to process
aClass - class to use. null results in the result being a copy of the array.
Returns:
an array which is a subset of the array where each object in the result is an instance of aClass.

sortedArrayUsingComparator

public static <T> NSArray<T> sortedArrayUsingComparator(NSArray<T> array,
                                                        NSComparator comparator)
Just like the method NSArray#sortedArrayUsingComparator(NSComparator), except it catches the NSComparator.ComparisonException and, if thrown, it wraps it in a runtime exception. Returns null when passed null for array.

Type Parameters:
T -
Parameters:
array -
comparator -
Returns:
the sorted array

arrayWithObjectsSwapped

public static <T> NSArray<T> arrayWithObjectsSwapped(NSArray<T> array,
                                                     Object object1,
                                                     Object object2)
Swaps the two given Objects in the given NSArray and returns a new NSArray. If one of the Objects is not element of the NSArray a RuntimeException will be thrown.

Type Parameters:
T -
Parameters:
array - in that the two given Objects have to be swapped
object1 - one object in the NSArray that will be swapped
object2 - the other object in the NSArray that will be swapped
Returns:
the new NSArray with the swapped elements
Throws:
{@link - RuntimeException} if one of the Objects is not in the NSArray
Author:
edgar - Jan 7, 2008

arrayWithObjectsAtIndexesSwapped

public static <T> NSArray<T> arrayWithObjectsAtIndexesSwapped(NSArray<T> array,
                                                              int indexOfObject1,
                                                              int indexOfObject2)
Swaps the two objects at the given indexes in the given NSArray and returns a new NSArray.

Parameters:
array - in that the two Objects at the given indexes have to be swapped
indexOfObject1 - index of one object in the NSArray that will be swapped
indexOfObject2 - index of the other object in the NSArray that will be swapped
Returns:
the new NSArray with the swapped elements
Throws:
{@link - RuntimeException} if one of the indexes is out of bound
Author:
edgar - Jan 7, 2008

swapObjectsInArray

public static <T> void swapObjectsInArray(NSMutableArray<T> array,
                                          T a,
                                          T b)
Swaps two objects a and b in an array inplace

Parameters:
array - the array
a - - first object
b - - second object
Throws:
{@link - RuntimeException} if one or both indexes are out of bounds
Author:
cug - Jan 7, 2008

swapObjectsAtIndexesInArray

public static <T> void swapObjectsAtIndexesInArray(NSMutableArray<T> array,
                                                   int indexOfA,
                                                   int indexOfB)
Swaps two objects at the given indexes in an array inplace

Parameters:
array - the array
indexOfA - - index of the first object
indexOfB - - index of the second object
Throws:
{@link - RuntimeException} if one or both indexes are out of bounds
Author:
cug - Jan 7, 2008

swapObjectWithObjectAtIndexInArray

public static <T> void swapObjectWithObjectAtIndexInArray(NSMutableArray<T> array,
                                                          T a,
                                                          int indexOfB)
Swaps the object a with the object at the given index

Parameters:
array - the array
a - - first object
indexOfB - - index of second object
Author:
edgar - Apr 14, 2008

deepClone

public static <T> NSArray<T> deepClone(NSArray<T> array,
                                       boolean onlyCollections)
Returns a deep clone of the given array. A deep clone will attempt to clone the values of this array as well as the array itself.

Parameters:
array - the array to clone
onlyCollections - if true, only collections in this array will be cloned, not individual values
Returns:
a deep clone of array

deepClone

public static <T> NSSet<T> deepClone(NSSet<T> set,
                                     boolean onlyCollections)
Returns a deep clone of the given set. A deep clone will attempt to clone the values of this set as well as the set itself.

Parameters:
set - the set to clone
onlyCollections - if true, only collections in this array will be cloned, not individual values
Returns:
a deep clone of set

arrayIsNullOrEmpty

public static boolean arrayIsNullOrEmpty(NSArray<?> aNSArray)
Check if an NSArray is null or Empty

Parameters:
aNSArray - - NSArray
aNSArray - - NSArray
Returns:
if an NSArray is null or Empty true returns 配列が null か空かをチェックします

arrayToLogstring

public static String arrayToLogstring(NSArray<String> aNSArray)
To create oneLine Log for an NSArray<String>

Parameters:
aNSArray - - NSArray
aNSArray - - 文字列配列
Returns:
change a NSArray to String NSArray 配列をログとして出力する時に複数行に渡らないで、一行で収まるように

Last updated: Tue, Oct 23, 2012 • 10:01 PM EDT

Copyright © 2002 – 2012 Project Wonder.