jfun.jaskell
Class Tuple

java.lang.Object
  extended byjfun.jaskell.Tuple
All Implemented Interfaces:
java.io.Serializable, jfun.util.Sizeable

public final class Tuple
extends java.lang.Object
implements java.io.Serializable, jfun.util.Sizeable

A jaskell tuple.

Author:
Ben Yu Jan 8, 2005
See Also:
Serialized Form

Method Summary
 Tuple addMap(java.util.Map m)
          Creates a new tuple by adding the key-pair values with the key-pair value of this tuple.
 Tuple addStrictFunction(java.lang.Object name, Function f)
          Add a strict function to this tuple as a member.
 Tuple addValue(java.lang.Object v)
          Add a value to this tuple as a member.
 Tuple addValue(java.lang.Object name, java.lang.Object v)
          Add a value to this tuple as a member.
 boolean containsKey(java.lang.Object key)
          Determines if the tuple contains the provided key.
 Tuple copy()
          Create a deep copy of the Tuple.
 boolean equals(java.lang.Object other)
           
 java.lang.Object eval(java.lang.Object name)
          Evaluate a tuple member identified by name.
static Tuple extendsTuple(Tuple t1, Tuple t2)
          Same as t1 `extends` t2.
 java.lang.Class getFamilyClass()
          Get the java class represented by this tuple.
 TupleMember getMember(java.lang.Object name)
          Get the tuple member identified by name.
 java.lang.Object getThis()
          Get the java object represented by this tuple.
 int hashCode()
           
 Tuple importClass(java.lang.Class type)
          Import a java class and its public static nested classes as a tuple under the class name.
 Tuple importClass(java.lang.String fullname, java.lang.Class type)
          Import a java class and its public static nested classes as a tuple.
 Tuple importClassHierarchy(java.lang.Class type)
          Import a java class and its public static nested classes into the evaluation context.
 Tuple importMember(java.lang.String fullname, TupleMember tm)
          Import a tuple member into this tuple.
static Tuple includesTuple(Tuple t1, Tuple t2)
          Same as t1 `includes` t2.
static Tuple instance()
          To create an empty Tuple instance.
 boolean isEmpty()
          To determine if the tuple is empty.
 java.lang.Object[] keys()
          Get the keys of the Tuple.
 java.lang.Object[] keys(java.lang.Object[] arr)
          Get the keys of the Tuple and store them in the provided array.
 TupleMember[] members()
          Get the tuple members.
 Tuple put(java.lang.Object name, TupleMember v)
          create a new Tuple object with the new TupleMember.
 Tuple puts(java.lang.Object[] keys, TupleMember[] mbrs)
          Add tuple members under given names.
 Tuple remove(java.lang.Object key)
          Create a new Tuple by removing one member identified by a key.
 Tuple removes(java.lang.Object[] keys)
          Create a new Tuple by removing members identified by the array of keys.
 int size()
          Get the number of members in the tuple.
 Tuple subtuple(java.lang.Object[] arr_flds)
          Create a slice of this tuple.
 java.lang.String toString()
          If the tuple contains toString member, this member is evaluated.
static TupleMember valueMember(java.lang.Object v)
          Create a TupleMember object that represents a value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getFamilyClass

public java.lang.Class getFamilyClass()
Get the java class represented by this tuple. null is returned if the tuple doesn't represent a java class.


getThis

public java.lang.Object getThis()
Get the java object represented by this tuple. null is returned if the tuple doesn't represent a java object.


copy

public Tuple copy()
Create a deep copy of the Tuple.


hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object other)

addMap

public Tuple addMap(java.util.Map m)
Creates a new tuple by adding the key-pair values with the key-pair value of this tuple.

Parameters:
m - the map object.
Returns:
the new Tuple object with the key-pair values in the map.

valueMember

public static TupleMember valueMember(java.lang.Object v)
Create a TupleMember object that represents a value.

Parameters:
v - the value.
Returns:
the TupleMember object.

puts

public Tuple puts(java.lang.Object[] keys,
                  TupleMember[] mbrs)
Add tuple members under given names. The keys array and mbrs array have to have the same length.

Parameters:
keys - the names of the members.
mbrs - the tuple member objects.
Returns:
the new Tuple containing the the new members.

remove

public Tuple remove(java.lang.Object key)
Create a new Tuple by removing one member identified by a key. If the tuple does not contain the key, no change is made.

Parameters:
key - the key.
Returns:
the new Tuple.

removes

public Tuple removes(java.lang.Object[] keys)
Create a new Tuple by removing members identified by the array of keys.

Parameters:
keys - the keys.
Returns:
the new Tuple.

keys

public java.lang.Object[] keys()
Get the keys of the Tuple.

Returns:
the array of the keys.

keys

public java.lang.Object[] keys(java.lang.Object[] arr)
Get the keys of the Tuple and store them in the provided array.

