Project Wonder 5.0

er.extensions.foundation
Class ERXDictionaryUtilities

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

public class ERXDictionaryUtilities
extends java.lang.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
<K,V> void
_removeMatchingEntries(com.webobjects.foundation.NSMutableDictionary<? extends K,? extends V> snapshot1, com.webobjects.foundation.NSMutableDictionary<? extends K,? extends V> snapshot2, boolean removeInverse)
           
static
<K,V> com.webobjects.foundation.NSDictionary<K,V>
deepClone(com.webobjects.foundation.NSDictionary<K,V> dict, boolean onlyCollections)
          Returns a deep clone of the given dictionary.
static
<K,V> com.webobjects.foundation.NSDictionary<K,V>
dictionaryByRemovingFromDictionaryKeysInArray(com.webobjects.foundation.NSDictionary<K,V> d, com.webobjects.foundation.NSArray<K> a)
          Removes an array of keys from a dictionary and returns the result.
static
<K,V> com.webobjects.foundation.NSDictionary<K,V>
dictionaryByRemovingKeysNotInArray(com.webobjects.foundation.NSDictionary<K,V> d, com.webobjects.foundation.NSArray<K> a)
          Creates a new dictionary with only the keys and objects in the array.
static com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> dictionaryFromObjectWithKeys(java.lang.Object object, com.webobjects.foundation.NSArray<java.lang.String> keys)
          Creates a dictionary from an objects and an array of key paths
static com.webobjects.foundation.NSDictionary dictionaryFromPropertyList(java.lang.String name, com.webobjects.foundation.NSBundle bundle)
          Creates an NSDictionary from a resource associated with a given bundle that is in property list format.
static
<K,V> com.webobjects.foundation.NSDictionary<K,V>
dictionaryWithDictionaryAndDictionary(com.webobjects.foundation.NSDictionary<? extends K,? extends V> dict1, com.webobjects.foundation.NSDictionary<? extends K,? extends V> dict2)
          Creates an immutable dictionary containing all of the keys and objects from two dictionaries.
static com.webobjects.foundation.NSDictionary dictionaryWithObjectsAndKeys(java.lang.Object[] objectsAndKeys)
          Creates a dictionary from a list of alternating objects and keys starting with an object.
static
<T> com.webobjects.foundation.NSArray<T>
keysSortedByValueAscending(com.webobjects.foundation.NSDictionary<T,?> d)
           
static java.lang.String queryStringForDictionary(com.webobjects.foundation.NSDictionary<?,?> dict, java.lang.String separator)
          Encodes a dictionary into a string that can be used in a request uri.
static java.lang.String queryStringForDictionary(com.webobjects.foundation.NSDictionary<?,?> dict, java.lang.String separator, java.lang.String encoding)
          Encodes a dictionary into a string that can be used in a request uri.
static
<K,V> void
removeMatchingEntries(com.webobjects.foundation.NSMutableDictionary<? extends K,? extends V> dict1, com.webobjects.foundation.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> com.webobjects.foundation.NSDictionary<K,V>
removeNullValues(com.webobjects.foundation.NSDictionary<K,V> dict)
           
static
<K,V> void
setObjectForKeys(com.webobjects.foundation.NSMutableDictionary<K,V> dictionary, V object, com.webobjects.foundation.NSArray<K> keys)
          Sets the object for each of the keys in the array on a mutable dictionary.
static com.webobjects.foundation.NSArray<java.lang.String> stringKeysSortedAscending(com.webobjects.foundation.NSDictionary<java.lang.String,?> 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 <K,V> com.webobjects.foundation.NSDictionary<K,V> dictionaryWithDictionaryAndDictionary(com.webobjects.foundation.NSDictionary<? extends K,? extends V> dict1,
                                                                                                      com.webobjects.foundation.NSDictionary<? extends K,? extends V> 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 com.webobjects.foundation.NSDictionary dictionaryFromPropertyList(java.lang.String name,
                                                                                com.webobjects.foundation.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 com.webobjects.foundation.NSDictionary dictionaryWithObjectsAndKeys(java.lang.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 <K,V> com.webobjects.foundation.NSDictionary<K,V> dictionaryByRemovingFromDictionaryKeysInArray(com.webobjects.foundation.NSDictionary<K,V> d,
                                                                                                              com.webobjects.foundation.NSArray<K> 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 <K,V> com.webobjects.foundation.NSDictionary<K,V> dictionaryByRemovingKeysNotInArray(com.webobjects.foundation.NSDictionary<K,V> d,
                                                                                                   com.webobjects.foundation.NSArray<K> 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 <K,V> com.webobjects.foundation.NSDictionary<K,V> removeNullValues(com.webobjects.foundation.NSDictionary<K,V> dict)

dictionaryFromObjectWithKeys

public static com.webobjects.foundation.NSDictionary<java.lang.String,java.lang.Object> dictionaryFromObjectWithKeys(java.lang.Object object,
                                                                                                                     com.webobjects.foundation.NSArray<java.lang.String> 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 com.webobjects.foundation.NSArray<java.lang.String> stringKeysSortedAscending(com.webobjects.foundation.NSDictionary<java.lang.String,?> d)

keysSortedByValueAscending

public static <T> com.webobjects.foundation.NSArray<T> keysSortedByValueAscending(com.webobjects.foundation.NSDictionary<T,?> d)
Parameters:
d - dictionary to sort keys from
Returns:
keys from d sorted by ascending value they are mapped to

removeMatchingEntries

public static <K,V> void removeMatchingEntries(com.webobjects.foundation.NSMutableDictionary<? extends K,? extends V> dict1,
                                               com.webobjects.foundation.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. Note that this comparison considers null == EO/NSKeyValueCoding.NullValue.

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

_removeMatchingEntries

public static <K,V> void _removeMatchingEntries(com.webobjects.foundation.NSMutableDictionary<? extends K,? extends V> snapshot1,
                                                com.webobjects.foundation.NSMutableDictionary<? extends K,? extends V> snapshot2,
                                                boolean removeInverse)

setObjectForKeys

public static <K,V> void setObjectForKeys(com.webobjects.foundation.NSMutableDictionary<K,V> dictionary,
                                          V object,
                                          com.webobjects.foundation.NSArray<K> 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 <K,V> com.webobjects.foundation.NSDictionary<K,V> deepClone(com.webobjects.foundation.NSDictionary<K,V> dict,
                                                                          boolean onlyCollections)
Returns a deep clone of the given dictionary. A deep clone will attempt to clone the keys and values (deeply) of this dictionary as well as the dictionary itself.

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

queryStringForDictionary

public static java.lang.String queryStringForDictionary(com.webobjects.foundation.NSDictionary<?,?> dict,
                                                        java.lang.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 java.lang.String queryStringForDictionary(com.webobjects.foundation.NSDictionary<?,?> dict,
                                                        java.lang.String separator,
                                                        java.lang.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: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.