Modifier and Type | Class and Description |
---|---|
static class |
ERXArrayUtilities.AvgNonNullOperator
Define an
NSArray.Operator
for the key avgNonNull. |
static class |
ERXArrayUtilities.FetchSpecOperator
Define an
NSArray.Operator
for the key fetchSpec. |
static class |
ERXArrayUtilities.FlattenOperator
Define an
NSArray.Operator
for the key flatten. |
static class |
ERXArrayUtilities.IsEmptyOperator
Define an
NSArray.Operator
for the key isEmpty. |
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. |
static class |
ERXArrayUtilities.ObjectAtIndexOperator
Define an
NSArray.Operator for the key objectAtIndex. |
static class |
ERXArrayUtilities.RemoveNullValuesOperator
Define an
NSArray.Operator
for the key removeNullValues. |
static class |
ERXArrayUtilities.ReverseOperator
Define an
NSArray.Operator
for the key reverse. |
static class |
ERXArrayUtilities.SortOperator
Define an
NSArray.Operator
for the key sort. |
static class |
ERXArrayUtilities.StandardDeviationOperator
Define an
NSArray.Operator
for the key stdDev and popStdDev. |
static class |
ERXArrayUtilities.SubarrayWithRangeOperator
Define an
NSArray.Operator
for the key subarrayWithRange. |
static class |
ERXArrayUtilities.UniqueOperator
Define an
NSArray.Operator
for the key unique. |
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
ERXArrayUtilities() |
Modifier and Type | Method and Description |
---|---|
static <T> void |
addObjectsFromArrayWithoutDuplicates(NSMutableArray<T> array1,
Collection<? extends T> array2)
Adds all of the non-duplicate elements from the second
array to the mutable array.
|
static <T> NSArray<T> |
arrayByAddingObjectsFromArrayWithoutDuplicates(Collection<? extends T> array1,
Collection<? extends T> array2)
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(Collection<?> array,
Class<T> aClass)
Prunes an array for only instances of the given class.
|
static <T> boolean |
arrayContainsAnyObjectFromArray(Collection<? extends T> array1,
Collection<? extends T> array2)
Function to determine if an array contains any of
the elements of another array.
|
static <T> boolean |
arrayContainsArray(Collection<? extends T> array1,
Collection<? extends T> array2)
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(Collection<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(Collection<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(Collection<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 <T> NSDictionary |
arrayGroupedByKeyPath(Collection<T> 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 <K,V> NSDictionary<K,NSArray<V>> |
arrayGroupedByKeyPath(Collection<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(Collection<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 <T,K,V> NSDictionary<K,NSArray<V>> |
arrayGroupedByToManyKeyPath(Collection<T> objects,
ERXKey<K> keyPath,
K nullGroupingKey,
ERXKey<V> valueKeyPath)
Typesafe variant of arrayGroupedByToManyKeyPath.
|
static <T> NSDictionary |
arrayGroupedByToManyKeyPath(Collection<T> 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 <K,V> NSDictionary<K,NSArray<V>> |
arrayGroupedByToManyKeyPath(Collection<V> objects,
ERXKey<K> keyPath,
boolean includeNulls)
Typesafe variant of arrayGroupedByToManyKeyPath.
|
static <K,V> NSDictionary<K,NSArray<V>> |
arrayGroupedByToManyKeyPath(Collection<V> objects,
ERXKey<K> keyPath,
K nullGroupingKey)
Typesafe variant of arrayGroupedByToManyKeyPath.
|
static <K,V> NSDictionary<K,NSArray<V>> |
arrayGroupedByToManyKeyPath(Collection<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(Collection<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 boolean |
arrayIsNullOrEmpty(Collection<?> array)
Check if an array is null or empty.
|
static <T> NSArray<T> |
arrayMinusArray(Collection<T> array,
Collection<?> minus)
Subtracts the contents of one array from another.
|
static <T> NSArray<T> |
arrayMinusObject(Collection<T> array,
T object)
Subtracts a single object from an array.
|
static <T> boolean |
arraysAreIdenticalSets(Collection<? super T> array1,
Collection<? super T> array2)
Simple comparison method to see if two array
objects are identical sets.
|
static String |
arrayToLogstring(Collection<String> array)
To create oneLine Log for an NSArray<String>
NSArray 配列をログとして出力する時に複数行に渡らないで、一行で収まるように
|
static <T> NSArray<T> |
arrayWithObjectsAtIndexesSwapped(NSArray<T> array,
int indexOfObject1,
int indexOfObject2)
Deprecated.
use
swapObjects(NSArray, int, int) instead |
static <T> NSArray<T> |
arrayWithObjectsSwapped(NSArray<T> array,
Object object1,
Object object2)
Deprecated.
use
swapObjects(NSArray, Object, Object) instead |
static <T> NSArray<T> |
arrayWithoutDuplicateKeyValue(Iterable<T> objects,
ERXKey<?> keyPath)
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> |
arrayWithoutDuplicateKeyValue(Iterable<T> objects,
String keyPath)
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(Collection<T> array)
Filters out all of the duplicate objects in
a given array.
|
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)
Deprecated.
user
ERXSetUtilities.deepClone(NSSet, boolean) instead |
static <K,T> NSDictionary<K,T> |
dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array,
ERXKey<K> keyPath)
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 <K,T> NSDictionary<K,T> |
dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array,
ERXKey<K> 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 <K,T> NSDictionary<K,T> |
dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array,
String keyPath)
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 <K,T> NSDictionary<K,T> |
dictionaryOfObjectsIndexedByKeyPath(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 <K,T> NSDictionary<K,T> |
dictionaryOfObjectsIndexedByKeyPathThrowOnCollision(NSArray<T> array,
ERXKey<K> keyPath,
boolean throwOnCollision)
Deprecated.
|
static <K,T> NSDictionary<K,T> |
dictionaryOfObjectsIndexedByKeyPathThrowOnCollision(NSArray<T> array,
String keyPath,
boolean throwOnCollision)
Deprecated.
|
static <T> NSArray<T> |
distinct(Collection<T> array)
Shorter name for arrayWithoutDuplicates, which I always forget the name of.
|
static boolean |
enumerationHasMatchWithQualifierEvaluation(Enumeration<?> enumeration,
EOQualifierEvaluation qualifier)
Checks if the given enumeration contains at least one match defined by the given object
implementing 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> |
filteredArrayWithQualifierEvaluation(Enumeration<T> enumeration,
EOQualifierEvaluation qualifier)
Deprecated.
|
static <T> NSArray<T> |
filteredArrayWithQualifierEvaluation(Iterable<T> iterable,
EOQualifierEvaluation qualifier)
Filters any kinds of collections that implement
Iterable
interface such as NSArray or NSSet using the
EOQualifierEvaluation interface. |
static <T> NSArray<T> |
filteredArrayWithQualifierEvaluation(Iterator<T> iterator,
EOQualifierEvaluation qualifier)
Deprecated.
|
static <T> T |
firstObject(List<T> array)
Returns the first object of the array.
|
static <T> T |
firstObjectWithValueForKeyPath(List<T> array,
Object value,
String keyPath)
Finds the first object in the array with a given value for a given key path.
|
static <T,V> T |
firstObjectWithValueForKeyPath(List<T> array,
V value,
ERXKey<V> keyPath)
Finds the first object in the array with a given value for a given key path.
|
static NSArray |
flatten(NSArray<?> array)
Recursively flattens an array of arrays and individual
objects into a single array of elements.
|
static NSArray |
flatten(NSArray<?> array,
boolean filterDuplicates)
Recursively flattens an array of arrays and individual
objects into a single array of elements.
|
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 <T> int |
indexOfFirstObjectWithValueForKeyPath(Collection<T> array,
Object value,
String keyPath)
Finds the index of the first object in the array with a given value for a given key path.
|
static <T,V> int |
indexOfFirstObjectWithValueForKeyPath(Collection<T> array,
V value,
ERXKey<V> keyPath)
Finds the index of the first object in the array with a given value for a given key path.
|
static <T> int |
indexOfObjectUsingEqualator(Collection<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(Collection<? extends T> array1,
Collection<? extends T> array2)
Intersects the elements of two arrays.
|
static boolean |
iteratorHasMatchWithQualifierEvaluation(Iterator<?> iterator,
EOQualifierEvaluation qualifier)
Checks if the given iterator contains at least one match defined by the given object
implementing 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(Collection<T> array,
Object value,
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,V> NSArray<T> |
objectsWithValueForKeyPath(Collection<T> array,
V value,
ERXKey<V> 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 occurrences of NSKeyValueCoding.Null from the end of the array
|
static <T> NSArray<T> |
reverse(List<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)
Deprecated.
use
ERXSetUtilities.setFromArray(Collection) instead |
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> NSArray<T> |
swapObjects(NSArray<T> array,
int indexA,
int indexB)
Swaps two objects at the given indexes in an array and returns a new
modified array.
|
static <T> NSArray<T> |
swapObjects(NSArray<T> array,
T a,
int indexB)
Swaps the object a with the object at the given index in an array and returns
a new modified array.
|
static <T> NSArray<T> |
swapObjects(NSArray<T> array,
T a,
T b)
Swaps the objects in an array and returns a new modified array.
|
static <T> void |
swapObjects(NSMutableArray<T> array,
int indexA,
int indexB)
Swaps two objects at the given indexes in an array inplace.
|
static <T> void |
swapObjects(NSMutableArray<T> array,
T a,
int indexB)
Swaps the object a with the object at the given index in an array inplace.
|
static <T> void |
swapObjects(NSMutableArray<T> array,
T a,
T b)
Swaps the given objects in an array inplace.
|
static <T> void |
swapObjectsAtIndexesInArray(NSMutableArray<T> array,
int indexOfA,
int indexOfB)
Deprecated.
use
swapObjects(NSMutableArray, int, int) instead |
static <T> void |
swapObjectsInArray(NSMutableArray<T> array,
T a,
T b)
Deprecated.
use
swapObjects(NSMutableArray, Object, Object) instead |
static <T> void |
swapObjectWithObjectAtIndexInArray(NSMutableArray<T> array,
T a,
int indexOfB)
Deprecated.
use
swapObjects(NSMutableArray, Object, int) instead |
static String[] |
toStringArray(List<?> array) |
static NSArray |
valuesForKeyPaths(Object source,
Collection<String> keyPaths)
Performs multiple key-value coding calls against an array or an object.
|
public static final String NULL_GROUPING_KEY
@Deprecated public static <T> NSSet<T> setFromArray(NSArray<T> array)
ERXSetUtilities.setFromArray(Collection)
insteadarray
- of elementspublic static NSSelector sortSelectorWithKey(String key)
new NSSelector("compareAscending", ObjectClassArray)
This method eases the pain on creating those selectors from a string.key
- sort keynull
public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(Collection<V> objects, ERXKey<K> keyPath)
See arrayGroupedByKeyPath(NSArray<V> 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.
objects
- array of objects to be groupedkeyPath
- path into objects used to group the objectsNULL_GROUPING_KEY
public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(Collection<V> objects, String keyPath)
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.
objects
- array of objects to be groupedkeyPath
- path into objects used to group the objectsNULL_GROUPING_KEY
public static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(Collection<T> objects, ERXKey<K> keyPath, boolean includeNulls, ERXKey<V> valueKeyPath)
arrayGroupedByKeyPath(NSArray<T> objects, String keyPath, boolean includeNulls, String valueKeyPath).
See arrayGroupedByKeyPath(NSArray<T> objects, String keyPath, boolean includeNulls, String valueKeyPath)
for examples.
objects
- array of objects to be groupedkeyPath
- path into objects used to group the objectsincludeNulls
- determines if keyPaths that resolve to null
are included in the resulting dictionaryvalueKeyPath
- 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.NULL_GROUPING_KEY
public static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(Collection<T> objects, String keyPath, boolean includeNulls, String valueKeyPath)
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"); }
objects
- array of objects to be groupedkeyPath
- path into objects used to group the objectsincludeNulls
- determines if keyPaths that resolve to null
are included in the resulting dictionaryvalueKeyPath
- 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.NULL_GROUPING_KEY
public static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByKeyPath(Collection<T> objects, ERXKey<K> keyPath, K nullGroupingKey, ERXKey<V> valueKeyPath)
arrayGroupedByKeyPath(NSArray objects, String keyPath, Object nullGroupingKey, String valueKeyPath)
.
See arrayGroupedByKeyPath(NSArray objects, String keyPath, Object nullGroupingKey, String valueKeyPath)
for examples.
objects
- array of objects to be groupedkeyPath
- path into objects used to group the objectsnullGroupingKey
- 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.NULL_GROUPING_KEY
public static <T> NSDictionary arrayGroupedByKeyPath(Collection<T> objects, String keyPath, Object nullGroupingKey, String valueKeyPath)
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"); }
objects
- array of objects to be groupedkeyPath
- path into objects used to group the objectsnullGroupingKey
- 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.NULL_GROUPING_KEY
public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(Collection<V> objects, ERXKey<K> keyPath, boolean includeNulls)
objects
- the objects to be groupedkeyPath
- the key to group byincludeNulls
- determines if the key paths that resolve to null should be allowed in the grouppublic static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(Collection<V> objects, String keyPath, boolean includeNulls)
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.objects
- array of objects to be groupedkeyPath
- path used to group the objects.includeNulls
- determines if keyPaths that resolve to null
should be allowed into the group.public static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(Collection<V> objects, ERXKey<K> keyPath, K nullGroupingKey)
objects
- array of objects to be groupedkeyPath
- 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 thempublic static <K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(Collection<V> objects, String keyPath, K nullGroupingKey)
ERXGenericRecord
if interested.objects
- array of objects to be groupedkeyPath
- 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 thempublic static <T,K,V> NSDictionary<K,NSArray<V>> arrayGroupedByToManyKeyPath(Collection<T> objects, ERXKey<K> keyPath, K nullGroupingKey, ERXKey<V> valueKeyPath)
objects
- array of objects to be groupedkeyPath
- 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 themvalueKeyPath
- 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
resultpublic static <T> NSDictionary arrayGroupedByToManyKeyPath(Collection<T> objects, String keyPath, Object nullGroupingKey, String valueKeyPath)
ERXGenericRecord
if interested.objects
- array of objects to be groupedkeyPath
- 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 themvalueKeyPath
- 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
resultpublic static <T> boolean arraysAreIdenticalSets(Collection<? super T> array1, Collection<? super T> array2)
array1
- first arrayarray2
- second array@Deprecated public static <T> NSArray<T> filteredArrayWithQualifierEvaluation(Enumeration<T> enumeration, EOQualifierEvaluation qualifier)
filteredArrayWithQualifierEvaluation(Iterable, EOQualifierEvaluation)
insteadEnumeration
interface such as NSArray
, NSSet
, Vector
and Hashtable
using the EOQualifierEvaluation
interface.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 Hashtablequalifier
- to do the filteringpublic static <T> NSArray<T> filteredArrayWithQualifierEvaluation(Iterable<T> iterable, EOQualifierEvaluation qualifier)
Iterable
interface such as NSArray
or NSSet
using the
EOQualifierEvaluation
interface.T
- class of array itemsiterable
- to be filteredqualifier
- to do the filteringpublic static boolean enumerationHasMatchWithQualifierEvaluation(Enumeration<?> enumeration, EOQualifierEvaluation qualifier)
EOQualifierEvaluation
interface.enumeration
- to be testedqualifier
- to do the filteringpublic static boolean iteratorHasMatchWithQualifierEvaluation(Iterator<?> iterator, EOQualifierEvaluation qualifier)
EOQualifierEvaluation
interface.iterator
- to be testedqualifier
- to do the filtering@Deprecated public static <T> NSArray<T> filteredArrayWithQualifierEvaluation(Iterator<T> iterator, EOQualifierEvaluation qualifier)
filteredArrayWithQualifierEvaluation(Iterable, EOQualifierEvaluation)
insteadIterator
interface such as ArrayList
, HashMap
, SortedSet
and TreeSet
using the EOQualifierEvaluation
interface.iterator
- to be filtered; use iterator() to obtain
an iterator from the collectionsqualifier
- to do the filteringpublic static <T> NSArray<T> arrayWithoutDuplicateKeyValue(Iterable<T> objects, ERXKey<?> keyPath)
T
- class of array itemsobjects
- array of objectskeyPath
- key path to be evaluated off of every objectpublic static <T> NSArray<T> arrayWithoutDuplicateKeyValue(Iterable<T> objects, String keyPath)
T
- class of array itemsobjects
- array of objectskeyPath
- key path to be evaluated off of every objectpublic static <T> NSArray<T> arrayMinusArray(Collection<T> array, Collection<?> minus)
T
- class of array itemsarray
- array to have values removed from itminus
- array of values to remove from the main arraypublic static <T> NSArray<T> arrayMinusObject(Collection<T> array, T object)
T
- class of array itemsarray
- array to have value removed from itobject
- to be removedpublic static <T> NSArray<T> arrayByAddingObjectsFromArrayWithoutDuplicates(Collection<? extends T> array1, Collection<? extends T> array2)
T
- class of array itemsarray1
- first arrayarray2
- second arraypublic static <T> NSArray<T> arrayByRemovingFirstObject(NSArray<T> array)
T
- class of array itemsarray
- the array to use to create the resultpublic static <T> void safeAddObject(NSMutableArray<T> array, T object)
T
- class of array itemsarray
- mutable array where non-null object will be addedobject
- to be added to arraypublic static <T> void addObjectsFromArrayWithoutDuplicates(NSMutableArray<T> array1, Collection<? extends T> array2)
T
- class of array itemsarray1
- mutable array where non-duplicate objects are
addedarray2
- array to be added to a1public static NSArray flatten(NSArray<?> array, boolean filterDuplicates)
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)
array
- array to be flattenedfilterDuplicates
- determines if the duplicate values
should be filteredpublic static NSArray flatten(NSArray<?> array)
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)
array
- array to be flattenedpublic static NSArray arrayFromPropertyList(String name, NSBundle bundle)
name
- name of the file or resource.bundle
- NSBundle to which the resource belongs.public static NSArray valuesForKeyPaths(Object source, Collection<String> keyPaths)
source
- collection or object to be acted upon.keyPaths
- array of key paths.public static <T> T firstObject(List<T> array)
T
- class of array itemsarray
- the array to searchpublic static <T,V> int indexOfFirstObjectWithValueForKeyPath(Collection<T> array, V value, ERXKey<V> keyPath)
T
- class of array itemsV
- class of value from key patharray
- the array to searchvalue
- the value to look forkeyPath
- the key path to use to compare to valuepublic static <T> int indexOfFirstObjectWithValueForKeyPath(Collection<T> array, Object value, String keyPath)
T
- class of array itemsarray
- the array to searchvalue
- the value to look forkeyPath
- the key path to use to compare to valuepublic static <T,V> T firstObjectWithValueForKeyPath(List<T> array, V value, ERXKey<V> keyPath)
T
- class of array itemsV
- class of value from key patharray
- the array to searchvalue
- the value to look forkeyPath
- the key path to use to compare to valuepublic static <T> T firstObjectWithValueForKeyPath(List<T> array, Object value, String keyPath)
T
- class of array itemsarray
- the array to searchvalue
- the value to look forkeyPath
- the key path to use to compare to valuepublic static <T,V> NSArray<T> objectsWithValueForKeyPath(Collection<T> array, V value, ERXKey<V> keyPath)
T
- class of array itemsV
- class of value from key patharray
- array to searchvalue
- value to look forkeyPath
- key path to apply on each object on the array to compare against valueToLookForpublic static <T> NSArray<T> objectsWithValueForKeyPath(Collection<T> array, Object value, String keyPath)
T
- class of array itemsarray
- array to searchvalue
- value to look forkeyPath
- key path to apply on each object on the array to compare against valueToLookForpublic static <T> int indexOfObjectUsingEqualator(Collection<T> array, T object, ERXEqualator equalator)
T
- class of array itemsarray
- the array to searchobject
- the object to look forequalator
- the equalator to use for performing the equality check between object and each object
in the arraypublic static <T> NSMutableArray<T> sortedMutableArraySortedWithKey(NSArray<T> array, String key)
array
- array to be sorted.key
- sort key.public static <T> NSArray<T> sortedArraySortedWithKey(NSArray<T> array, String key)
array
- array to be sorted.key
- sort key.public static <T> NSArray<T> sortedArraySortedWithKey(NSArray<T> array, String key, NSSelector selector)
array
- array to be sorted.key
- sort key.selector
- sort order selector to use, if null, then sort will be case insensitive ascending.public static <T> NSArray<T> sortedArraySortedWithKeys(NSArray<T> array, NSArray<String> keys, NSSelector selector)
array
- array to be sorted.keys
- sort keysselector
- sort order selector to use, if null, then sort will be case insensitive ascending.
a.addObject(theObject);
a.addObject(theObject);public static void sortArrayWithKey(NSMutableArray<?> array, String key)
array
- array to be sorted.key
- sort key.public static void sortArrayWithKey(NSMutableArray<?> array, String key, NSSelector selector)
array
- array to be sorted.key
- sort key.selector
- sort order selector to use, if null, then sort will be ascending.public static void initialize()
public static Number median(NSArray<?> array, String keypath)
array
- array of objectskeypath
- key path for the medianpublic static Number stdDev(NSArray<?> array, String keypath, boolean isPopulation)
array
- an array of objectskeypath
- a key path to a numeric value on each objectisPopulation
- public static <T> NSArray<T> distinct(Collection<T> array)
T
- class of array itemsarray
- the array to return distinct values frompublic static <T> NSArray<T> arrayWithoutDuplicates(Collection<T> array)
T
- class of array itemsarray
- to be filteredpublic static <T> NSArray<NSArray<T>> batchedArrayWithSize(NSArray<T> array, int batchSize)
T
- class of array itemsarray
- array to batchbatchSize
- number of items in each batchpublic static <T> NSArray<T> filteredArrayWithEntityFetchSpecification(NSArray<T> array, String entity, String fetchSpec, NSDictionary<String,?> bindings)
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.public static <T> NSArray<T> filteredArrayWithEntityFetchSpecification(NSArray<T> array, String entity, String fetchSpec)
array
- array to be filtered.fetchSpec
- name of the EOQualifierEvaluation
.entity
- name of the EOEntity
to which the fetch specification is associated.public static <T> void shiftObjectLeft(NSMutableArray<T> array, T object)
T
- class of array itemsarray
- array to be modified.object
- the object that should be movedpublic static <T> void shiftObjectRight(NSMutableArray<T> array, T object)
T
- class of array itemsarray
- array to be modifiedobject
- the object that should be movedpublic static <T> boolean arrayContainsAnyObjectFromArray(Collection<? extends T> array1, Collection<? extends T> array2)
T
- class of array itemsarray1
- to test if it contains any of the objectsarray2
- array of objects to test if the first array
contains any ofpublic static <T> boolean arrayContainsArray(Collection<? extends T> array1, Collection<? extends T> array2)
T
- class of array itemsarray1
- to test if it contains all of the objects of another arrayarray2
- array of objects to test if the first array
contains all ofpublic static <T> NSArray<T> intersectingElements(Collection<? extends T> array1, Collection<? extends T> array2)
T
- class of array itemsarray1
- the first arrayarray2
- the second arraypublic static <T> NSArray<T> reverse(List<T> array)
T
- class of array itemsarray
- to be reversedpublic static String friendlyDisplayForKeyPath(NSArray<?> list, String attribute, String nullArrayDisplay, String separator, String finalSeparator)
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".
list
- of objects to be displayed in a friendly
mannerattribute
- key to be called on each object in
the listnullArrayDisplay
- string to be returned if the
list is null or emptyseparator
- string to be used for the first itemsfinalSeparator
- used between the last itemspublic static NSArray<?> arrayForKeysPath(NSArray<?> array, NSArray<String> keys)
array
- array of objectskeys
- array of keyspublic static <T> NSArray<T> removeNullValues(NSArray<T> array)
array
- the array from which the NullValue should be removedpublic static <T> NSArray<T> removeNullValues(NSArray<T> target, NSArray<T> array)
target
- array to remove objects fromarray
- array of valuespublic static String[] objectArrayCastToStringArray(Object[] o)
String[] myStringArray = (String[])myObjectArray;
except that it creates a clone of the array.o
- an Object array containing String elementspublic static String objectArrayToString(Object[] o)
o
- the object which one wants to print as a Stringlog.info("my array = "+ERXArrayUtilities.objectArrayToString(myArray));
public static String objectArrayToString(Object[][] array)
array
- the object which one wants to print as a Stringlog.info("my array = "+ERXArrayUtilities.objectArrayToString(myArray));
public static String objectArraysToString(NSArray<Object[][]> array)
array
- the object which one wants to print as a Stringlog.info("my array = "+ERXArrayUtilities.objectArrayToString(myArray));
public static <T> NSArray<T> removeNullValuesFromEnd(NSArray<T> array)
array
- the array from which the values should be removedpublic static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array, ERXKey<K> keyPath)
This is a typesafe variant of dictionaryOfObjectsIndexedByKeyPath(NSArray<V> objects, String keyPath).
Calls dictionaryOfObjectsIndexedByKeyPathThrowOnCollision()
passing false
for throwOnCollision.
K
- class of key path valueT
- class of array itemsarray
- array to indexkeyPath
- keyPath to index. If any object returns null
or NSKeyValueCoding.NullValue for this keyPath, the
object is not put into the resulting dictionary.null
, an empty dictionary is returned.public static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array, String keyPath)
Calls dictionaryOfObjectsIndexedByKeyPathThrowOnCollision()
passing false
for throwOnCollision.
K
- class of key path valueT
- class of array itemsarray
- array to indexkeyPath
- keyPath to index. If any object returns null
or NSKeyValueCoding.NullValue for this keyPath, the
object is not put into the resulting dictionary.null
, an empty dictionary is returned.@Deprecated public static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPathThrowOnCollision(NSArray<T> array, ERXKey<K> keyPath, boolean throwOnCollision)
dictionaryOfObjectsIndexedByKeyPath(NSArray, ERXKey, boolean)
insteadThis is a typesafe variant of dictionaryOfObjectsIndexedByKeyPath(NSArray<V> objects, String keyPath, boolean throwOnCollision).
array
- array to indexkeyPath
- 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.null
, an empty dictionary is returned.@Deprecated public static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPathThrowOnCollision(NSArray<T> array, String keyPath, boolean throwOnCollision)
dictionaryOfObjectsIndexedByKeyPath(NSArray, String, boolean)
insteadarray
- array to indexkeyPath
- 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.null
, an empty dictionary is returned.public static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array, ERXKey<K> keyPath, boolean throwOnCollision)
This is a typesafe variant of dictionaryOfObjectsIndexedByKeyPath(NSArray<V> objects, String keyPath, boolean throwOnCollision).
K
- class of key path valueT
- class of array itemsarray
- array to indexkeyPath
- 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.null
, an empty dictionary is returned.public static <K,T> NSDictionary<K,T> dictionaryOfObjectsIndexedByKeyPath(NSArray<T> array, String keyPath, boolean throwOnCollision)
K
- class of key path valueT
- class of array itemsarray
- array to indexkeyPath
- 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.null
, an empty dictionary is returned.public static <T> NSArray<T> arrayBySelectingInstancesOfClass(Collection<?> array, Class<T> aClass)
T
- class to extractarray
- array to processaClass
- class to use. null results in the result being a copy of the array
.array
where each object in the result is
an instance of aClass
.public static <T> NSArray<T> sortedArrayUsingComparator(NSArray<T> array, NSComparator comparator)
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.T
- class of array itemsarray
- the array to sortcomparator
- the comparator@Deprecated public static <T> NSArray<T> arrayWithObjectsSwapped(NSArray<T> array, Object object1, Object object2)
swapObjects(NSArray, Object, Object)
insteadObject
s in the given NSArray
and
returns a new NSArray
. If one of the Object
s is not
element of the NSArray
a RuntimeException
will be thrown.T
- array
- in that the two given Object
s have to be swappedobject1
- one object in the NSArray
that will be swappedobject2
- the other object in the NSArray
that will be swappedNSArray
with the swapped elementsRuntimeException
- if one of the Object
s is not in the NSArray
@Deprecated public static <T> NSArray<T> arrayWithObjectsAtIndexesSwapped(NSArray<T> array, int indexOfObject1, int indexOfObject2)
swapObjects(NSArray, int, int)
insteadarray
- in that the two Object
s at the given indexes have to be swappedindexOfObject1
- index of one object in the NSArray
that will be swappedindexOfObject2
- index of the other object in the NSArray
that will be swappedNSArray
with the swapped elementsRuntimeException
- if one of the indexes is out of bound@Deprecated public static <T> void swapObjectsInArray(NSMutableArray<T> array, T a, T b)
swapObjects(NSMutableArray, Object, Object)
insteadarray
- the arraya
- - first objectb
- - second objectRuntimeException
- if one or both indexes are out of bounds@Deprecated public static <T> void swapObjectsAtIndexesInArray(NSMutableArray<T> array, int indexOfA, int indexOfB)
swapObjects(NSMutableArray, int, int)
insteadarray
- the arrayindexOfA
- - index of the first objectindexOfB
- - index of the second objectRuntimeException
- if one or both indexes are out of bounds@Deprecated public static <T> void swapObjectWithObjectAtIndexInArray(NSMutableArray<T> array, T a, int indexOfB)
swapObjects(NSMutableArray, Object, int)
insteadarray
- the arraya
- - first objectindexOfB
- - index of second objectpublic static <T> void swapObjects(NSMutableArray<T> array, int indexA, int indexB)
T
- class of array elementsarray
- an arrayindexA
- index of the first objectindexB
- index of the second objectpublic static <T> void swapObjects(NSMutableArray<T> array, T a, int indexB)
T
- class of array elementsarray
- an arraya
- the first objectindexB
- index of the second objectpublic static <T> void swapObjects(NSMutableArray<T> array, T a, T b)
T
- class of array elementsarray
- an arraya
- the first objectb
- the second objectpublic static <T> NSArray<T> swapObjects(NSArray<T> array, int indexA, int indexB)
T
- class of array elementsarray
- an arrayindexA
- index of the first objectindexB
- index of the second objectpublic static <T> NSArray<T> swapObjects(NSArray<T> array, T a, int indexB)
T
- class of array elementsarray
- an arraya
- the first objectindexB
- index of the second objectpublic static <T> NSArray<T> swapObjects(NSArray<T> array, T a, T b)
T
- class of array elementsarray
- an arraya
- the first objectb
- the second objectpublic static <T> NSArray<T> deepClone(NSArray<T> array, boolean onlyCollections)
T
- class of array elementsarray
- the array to cloneonlyCollections
- if true, only collections in this array will be cloned, not individual values@Deprecated public static <T> NSSet<T> deepClone(NSSet<T> set, boolean onlyCollections)
ERXSetUtilities.deepClone(NSSet, boolean)
insteadset
- the set to cloneonlyCollections
- if true, only collections in this array will be cloned, not individual valuespublic static boolean arrayIsNullOrEmpty(Collection<?> array)
array
- true
が戻りますpublic static String arrayToLogstring(Collection<String> array)
array
- Copyright © 2002 – 2024 Project Wonder.