|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jess.Value
The class jess.Value is probably the one you'll use the most in working with Jess. A Value is a self-describing data object. Every datum in Jess is contained in one. Once it is constructed, a Value's type and contents cannot be changed; it is immutable.
Value objects are constructed by specifying the data and (usually) the type. Each overloaded constructor assures that the given data and the given type are compatible. Note that for each constructor, more than one value of the type parameter may be acceptable.
jess.Value has a number of subclasses:
Variable
, FuncallValue
, FactIDValue
, and
LongValue
are the four of
most interest to the reader. When you wish to create a value to represent a
variable, a function call, a fact, or a Java long, you must use the
appropriate subclass.
Note to the design-minded: We could have used a Factory pattern here and hidden the subclasses from the programmer; now backwards compatibility prevents us from making this change.
Value supports a number of functions to get the actual data out
of a Valueobject. Some jess.Value objects may need to be resolved before
use. To resolve a jess.Value means to interpret it in a
particular context. jess.Value objects can represent both
static values (symbols, numbers, strings) and dynamic ones (variables,
function calls). It is the dynamic ones that obviously have to be
interpreted in context. The class Context
provides a context for interpreting Values.
All the jess.Value member functions, like
intValue(jess.Context)
, that accept a jess.Context as an
argument are self-resolving; that is, if a jess.Value
object represents a function call, the call will be executed in the
given jess.Context, and the intValue() method will
be called on the result. Therefore, you often don't need to worry
about resolution as it is done automatically. There are several cases
where you will, however.
resolveValue(jess.Context)
and store
the return value in a new jess.Value variable, using this
value as the new parameter. Note that the type() method will
return RU.VARIABLE
for a jess.Value object that
refers to a variable, regardless of the type of the value the variable
is bound to. The resolved value will return the proper type.
Note that arguments to deffunctions are resolved
automatically, before your Jess language code runs. If you try to convert random values by creating a Value and retrieving
it as some other type, you'll generally get a JessException
. However, some
types can be freely interconverted: for example, integers and floats.
(C) 2006 Sandia National Laboratories
Constructor Summary | |
Value(boolean b)
Contruct a boolean value object (one of the RU.SYMBOLs 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 Java object 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)
Deprecated. use symbolValue instead |
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), but returns true for 3 == 3.0 |
java.lang.Object |
externalAddressValue(Context c)
Deprecated. As of Jess 7, use javaObjectValue() instead. |
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 double. |
Funcall |
funcallValue(Context c)
Returns the contents of this value, as a function call. |
Userfunction |
functionValue(Context c)
Return the value of this object as a Userfunction. |
int |
hashCode()
Return a hashcode for the object. |
int |
intValue(Context c)
Returns the contents of this value, as an int. |
boolean |
isLexeme(Context c)
Indicate whether this object represents a lexeme. |
boolean |
isNumeric(Context c)
Indicate whether this object represents a number. |
java.lang.Object |
javaObjectValue(Context c)
Returns the contents of this value, as a Java object. |
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 |
symbolValue(Context c)
Returns the contents of this value, as a symbol. |
java.lang.String |
toString()
Return a pretty-print version of this value, without adding parens to any lists. |
java.lang.String |
toStringWithParens()
Return a pretty-print version of 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 |
public Value(int value, int type) throws JessException
value
- the valuetype
- the type
JessException
- if the value and type don't match.public Value(Value v)
v
- the Value to copypublic Value(java.lang.String s, int type) throws JessException
s
- the valuetype
- the type
JessException
- if the value and type don't match.public Value(ValueVector f, int type) throws JessException
f
- the valuetype
- the type
JessException
- if the value and type don't match.public Value(double d, int type) throws JessException
d
- the valuetype
- the type
JessException
- if the value and type don't match.public Value(boolean b)
b
- the valuepublic Value(java.lang.Object o)
o
- the value -- any Java objectMethod Detail |
public java.lang.Object externalAddressValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain a Java objectpublic java.lang.Object javaObjectValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain a Java objectpublic Funcall funcallValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain a function call.public Fact factValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain a factpublic ValueVector listValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain a list
JessException
- if something goes wrong during value resolutionpublic double numericValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain any kind of numberpublic int intValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain any kind of numberpublic long longValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain any kind of number.public double floatValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain any kind of number.public final java.lang.String atomValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain any kind of String.public java.lang.String symbolValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain any kind of Stringpublic java.lang.String variableValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain a variable.public java.lang.String stringValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this value does not contain any kind of String.public Userfunction functionValue(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if this is not a functionpublic java.lang.String toString()
public java.lang.String toStringWithParens()
public int type()
RU
.
public boolean equals(java.lang.Object v)
v
- the object to compare to.
public boolean equals(Value v)
v
- the Value to compare to.
public boolean equalsStar(Value v)
v
- Value to compare to
public int hashCode()
public Value resolveValue(Context c) throws JessException
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.
JessException
- if something goes wrong during value resolutionVariable
,
Funcall
public boolean isNumeric(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if something goes wrong during value resolutionpublic boolean isLexeme(Context c) throws JessException
c
- the execution context used to resolve the value
JessException
- if something goes wrong during value resolution
|
© 2006 Sandia Corporation | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |