one.world.core
Class DynamicTuple

java.lang.Object
  |
  +--one.world.core.Tuple
        |
        +--one.world.core.Event
              |
              +--one.world.core.DynamicTuple
All Implemented Interfaces:
Cloneable, Serializable

public final class DynamicTuple
extends Event

Implementation of a dynamically typed tuple. A dynamically typed tuple implements a mapping from field names to values. Fields can be dynamically added and removed as well as modified.

Note that access to the dynamic fields of a dynamic tuple is not synchronized. Concurrenct accesses must be synchronized externally.

Version:
$Revision: 1.14 $
See Also:
Tuple, Serialized Form

Fields inherited from class one.world.core.Event
closure, source
 
Fields inherited from class one.world.core.Tuple
CLOSURE, id, ID, META_DATA, metaData, SOURCE
 
Constructor Summary
DynamicTuple()
          Create a new, empty dynamically typed tuple.
DynamicTuple(EventHandler source, Object closure)
          Create a new dynamically typed tuple with the specified source and closure.
 
Method Summary
 Object clone()
          Make a shallow copy of this dynamic tuple.
 List fields()
          Get a list of this tuple's field names.
 Object get(String name)
          Get the value of the specified field.
 Object get(String name, Class k, boolean allowNull)
          Get the value of the specified field.
 Class getType(String name)
          Get the declared type of the field with the specified name.
 boolean hasField(String name)
          Determine whether this tuple has a field with the specified name.
 void set(String name, Object value)
          Set the specified field to the specified value.
 String toString()
          Get a string representation for this dynamic tuple.
 void validate()
          Validate this dynamic tuple.
 
Methods inherited from class one.world.core.Tuple
containsNonSymbolicHandler, equals, getMetaData, hashCode, hasMetaData, remove, setMetaData, wrap
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DynamicTuple

public DynamicTuple()
Create a new, empty dynamically typed tuple. This constructor sets source field of the newly created dynamic tuple to the canonical null handler, so that the new dynamic tuple validates.
See Also:
NullHandler

DynamicTuple

public DynamicTuple(EventHandler source,
                    Object closure)
Create a new dynamically typed tuple with the specified source and closure.
Parameters:
source - The source for the new dynamically typed tuple.
closure - The closure for the new dynamically typed tuple.
Method Detail

clone

public Object clone()
Make a shallow copy of this dynamic tuple.
Overrides:
clone in class Tuple
Following copied from class: one.world.core.Tuple
Returns:
A shallow copy of this tuple.

get

public Object get(String name)
Get the value of the specified field.
Overrides:
get in class Tuple
Following copied from class: one.world.core.Tuple
Parameters:
name - The name of the field.
Returns:
The value of the specified field, or null if this tuple has no such field.

get

public final Object get(String name,
                        Class k,
                        boolean allowNull)
Get the value of the specified field. This method returns the value of the specified field, if the field exists and if its value has the specified type.

Note that this method cannot be used to access the four statically typed fields – id, metaData, source, and closure – of a dynamic tuple.

Parameters:
name - The name of the field.
k - The required type for the field's value.
allowNull - Flag for whether to allow null values.
Throws:
IllegalArgumentException - Signals that this dynamic tuple does not have a field with the specified name, that the field's value does not have the specified type, or that the field's value is null and allowNull is false.

set

public void set(String name,
                Object value)
Set the specified field to the specified value.
Overrides:
set in class Tuple
Following copied from class: one.world.core.Tuple
Parameters:
name - The name of the field.
value - The new value for the field.
Throws:
IllegalArgumentException - Signals that a statically typed tuples does not have a field with the specified name or that the specified value is of the wrong type.

hasField

public boolean hasField(String name)
Determine whether this tuple has a field with the specified name.
Overrides:
hasField in class Tuple
Following copied from class: one.world.core.Tuple
Parameters:
name - The name of the field to test for.
Returns:
true if this tuple has a field with the specified name.

getType

public Class getType(String name)
Get the declared type of the field with the specified name.
Overrides:
getType in class Tuple
Following copied from class: one.world.core.Tuple
Parameters:
name - The name of the field.

fields

public List fields()
Get a list of this tuple's field names.
Overrides:
fields in class Tuple
Following copied from class: one.world.core.Tuple
Returns:
A list of this tuple's field names.

validate

public void validate()
              throws TupleException
Validate this dynamic tuple.
Overrides:
validate in class Event
Following copied from class: one.world.core.Tuple
Throws:
TupleException - Signals that the tuple is either malformed (i.e., does not conform to the tuple specification) or invalid (i.e., does not conform to the semantic constraints of its type).
See Also:
MalformedTupleException, InvalidTupleException, Type.validate(Class)

toString

public String toString()
Get a string representation for this dynamic tuple.
Overrides:
toString in class Tuple
Following copied from class: one.world.core.Tuple
Returns:
A string representation for this tuple.


(C) Copyright 2001 UW CSE