jess
Class Value

java.lang.Object
  extended byjess.Value
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BindingValue, FactIDValue, FuncallValue, LongValue, Variable

public class Value
extends java.lang.Object
implements java.io.Serializable

A class to represent a Jess typed value. Does some 'type conversions'. Subclasses of this are used to represent Variables and other special types.

(C) 1998 E.J. Friedman-Hill and the Sandia Corporation

Author:
Ernest J. Friedman-Hill
See Also:
Serialized Form

Constructor Summary
Value(boolean b)
          Contruct a boolean value object (one of the RU.ATOMs TRUE or FALSE.
Value(double d, int type)
          Contruct a value of floating-point type.
Value(int value, int type)
          Contruct a value of integral type.
Value(java.lang.Object o)
          Contruct a value of external address type.
Value(java.lang.String s, int type)
          Contruct a value of String type.
Value(Value v)
          Contruct a value that is a copy of another Value.
Value(ValueVector f, int type)
          Contruct a value of list type.
 
Method Summary
 java.lang.String atomValue(Context c)
          Returns the contents of this value, as an atom
 boolean equals(java.lang.Object v)
          Compare this value to another object.
 boolean equals(Value v)
          Compare this value to another value.
 boolean equalsStar(Value v)
          Like equals(Value) above, but returns true for 3 == 3.0
 java.lang.Object externalAddressValue(Context c)
          Returns the contents of this value, as an external adress object
 Fact factValue(Context c)
          Returns the contents of this value, as a fact
 double floatValue(Context c)
          Returns the contents of this value, as a number
 Funcall funcallValue(Context c)
          Returns the contents of this value, as a function call.
 int hashCode()
          Return a hashcode for the object
 int intValue(Context c)
          Returns the contents of this value, as an int
 ValueVector listValue(Context c)
          Returns the contents of this value, as a list
 long longValue(Context c)
          Returns the contents of this value, as a long
 double numericValue(Context c)
          Returns the contents of this value, as a number
 Value resolveValue(Context c)
          Given an evaluation context, return the "true value" of this Value.
 java.lang.String stringValue(Context c)
          Returns the contents of this value, as a String
 java.lang.String toString()
          Pretty-print this value, without adding parens to any lists
 java.lang.String toStringWithParens()
          Pretty-print this value, adding parens to any lists
 int type()
          Return the type of this variable.
 java.lang.String variableValue(Context c)
          Returns the contents of this value, as a String (a variable name)
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Value

public Value(int value,
             int type)
      throws JessException
Contruct a value of integral type. Allowed type values are NONE and INTEGER

Parameters:
value - The value
type - The type
Throws:
JessException - If the value and type don't match.

Value

public Value(Value v)
Contruct a value that is a copy of another Value.

Parameters:
v - Value to copy

Value

public Value(java.lang.String s,
             int type)
      throws JessException
Contruct a value of String type. Allowed type values are RU.ATOM, RU.STRING, RU.SLOT and RU.MULTISLOT.

Parameters:
s - The value
type - The type
Throws:
JessException - If the value and type don't match.

Value

public Value(ValueVector f,
             int type)
      throws JessException
Contruct a value of list type. Allowed type values are FACT and LIST.

Parameters:
f - The value
type - The type
Throws:
JessException - If the value and type don't match.

Value

public Value(double d,
             int type)
      throws JessException
Contruct a value of floating-point type. Allowed type values are FLOAT, LONG, and INTEGER -- although LONG can only be used if this is called from the subclass LongValue.

Parameters:
d - The value
type - The type
Throws:
JessException - If the value and type don't match.

Value

public Value(boolean b)
Contruct a boolean value object (one of the RU.ATOMs TRUE or FALSE.

Parameters:
b - The value

Value

public Value(java.lang.Object o)
Contruct a value of external address type.

Parameters:
o - The value
Method Detail

externalAddressValue

public java.lang.Object externalAddressValue(Context c)
                                      throws JessException
Returns the contents of this value, as an external adress object

Returns:
The external address object
Throws:
JessException - If this value does not contain an object

funcallValue

public Funcall funcallValue(Context c)
                     throws JessException
Returns the contents of this value, as a function call.

Returns:
The function call object
Throws:
JessException - If this value does not contain a function call

factValue

public Fact factValue(Context c)
               throws JessException
Returns the contents of this value, as a fact

Returns:
The fact
Throws:
JessException - If this value does not contain a fact

listValue

public ValueVector listValue(Context c)
                      throws JessException
Returns the contents of this value, as a list

Returns:
The list
Throws:
JessException - If this value does not contain a list

numericValue

public double numericValue(Context c)
                    throws JessException
Returns the contents of this value, as a number

Returns:
The number as a double
Throws:
JessException - If this value does not contain any kind of number

intValue

public int intValue(Context c)
             throws JessException
Returns the contents of this value, as an int

Returns:
The number as an int
Throws:
JessException - If this value does not contain any kind of number

longValue

public long longValue(Context c)
               throws JessException
Returns the contents of this value, as a long

Returns:
The number as a long
Throws:
JessException - If this value does not contain any kind of number

floatValue

public double floatValue(Context c)
                  throws JessException
Returns the contents of this value, as a number

Returns:
The number as a double
Throws:
JessException - If this value does not contain any kind of number

atomValue

public java.lang.String atomValue(Context c)
                           throws JessException
Returns the contents of this value, as an atom

Returns:
The atom
Throws:
JessException - If this value does not contain any kind of String

variableValue

public java.lang.String variableValue(Context c)
                               throws JessException
Returns the contents of this value, as a String (a variable name)

Returns:
The name of the variable
Throws:
JessException - If this value does not contain a variable

stringValue

public java.lang.String stringValue(Context c)
                             throws JessException
Returns the contents of this value, as a String

Returns:
The string
Throws:
JessException - If this value does not contain any kind of String

toString

public java.lang.String toString()
Pretty-print this value, without adding parens to any lists

Returns:
The formatted string

toStringWithParens

public java.lang.String toStringWithParens()
Pretty-print this value, adding parens to any lists

Returns:
The formatted string

type

public int type()
Return the type of this variable. Always one of the constants in jess.RU.

Returns:
The type

equals

public boolean equals(java.lang.Object v)
Compare this value to another object. As a convenience, if the parameter is not a Value, it will be compared to any contained Object inside this Vector (a String or external address object.)

Parameters:
v - The object to compare to.
Returns:
True if the objects are equivalent.

equals

public boolean equals(Value v)
Compare this value to another value. Believe it or not, using this separate overloaded routine has a measurable impact on performance - since so much time is spent comparing Values.

Parameters:
v - The Value to compare to.
Returns:
True if the Values are equivalent.

equalsStar

public boolean equalsStar(Value v)
Like equals(Value) above, but returns true for 3 == 3.0

Parameters:
v - Value to compare to
Returns:
True if the values are loosely equivalent

hashCode

public int hashCode()
Return a hashcode for the object

Returns:
The hashcode

resolveValue

public Value resolveValue(Context c)
                   throws JessException
Given an evaluation context, return the "true value" of this Value. For this class, the true value is always "this". For subclasses, the Context may be used to compute a new Value.

Parameters:
c - An execution context. You can pass null if you are sure that you're not calling this method on a subclass that uses the argument.
Returns:
This object
Throws:
JessException
See Also:
Variable, Funcall

© 2001 E.J. Friedman-Hill and Sandia Corporation