Returns:
the array of the keys.

members

public TupleMember[] members()
Get the tuple members.

Returns:
the array of members.

size

public int size()
Get the number of members in the tuple.

Specified by:
size in interface jfun.util.Sizeable
Returns:
the number of members.

isEmpty

public boolean isEmpty()
To determine if the tuple is empty.

Specified by:
isEmpty in interface jfun.util.Sizeable
Returns:
true if empty, false otherwise.

getMember

public TupleMember getMember(java.lang.Object name)
Get the tuple member identified by name.

Parameters:
name - the member name.
Returns:
the member. null if not found.

containsKey

public boolean containsKey(java.lang.Object key)
Determines if the tuple contains the provided key.

Parameters:
key - the key.
Returns:
true if the tuple contains the key, false otherwise.

eval

public java.lang.Object eval(java.lang.Object name)
Evaluate a tuple member identified by name.

Parameters:
name - the tuple name.
Returns:
the result of evaluating the member.

put

public Tuple put(java.lang.Object name,
                 TupleMember v)
create a new Tuple object with the new TupleMember.

Parameters:
name - the name of the member. If a member with this name already exists, it is overridden.
v - the tuple member.
Returns:
the new Tuple object.

addValue

public Tuple addValue(java.lang.Object name,
                      java.lang.Object v)
Add a value to this tuple as a member.

Parameters:
name - the member name.
v - the value.
Returns:
the new Tuple that contains this new value.

addValue

public Tuple addValue(java.lang.Object v)
Add a value to this tuple as a member. The string representation of the value is used as key.

Parameters:
v - the value.
Returns:
the new Tuple that contains this new value.

addStrictFunction

public Tuple addStrictFunction(java.lang.Object name,
                               Function f)
Add a strict function to this tuple as a member.

Parameters:
name - the member name.
f - the strict function.
Returns:
the new Tuple that contains this function.

importClass

public Tuple importClass(java.lang.Class type)
Import a java class and its public static nested classes as a tuple under the class name. Only the last part of the class name will be used. For example: java.lang.System will be imported under name "System". any free occurrence of will be bound to this tuple.

Parameters:
type - the java class.
Returns:
a new Tuple object containing the new class tuple.

importClass

public Tuple importClass(java.lang.String fullname,
                         java.lang.Class type)
Import a java class and its public static nested classes as a tuple.

Parameters:
fullname - the fullname of the tuple.
type - the java class.
Returns:
a new Tuple object containing the new class tuple.

importClassHierarchy

public Tuple importClassHierarchy(java.lang.Class type)
Import a java class and its public static nested classes into the evaluation context. This tuple will be created in a tuple hierarchy corresponding to the java package structure.
For example: importClassHierarchy("myjava", java.util.Collections.class); will create a tuple structure as: myjava - java - util - Collection. if any of the intermediary tuple already exists, it is populated with this new class.
primitive type is imported into the "java" namespace. i.e. int should be referenced as "java.int".

Parameters:
type - the java class.
Returns:
a new Tuple object containing the new class tuple.

importMember

public Tuple importMember(java.lang.String fullname,
                          TupleMember tm)
Import a tuple member into this tuple. The name is specified in a fully qualified format. For example: "mycompany.dept1.group1". All the intermediate name are tuple names. If one tuple already exists, the new change is added. If the tuple does not exist, a new tuple is created.

Parameters:
fullname - the fully qualified name for this member.
tm - the tuple member.
Returns:
the new Tuple with the member added to the hierarchy specified by the name.

toString

public java.lang.String toString()
If the tuple contains toString member, this member is evaluated. Otherwise, It will evaluate all the members in this tuple. Be careful if any member has side-effect.


instance

public static Tuple instance()
To create an empty Tuple instance.

Returns:
the Tuple instance.

extendsTuple

public static Tuple extendsTuple(Tuple t1,
                                 Tuple t2)
Same as t1 `extends` t2. The result tuple contains everything in t1 and everything in t2 that's not in t1. "this" binds to the new tuple. If either tuple is null, the other one is returned.

Parameters:
t1 - the 1st tuple.
t2 - the 2nd tuple.
Returns:
the result tuple.

includesTuple

public static Tuple includesTuple(Tuple t1,
                                  Tuple t2)
Same as t1 `includes` t2. The result tuple contains everything in t2 and everything in t1 that's not in t2. "this" binds to the t1 for members from t1; binds to t2 for members from t2. If either tuple is null, the other one is returned.

Parameters:
t1 - the 1st tuple.
t2 - the 2nd tuple.
Returns:
the result tuple.

subtuple

public Tuple subtuple(java.lang.Object[] arr_flds)
Create a slice of this tuple. "this" still binds to this tuple.

Parameters:
arr_flds - the fields to select.
Returns:
the new Tuple.