jfun.jaskell
Class DefaultResolver

java.lang.Object
  extended byjfun.jaskell.DefaultResolver
All Implemented Interfaces:
Resolver

public class DefaultResolver
extends java.lang.Object
implements Resolver

This is the default implementation of Resolver interface. It returns the default value for unbound variable and undefined tuple member.

Author:
Ben Yu Feb 17, 2006 11:23:55 AM

Constructor Summary
protected DefaultResolver()
           
 
Method Summary
static Tuple asTuple(java.lang.Object obj)
          Convert an object to a Tuple if it is not already a Tuple.
static Resolver instance()
          To get an instance of this implementation.
 java.lang.Object resolveMember(java.lang.Object obj, java.lang.String name, java.lang.Object def)
          This implementation converts the object to a tuple, and if the member name is contained in the tuple, resolution succeeded with the tuple member value; otherwise, default value is returned.
 java.lang.Object resolveSubscript(java.lang.Object obj, java.lang.Object[] args, java.lang.Object def)
          This implementation applies subscript to array, list, java.util.Map and Tuple.
 java.lang.Object resolveVar(java.lang.String name, java.lang.Object def)
          Simply return the default value as an indicator of resolution failure.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultResolver

protected DefaultResolver()
Method Detail

resolveVar

public java.lang.Object resolveVar(java.lang.String name,
                                   java.lang.Object def)
Simply return the default value as an indicator of resolution failure.

Specified by:
resolveVar in interface Resolver
Parameters:
name - the variable name.
def - the default value.
Returns:
the variable value or the default value if not resolveable.

resolveMember

public java.lang.Object resolveMember(java.lang.Object obj,
                                      java.lang.String name,
                                      java.lang.Object def)
This implementation converts the object to a tuple, and if the member name is contained in the tuple, resolution succeeded with the tuple member value; otherwise, default value is returned.

Specified by:
resolveMember in interface Resolver
Parameters:
obj - the object.
name - the member name.
def - the default value.
Returns:
the member value or the default value if not resolveable.

resolveSubscript

public java.lang.Object resolveSubscript(java.lang.Object obj,
                                         java.lang.Object[] args,
                                         java.lang.Object def)
This implementation applies subscript to array, list, java.util.Map and Tuple. The default value is returned for other types.

Specified by:
resolveSubscript in interface Resolver
Parameters:
obj - the object.
args - the subscripts.
def - the default value.
Returns:
the result or the default value if not resolveable.

instance

public static Resolver instance()
To get an instance of this implementation.


toString

public java.lang.String toString()

asTuple

public static Tuple asTuple(java.lang.Object obj)
Convert an object to a Tuple if it is not already a Tuple.

Parameters:
obj - the object.
Returns:
the Tuple.