org.rococoa.contrib
Class AbstractPropertyDictionary<E extends Enum<E> & NativeEnum<?>>

java.lang.Object
  extended by org.rococoa.contrib.AbstractPropertyDictionary<E>
Type Parameters:
E - the enumerated type of the keys used with this dictionary
Direct Known Subclasses:
NSSpeechDictionary, NSSpeechDictionary.Entry, NSSpeechSynthesizer.NSSpeechCommand, NSSpeechSynthesizer.NSSpeechError, NSSpeechSynthesizer.NSSpeechPhonemeInfo, NSSpeechSynthesizer.NSSpeechStatus, NSSpeechSynthesizer.NSSpeechSynthesizerInfo, NSVoice

public abstract class AbstractPropertyDictionary<E extends Enum<E> & NativeEnum<?>>
extends Object

Wraps an NSMutableDictionary with a set of keys defined by a Java enumeration. Also provides convenience methods for converting between Java and Cocoa types for the values.


Constructor Summary
protected AbstractPropertyDictionary(int initialCapacity)
          Construct a new empty dictionary with the given initial capacity.
protected AbstractPropertyDictionary(NSDictionary data)
          Construct a new dictionary with the given dictionary.
protected AbstractPropertyDictionary(NSMutableDictionary data)
          Construct a new dictionary with the given dictionary.
 
Method Summary
 boolean getBoolean(E key)
          Get the value associated with the given key as a boolean
 NSMutableDictionary getData()
          Get the underlying dictionary
 Date getDate(E key)
          Get the value associated with the given key as a Date
<EN extends Enum<EN> & NativeEnum<?>>
EN
getEnum(Class<EN> nativeEnum, E key)
          Get the value associated with the given key as an enum
 int getInt(E key)
          Get the value associated with the given key as an int
 short getShort(E key)
          Get the value associated with the given key as a short
 String getString(E key)
          Get the value associated with the given key as a String
<R extends NSObject>
R
getValueAsType(E key, Class<R> type)
          Get the value associated with the given key as coercing it to the given type.
 void setDate(E key, Date date)
          Set the value associated with the given key.
 void setString(E key, String value)
          Set the value associated with the given key.
 void setValue(E key, NSObject value)
          Set the value associated with the given key.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractPropertyDictionary

protected AbstractPropertyDictionary(int initialCapacity)
Construct a new empty dictionary with the given initial capacity.

Parameters:
initialCapacity - the initial capacity to use

AbstractPropertyDictionary

protected AbstractPropertyDictionary(NSMutableDictionary data)
Construct a new dictionary with the given dictionary. The dictionary is not copied.

Parameters:
data - the dictionary to use

AbstractPropertyDictionary

protected AbstractPropertyDictionary(NSDictionary data)
Construct a new dictionary with the given dictionary. The dictionary is copied into a mutable dictionary.

Parameters:
data - the dictionary to use
Method Detail

getData

public NSMutableDictionary getData()
Get the underlying dictionary

Returns:
the dictionary being wrapped

getString

public String getString(E key)
Get the value associated with the given key as a String

Parameters:
key - the key whose associated value will be returned
Returns:
the value associated with the key as a Java String

setString

public void setString(E key,
                      String value)
Set the value associated with the given key.

Parameters:
key - the key whose value will be set
value - the value to set

getInt

public int getInt(E key)
Get the value associated with the given key as an int

Parameters:
key - the key whose associated value will be returned
Returns:
the value associated with the key as a Java int

getShort

public short getShort(E key)
Get the value associated with the given key as a short

Parameters:
key - the key whose associated value will be returned
Returns:
the value associated with the key as a Java short

getBoolean

public boolean getBoolean(E key)
Get the value associated with the given key as a boolean

Parameters:
key - the key whose associated value will be returned
Returns:
the value associated with the key as a Java boolean

getDate

public Date getDate(E key)
Get the value associated with the given key as a Date

Parameters:
key - the key whose associated value will be returned
Returns:
the value associated with the key as a Java Date

setDate

public void setDate(E key,
                    Date date)
Set the value associated with the given key.

Parameters:
key - the key whose value will be set
date - the value to set

getEnum

public <EN extends Enum<EN> & NativeEnum<?>> EN getEnum(Class<EN> nativeEnum,
                                                       E key)
Get the value associated with the given key as an enum

Type Parameters:
EN - the type of enum to return
Parameters:
key - the key whose associated value will be returned
nativeEnum - the class of the enum, used to resolve native values to the corresponding Java enum values
Returns:
the value associated with the key as a Java Enum

getValueAsType

public <R extends NSObject> R getValueAsType(E key,
                                             Class<R> type)
Get the value associated with the given key as coercing it to the given type.

Type Parameters:
R - the type to return
Parameters:
key - the key whose associated value will be returned
type - the subclass of NSObject that the value associated with key will be coerced to
Returns:
the value associated with the key coerced as into type

setValue

public void setValue(E key,
                     NSObject value)
Set the value associated with the given key.

Parameters:
key - the key whose value will be set
value - the value to set

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.