net.beadsproject.beads.data
Class DataBead

java.lang.Object
  extended by net.beadsproject.beads.core.Bead
      extended by net.beadsproject.beads.data.DataBead
All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>

public class DataBead
extends Bead
implements java.util.Map<java.lang.String,java.lang.Object>

A bead that stores properties as key/value pairs. Keys must be Strings, and values may be any Object. Implements the Map interface.

Version:
0.9.6
Author:
Benito Crawford

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
 java.util.Map<java.lang.String,java.lang.Object> properties
           
 
Constructor Summary
DataBead()
          Creates a DataBead instance with no defined properties.
DataBead(java.util.Map<java.lang.String,java.lang.Object> ht)
          Creates a DataBead instance that uses a Map (a Hashtable, for example) for its properties.
DataBead(java.lang.Object... objects)
          Creates a new DataBead from an interleaved series of key-value pairs, which must be in the form (String, Object, String, Object...), etc.
DataBead(java.lang.String[] proparr, java.lang.Object[] valarr)
          Creates a DataBead instance with properties specified by a String array that are set to corresponding values specified by an Object array.
DataBead(java.lang.String key, java.lang.Object val)
          Creates a DataBead with one property defined by the specified key and value.
 
Method Summary
 void clear()
           
 DataBead clone()
          Returns a new DataBead with a shallow copy of the the original DataBead's properties.
static DataBead combine(DataBead a, DataBead b)
          Creates a new DataBead that combines properties from both input DataBeads.
 void configureObject(java.lang.Object o)
          Uses the parameters stored by this DataBead, this method configures the given object by using reflection to discover appropriate setter methods.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 float getFloat(java.lang.String key, float defaultVal)
          Gets a float representation of the specified property; returns the specified default value if that property doesn't exist or cannot be cast as a float.
 float[] getFloatArray(java.lang.String key)
          Gets a float array from the value stored with the specified key.
 java.lang.Float getFloatObject(java.lang.String key)
          Gets a Float representation of the specified property; returns null if that property doesn't exist or cannot be cast as a Float.
 UGen getUGen(java.lang.String key)
          Returns the UGen value for the specified key.
 UGen[] getUGenArray(java.lang.String key)
          Gets an array of UGens from the value stored with the specified key.
 boolean isEmpty()
           
 java.util.Set<java.lang.String> keySet()
           
 void messageReceived(Bead message)
          If the input message is a DataBead, this adds the properties from the message Bead to this one.
 java.lang.Object put(java.lang.String key, java.lang.Object value)
           
 void putAll(DataBead db)
          Adds the properties from the input DataBead to this one.
 void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
           
 void putAll(java.lang.Object... objects)
          Adds an interleaved series of key-value pairs to the DataBead, which must be in the form (String, Object, String, Object...), etc.
 java.lang.Object remove(java.lang.Object key)
           
 int size()
           
 java.lang.String toString()
          Returns a String specifying the Bead's class and it's name.
 java.util.Collection<java.lang.Object> values()
           
 
Methods inherited from class net.beadsproject.beads.core.Bead
getKillListener, getName, isDeleted, isPaused, kill, message, pause, setKillListener, setName, start
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

properties

public java.util.Map<java.lang.String,java.lang.Object> properties
Constructor Detail

DataBead

public DataBead()
Creates a DataBead instance with no defined properties. Properties may be added with put().


DataBead

public DataBead(java.lang.String key,
                java.lang.Object val)
Creates a DataBead with one property defined by the specified key and value. Other properties may be added with put().

Parameters:
key - The property name.
val - The property value.

DataBead

public DataBead(java.lang.String[] proparr,
                java.lang.Object[] valarr)
Creates a DataBead instance with properties specified by a String array that are set to corresponding values specified by an Object array. Other properties may be added with put().

Parameters:
proparr - The array of property names.
valarr - The array of Object values.

DataBead

public DataBead(java.util.Map<java.lang.String,java.lang.Object> ht)
Creates a DataBead instance that uses a Map (a Hashtable, for example) for its properties. (This does not copy the input Map, so any changes to it will change the properties of the DataBead!) Other properties may be added with put().

Parameters:
ht - The input Map.

DataBead

public DataBead(java.lang.Object... objects)
Creates a new DataBead from an interleaved series of key-value pairs, which must be in the form (String, Object, String, Object...), etc.

