public class ERXDictionaryUtilities extends Object
NSDictionary
utilities.Modifier and Type | Class and Description |
---|---|
static class |
ERXDictionaryUtilities.NSDictionaryKeyValueComparator
Compares dictionary keys based on the value they are associated with.
|
Constructor and Description |
---|
ERXDictionaryUtilities() |
Modifier and Type | Method and Description |
---|---|
static <K,V> void |
_removeMatchingEntries(NSMutableDictionary<? extends K,? extends V> snapshot1,
NSMutableDictionary<? extends K,? extends V> snapshot2,
boolean removeInverse) |
static <K,V> NSDictionary<K,V> |
deepClone(NSDictionary<K,V> dict,
boolean onlyCollections)
Returns a deep clone of the given dictionary.
|
static <K,V> NSDictionary<K,V> |
dictionaryByRemovingFromDictionaryKeysInArray(NSDictionary<K,V> d,
NSArray<K> a)
Removes an array of keys from a dictionary and
returns the result.
|
static <K,V> NSDictionary<K,V> |
dictionaryByRemovingKeysNotInArray(NSDictionary<K,V> d,
NSArray<K> a)
Creates a new dictionary with only the keys and objects in the array.
|
static NSMutableDictionary<String,Object> |
dictionaryFromObjectWithKeyMappings(Object object,
NSDictionary<String,ERXKey<?>> keyMappings)
Creates a dictionary from an object according to the given key mappings, skipping null values.
|
static NSDictionary<String,Object> |
dictionaryFromObjectWithKeys(Object object,
ERXKey... keys)
Creates a dictionary from an objects and an array of key paths
|
static NSDictionary<String,Object> |
dictionaryFromObjectWithKeys(Object object,
NSArray<String> keys)
Creates a dictionary from an objects and an array of key paths
|
static NSDictionary<String,Object> |
dictionaryFromObjectWithKeys(Object object,
String... keys)
Creates a dictionary from an object and a list of key paths
|
static NSDictionary |
dictionaryFromPropertyList(String name,
NSBundle bundle)
Creates an NSDictionary from a resource associated with a given bundle
that is in property list format.
|
static <K,V> NSDictionary<K,V> |
dictionaryWithDictionaryAndDictionary(NSDictionary<? extends K,? extends V> dict1,
NSDictionary<? extends K,? extends V> dict2)
Creates an immutable dictionary containing all of the keys and
objects from two dictionaries.
|
static NSDictionary |
dictionaryWithObjectsAndKeys(Object[] objectsAndKeys)
Creates a dictionary from a list of alternating objects and keys
starting with an object.
|
static <T> NSArray<T> |
keysSortedByValueAscending(NSDictionary<T,?> d) |
static String |
queryStringForDictionary(NSDictionary<?,?> dict,
String separator)
Encodes a dictionary into a string that can be used in a request uri.
|
static String |
queryStringForDictionary(NSDictionary<?,?> dict,
String separator,
String encoding)
Encodes a dictionary into a string that can be used in a request uri.
|
static <K,V> void |
removeMatchingEntries(NSMutableDictionary<? extends K,? extends V> dict1,
NSMutableDictionary<? extends K,? extends V> dict2)
Removes entries from both dictionaries that match, leaving you with two dictionaries containing
only values that did NOT match.
|
static <K,V> NSDictionary<K,V> |
removeNullValues(NSDictionary<K,V> dict) |
static <K,V> void |
setObjectForKeys(NSMutableDictionary<K,V> dictionary,
V object,
NSArray<K> keys)
Sets the object for each of the keys in the array on a mutable dictionary.
|
static NSArray<String> |
stringKeysSortedAscending(NSDictionary<String,?> d) |
public static <K,V> NSDictionary<K,V> dictionaryWithDictionaryAndDictionary(NSDictionary<? extends K,? extends V> dict1, NSDictionary<? extends K,? extends V> dict2)
dict1
- the first dictionarydict2
- the second dictionarypublic static NSDictionary dictionaryFromPropertyList(String name, NSBundle bundle)
name
- name of the file or resource.bundle
- NSBundle to which the resource belongs.public static NSDictionary dictionaryWithObjectsAndKeys(Object[] objectsAndKeys)
objectsAndKeys
- alternating list of objects and keyspublic static <K,V> NSDictionary<K,V> dictionaryByRemovingFromDictionaryKeysInArray(NSDictionary<K,V> d, NSArray<K> a)
d
- dictionary to be pruneda
- array of keys to be prunedpublic static <K,V> NSDictionary<K,V> dictionaryByRemovingKeysNotInArray(NSDictionary<K,V> d, NSArray<K> a)
d
- dictionary to be pruneda
- array of keys to be includedpublic static <K,V> NSDictionary<K,V> removeNullValues(NSDictionary<K,V> dict)
public static NSDictionary<String,Object> dictionaryFromObjectWithKeys(Object object, NSArray<String> keys)
object
- object to pull the values fromkeys
- array of keyspublic static NSDictionary<String,Object> dictionaryFromObjectWithKeys(Object object, String... keys)
object
- object to pull the values fromkeys
- list of keysNSDictionary
containing all of the object-key pairs.public static NSDictionary<String,Object> dictionaryFromObjectWithKeys(Object object, ERXKey... keys)
object
- object to pull the values fromkeys
- list of keysNSDictionary
containing all of the object-key pairs.public static NSMutableDictionary<String,Object> dictionaryFromObjectWithKeyMappings(Object object, NSDictionary<String,ERXKey<?>> keyMappings)
Usage:
NSDictionary<String, Object> data = dictionaryFromObjectWithKeyMappings(eo, NSDictionary.of("key1", EO.ATTRIBUTE1, "key2", EO.ATTRIBUTE2);Result:
{"key1" = "valueForAttribute1"; "key2" = "valueForAttribute2"}
object
- object to pull the values fromkeyMappings
- keypath mapping for keysNSDictionary
containing all of the object-key pairs.public static NSArray<String> stringKeysSortedAscending(NSDictionary<String,?> d)
public static <T> NSArray<T> keysSortedByValueAscending(NSDictionary<T,?> d)
d
- dictionary to sort keys frompublic static <K,V> void removeMatchingEntries(NSMutableDictionary<? extends K,? extends V> dict1, NSMutableDictionary<? extends K,? extends V> dict2)
dict1
- the first dictionarydict2
- the second dictionarypublic static <K,V> void _removeMatchingEntries(NSMutableDictionary<? extends K,? extends V> snapshot1, NSMutableDictionary<? extends K,? extends V> snapshot2, boolean removeInverse)
public static <K,V> void setObjectForKeys(NSMutableDictionary<K,V> dictionary, V object, NSArray<K> keys)
dictionary
- dictionary to mutate. a null dictionary is a no-op.object
- object to set. an exception will be thrown if object is null.keys
- array of keys to invoke setObjectForKey()
for each key. a null
or empty array is a no-op.public static <K,V> NSDictionary<K,V> deepClone(NSDictionary<K,V> dict, boolean onlyCollections)
dict
- the dictionary to cloneonlyCollections
- if true, only collections in this dictionary will be cloned, not individual valuespublic static String queryStringForDictionary(NSDictionary<?,?> dict, String separator)
dict
- dictionary with form valuesseparator
- optional value separatorpublic static String queryStringForDictionary(NSDictionary<?,?> dict, String separator, String encoding)
dict
- dictionary with form valuesseparator
- optional value separatorCopyright © 2002 – 2024 Project Wonder.