Project Wonder 5.0.0.8795

er.extensions.foundation
Class ERXDictionaryUtilities

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

public class ERXDictionaryUtilities
extends Object

Collection of NSDictionary utilities.


Nested Class Summary
static class ERXDictionaryUtilities.NSDictionaryKeyValueComparator
          Compares dictionary keys based on the value they are associated with.
 
Constructor Summary
ERXDictionaryUtilities()
           
 
Method Summary
static void _removeMatchingEntries(NSMutableDictionary snapshot1, NSMutableDictionary snapshot2, boolean removeInverse)
           
static NSDictionary deepClone(NSDictionary dict, boolean onlyCollections)
           
static NSDictionary dictionaryByRemovingFromDictionaryKeysInArray(NSDictionary d, NSArray a)
          Removes an array of keys from a dictionary and returns the result.
static NSDictionary dictionaryByRemovingKeysNotInArray(NSDictionary d, NSArray a)
          Creates a new dictionary with only the keys and objects in the array.
static NSDictionary dictionaryFromObjectWithKeys(Object object, NSArray keys)
          Creates a dictionary from an objects and an array 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 NSDictionary dictionaryWithDictionaryAndDictionary(NSDictionary dict1, NSDictionary 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 NSArray keysSortedByValueAscending(NSDictionary d)
           
static String queryStringForDictionary(NSDictionary<Object,Object> dict, String separator)
          Encodes a dictionary into a string that can be used in a request uri.
static String queryStringForDictionary(NSDictionary<Object,Object> dict, String separator, String encoding)
          Encodes a dictionary into a string that can be used in a request uri.
static void removeMatchingEntries(NSMutableDictionary dict1, NSMutableDictionary dict2)
          Removes entries from both dictionaries that match, leaving you with two dictionaries containing only values that did NOT match.
static NSDictionary removeNullValues(NSDictionary dict)
           
static void setObjectForKeys(NSMutableDictionary dictionary, Object object, NSArray keys)
          Sets the object for each of the keys in the array on a mutable dictionary.
static NSArray<String> stringKeysSortedAscending(NSDictionary<String,Object> d)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ERXDictionaryUtilities

public ERXDictionaryUtilities()
Method Detail

dictionaryWithDictionaryAndDictionary

public static NSDictionary dictionaryWithDictionaryAndDictionary(NSDictionary dict1,
                                                                 NSDictionary dict2)
Creates an immutable dictionary containing all of the keys and objects from two dictionaries.

Parameters:
dict1 - the first dictionary
dict2 - the second dictionary
Returns:
immutbale dictionary containing the union of the two dictionaries.

dictionaryFromPropertyList

public static NSDictionary dictionaryFromPropertyList(String name,
                                                      NSBundle bundle)
Creates an NSDictionary 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:
NSDictionary de-serialized from the property list.

dictionaryWithObjectsAndKeys

public static NSDictionary dictionaryWithObjectsAndKeys(Object[] objectsAndKeys)
Creates a dictionary from a list of alternating objects and keys starting with an object.

Parameters:
objectsAndKeys - alternating list of objects and keys
Returns:
NSDictionary containing all of the object-key pairs.

dictionaryByRemovingFromDictionaryKeysInArray

public static NSDictionary dictionaryByRemovingFromDictionaryKeysInArray(NSDictionary d,
                                                                         NSArray a)
Removes an array of keys from a dictionary and returns the result.

Parameters:
d - dictionary to be pruned
a - array of keys to be pruned
Returns:
pruned dictionary

dictionaryByRemovingKeysNotInArray

public static NSDictionary dictionaryByRemovingKeysNotInArray(NSDictionary d,
                                                              NSArray a)
Creates a new dictionary with only the keys and objects in the array. The result is the objects for the intersection of keys in the dictionary and the array. This is the opposite of dictionaryByRemovingFromDictionaryKeysInArray.

Parameters:
d - dictionary to be pruned
a - array of keys to be included
Returns:
pruned dictionary

removeNullValues

public static NSDictionary removeNullValues(NSDictionary dict)

dictionaryFromObjectWithKeys

public static NSDictionary dictionaryFromObjectWithKeys(Object object,
                                                        NSArray keys)
Creates a dictionary from an objects and an array of key paths

Parameters:
object - object to pull the values from
keys - array of keys
Returns:
NSDictionary containing all of the object-key pairs.

stringKeysSortedAscending

public static NSArray<String> stringKeysSortedAscending(NSDictionary<String,Object> d)

keysSortedByValueAscending

public static NSArray keysSortedByValueAscending(NSDictionary d)
Parameters:
d - dictionary to sort keys from
Returns:
keys from d sorted by ascending value they are mapped to

removeMatchingEntries

public static void removeMatchingEntries(NSMutableDictionary dict1,
                                         NSMutableDictionary dict2)
Removes entries from both dictionaries that match, leaving you with two dictionaries containing only values that did NOT match. Note that this comparison considers null == EO/NSKeyValueCoding.NullValue.

Parameters:
dict1 - the first dictionary
dict2 - the second dictionary

_removeMatchingEntries

public static void _removeMatchingEntries(NSMutableDictionary snapshot1,
                                          NSMutableDictionary snapshot2,
                                          boolean removeInverse)

setObjectForKeys

public static void setObjectForKeys(NSMutableDictionary dictionary,
                                    Object object,
                                    NSArray keys)
Sets the object for each of the keys in the array on a mutable dictionary.

Parameters:
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.

deepClone

public static NSDictionary deepClone(NSDictionary dict,
                                     boolean onlyCollections)

queryStringForDictionary

public static String queryStringForDictionary(NSDictionary<Object,Object> dict,
                                              String separator)
Encodes a dictionary into a string that can be used in a request uri.

Parameters:
dict - dictionary with form values
separator - optional value separator

queryStringForDictionary

public static String queryStringForDictionary(NSDictionary<Object,Object> dict,
                                              String separator,
                                              String encoding)
Encodes a dictionary into a string that can be used in a request uri.

Parameters:
dict - dictionary with form values
separator - optional value separator

Last updated: Fri, Jan 9, 2009 • 04:35 AM EST

Copyright © 2002 – 2007 Project Wonder.