Parameters:
objects - interleaved series of key-value pairs.
Method Detail

messageReceived

public void messageReceived(Bead message)
If the input message is a DataBead, this adds the properties from the message Bead to this one. (Equivalent to putAll(DataBead) .)

Overrides:
messageReceived in class Bead
Parameters:
message - the message

putAll

public void putAll(DataBead db)
Adds the properties from the input DataBead to this one.

Parameters:
db - The input DataBead.

putAll

public void putAll(java.lang.Object... objects)
Adds an interleaved series of key-value pairs to the DataBead, which must be in the form (String, Object, String, Object...), etc.

Parameters:
objects - an interleaved series of key-value pairs.

configureObject

public void configureObject(java.lang.Object o)
Uses the parameters stored by this DataBead, this method configures the given object by using reflection to discover appropriate setter methods. For example, if the object has a method setX(float f) then the key-value pair will be used to invoke this method. Errors are caught and printed (actually, not right now...).

Be aware that this may not work as expected with all objects. Use with care...

Parameters:
o - the Object to configure.

getFloat

public float getFloat(java.lang.String key,
                      float defaultVal)
Gets a float representation of the specified property; returns the specified default value if that property doesn't exist or cannot be cast as a float.

This method is a useful way to update float parameters in a class:

float param = startval;
...
param = databead.getFloat("paramKey", param);

Parameters:
key - The property key.
defaultVal - The value to return if the property does not contain a float-convertible value.
Returns:
The property value, or the default value if there is no float representation of the property.

getFloatObject

public java.lang.Float getFloatObject(java.lang.String key)
Gets a Float representation of the specified property; returns null if that property doesn't exist or cannot be cast as a Float.

Parameters:
key - The property key.
Returns:
The property value, or the default value if there is no float representation of the property.

getUGen

public UGen getUGen(java.lang.String key)
Returns the UGen value for the specified key. If the value stored at the key is not a UGen, it returns null.

Parameters:
key - The key.
Returns:
The UGen if it exists.

getFloatArray

public float[] getFloatArray(java.lang.String key)
Gets a float array from the value stored with the specified key. If the stored value is actually of type float[], the method returns that object. In the event that the stored value is an array of numbers of some other type, the method will return a new float array filled with values converted to float; an array of doubles, for instance, will be recast as floats. Single numbers will be returned as a one-element float array. If no array can be formed from the stored value, or if there is no stored value, the method returns null.

Parameters:
key - The key.
Returns:
The derived float array.

getUGenArray

public UGen[] getUGenArray(java.lang.String key)
Gets an array of UGens from the value stored with the specified key. If the value is a UGen object (not an array), the method returns a new one-element UGen array with the value stored in it. If the value is empty, or not a UGen array or UGen, the method returns null.

Parameters:
key - The key.
Returns:
The UGen array.

clone

public DataBead clone()
Returns a new DataBead with a shallow copy of the the original DataBead's properties.

Overrides:
clone in class java.lang.Object

combine

public static DataBead combine(DataBead a,
                               DataBead b)
Creates a new DataBead that combines properties from both input DataBeads. If the same key exists in both, the value from the first one is used.

Parameters:
a - The first input DataBead.
b - The second input DataBead.
Returns:
The new DataBead.

toString

public java.lang.String toString()
Description copied from class: Bead
Returns a String specifying the Bead's class and it's name.

Overrides:
toString in class Bead
Returns:
String describing the Bead.

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<java.lang.String,java.lang.Object>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<java.lang.String,java.lang.Object>

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.String,java.lang.Object>

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map<java.lang.String,java.lang.Object>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<java.lang.String,java.lang.Object>

keySet

public java.util.Set<java.lang.String> keySet()
Specified by:
keySet in interface java.util.Map<java.lang.String,java.lang.Object>

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map<java.lang.String,java.lang.Object>

putAll

public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
Specified by:
putAll in interface java.util.Map<java.lang.String,java.lang.Object>

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<java.lang.String,java.lang.Object>

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.String,java.lang.Object>

values

public java.util.Collection<java.lang.Object> values()
Specified by:
values in interface java.util.Map<java.lang.String,java.lang.Object>

clear

public void clear()
Specified by:
clear in interface java.util.Map<java.lang.String,java.lang.Object>