condor.classad
Class Constant

Object
  |
  +--condor.classad.Expr
        |
        +--condor.classad.Constant

public class Constant
extends Expr

A constant (Integer, Real, etc.). The constant is wrapped so that it may be used as a node in an expression tree. To conserve space, there is at most one Constant instance with any given value.

Version:
2.0
Author:
Marvin Solomon
See Also:
Expr

Nested Class Summary
 
Nested classes inherited from class condor.classad.Expr
Expr.Env
 
Field Summary
static Constant CyclicRef
          An undefined constant that represents the result a attempting to resovle a cyclic attribute reference as in [a=b;b=a].
static Constant Error
          A default error constant
static Constant False
          The unique boolean Constant false
static Constant True
          The unique boolean constant true
static Constant Undef
          A default undefined constant
 Object value
          The actual value of this Constant.
 
Fields inherited from class condor.classad.Expr
ABSOLUTE_TIME, AND, ATTRIBUTE, BIT_COMPLEMENT, BITAND, BITOR, BITXOR, BOOLEAN, CALL, COND, dateAndTimeFormat, dateFormat, dblevel, DIFFERENT, DIV, EQUAL, ERROR, GREATER, GREATER_EQ, INTEGER, LEFT_SHIFT, LESS, LESS_EQ, LIST, MAXPREC, MINUS, MOD, NOT, NOT_EQUAL, OP, opName, opNameXML, OR, PLUS, REAL, RECORD, RELATIVE_TIME, RIGHT_SHIFT, SAME, SELECTION, STRING, SUBSCRIPT, TIMES, type, UMINUS, UNDEFINED, UPLUS, URIGHT_SHIFT
 
Method Summary
static Constant bool(boolean b)
          Convenience function: Convert a boolean to Constant.True or Constant.False.
static Constant error(String msg)
          Convenience function: Create an ERROR constant containing a particular message.
static StringBuffer escapeString(StringBuffer sb, String s, char quote)
          Append to sb a quoted version of string, replacing non-printable values by backslash escapes.
protected  Expr eval1(Expr.Env env)
          Evaluate this Expr.
static Constant getInstance(char[] buf, int start, int stop)
          Create a String Constant from a character array, processing backslash escapes.
static Constant getInstance(Date value)
          Create an absolute time Constant.
static Constant getInstance(double value)
          Returns the unique real constant with value "value", creating one if necessary.
static Constant getInstance(int value)
          Returns the unique integer constant with value "value", creating one if necessary.
static Constant getInstance(long value)
          Returns the unique time constant with value "value", creating one if necessary.
static Constant getInstance(String value)
          Returns the unique String constant with value "value", creating one if necessary.
 int intValue()
          Get the integer value of this Constant if possible.
 boolean isTrue()
          Convenience function to test whether an expression is the constant TRUE.
 long milliseconds()
          Convert a time value to milliseconds.
(package private) static Date parseAbsTime(String s)
          Helper function for absTime(String).
(package private) static long parseRelTime(String s)
          Helper function for relTime(String).
 int prec()
          The precedence of this expression node (MAXPREC).
 double realValue()
          Get the double floating point value of this Constant if possible.
(package private) static String rel2str(long t)
          Format a relative time value as a readable String.
 String stringValue()
          Get the string value of this Constant if possible.
 StringBuffer toString(StringBuffer sb)
          Convert this Expr to a string, appending the result to the end of "sb".
static Constant undefined(String msg)
          Convenience function: Create an UNDEFINED constant containing a particular message.
(package private) static String unquoteString(char[] buf, int start, int stop)
          Generate a string from an array of characters, processing backslash escapes.
 
Methods inherited from class condor.classad.Expr
db, db, eval, eval, isConstant, selectExpr, subExpr, toString, typeName
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

public final Object value
The actual value of this Constant. Usage depends on type:
UNDEFINED
A String error message.
ERROR
A String error message.
BOOLEAN
null (there are only two Boolean Constants).
INTEGER
An Integer value.
REAL
A Double value.
STRING
A String value.
ABSOLUTE_TIME
A java.util.Date value.
RELATIVE_TIME
A Long value (number of milliseconds).


Undef

public static final Constant Undef
A default undefined constant


CyclicRef

public static final Constant CyclicRef
An undefined constant that represents the result a attempting to resovle a cyclic attribute reference as in [a=b;b=a].


Error

public static final Constant Error
A default error constant


True

public static final Constant True
The unique boolean constant true


False

public static final Constant False
The unique boolean Constant false

Method Detail

getInstance

public static final Constant getInstance(int value)
Returns the unique integer constant with value "value", creating one if necessary.

Parameters:
value - the value of the Constant.
Returns:
a new INTEGER constant.

getInstance

public static final Constant getInstance(double value)
Returns the unique real constant with value "value", creating one if necessary.

Parameters:
value - the value of the Constant.
Returns:
a new REAL constant.

getInstance

public static final Constant getInstance(String value)
Returns the unique String constant with value "value", creating one if necessary.

Parameters:
value - the value of the Constant, not including any surrounding quotes.
Returns:
a new STRING constant.

getInstance

public static final Constant getInstance(char[] buf,
                                         int start,
                                         int stop)
Create a String Constant from a character array, processing backslash escapes. Any surrounding quotes have already been stripped.

Parameters:
buf - the array of characters.
start - the index preceding the first character to be used.
stop - the index following the last characater to be used.
Returns:
a new STRING constant.

getInstance

public static final Constant getInstance(Date value)
Create an absolute time Constant.

Parameters:
value - the value of the Constant.
Returns:
a new ABSTIME constant.

getInstance

public static final Constant getInstance(long value)
Returns the unique time constant with value "value", creating one if necessary.

Parameters:
value - the value of the constant in milliseconds
Returns:
a new RELTIME constant.

eval1

protected Expr eval1(Expr.Env env)
Evaluate this Expr. This is the internal method used to implement Expr.eval().

Specified by:
eval1 in class Expr
Parameters:
env - an environment used to evaluate the operands. It is cleared to the null environment before return.
Returns:
this Constant.

toString

public StringBuffer toString(StringBuffer sb)
Convert this Expr to a string, appending the result to the end of "sb". The representation is the "canonical native format".

Specified by:
toString in class Expr
Parameters:
sb - a place to put the result.
Returns:
sb.
See Also:
ClassAdWriter

error

public static Constant error(String msg)
Convenience function: Create an ERROR constant containing a particular message.

Parameters:
msg - the message.
Returns:
the Constant.

undefined

public static Constant undefined(String msg)
Convenience function: Create an UNDEFINED constant containing a particular message.

Parameters:
msg - the message.
Returns:
the Constant.

bool

public static Constant bool(boolean b)
Convenience function: Convert a boolean to Constant.True or Constant.False.

Parameters:
b - the boolean value.
Returns:
the Constant.

intValue

public int intValue()
             throws ArithmeticException
Get the integer value of this Constant if possible.

Overrides:
intValue in class Expr
Returns:
the integer value of this IntegerConstant.
Throws:
ArithmeticException - if this Constant is not an integer.

realValue

public double realValue()
                 throws ArithmeticException
Get the double floating point value of this Constant if possible.

Overrides:
realValue in class Expr
Returns:
the real value of this RealConstant or the value of this IntegerConstant converted to double.
Throws:
ArithmeticException - if this Constant is not an instance of IntegerConstant or RealConstant.

stringValue

public String stringValue()
                   throws ArithmeticException
Get the string value of this Constant if possible.

Overrides:
stringValue in class Expr
Returns:
the string value of this StringConstant.
Throws:
ArithmeticException - if this Constant is not an instance of StringConstant.

isTrue

public boolean isTrue()
Convenience function to test whether an expression is the constant TRUE. Note that unlike inValue, etc., this method never throws an exception.

Overrides:
isTrue in class Expr
Returns:
true if this Expr is a constant of type boolean with value true, and false in all other cases.

milliseconds

public long milliseconds()
                  throws ArithmeticException
Convert a time value to milliseconds.

Returns:
the number of milliseconds (since 1/1/70 for ABSOLUTE_TIME values).
Throws:
ArithmeticException - if this Constant is not a time value.

prec

public int prec()
The precedence of this expression node (MAXPREC). Used to print expressions without superfluous parentheses.

Specified by:
prec in class Expr
Returns:
the precendence of this node.
See Also:
ClassAdWriter.MINIMAL_PARENTHESES

unquoteString

static final String unquoteString(char[] buf,
                                  int start,
                                  int stop)
Generate a string from an array of characters, processing backslash escapes. The the characters buf[start+1] ... buf[stop-1] are converted to a String, after replacing backslash escapes such as \n by their values.

Parameters:
buf - the array of characters.
start - the index of the first character to be used.
stop - the index following the last characater to be used.
Returns:
the converted String.

escapeString

public static StringBuffer escapeString(StringBuffer sb,
                                        String s,
                                        char quote)
Append to sb a quoted version of string, replacing non-printable values by backslash escapes. The result starts and ends with quote; any embedded occurrences of quote are preceded by backslashes. Any non-printing characters are escaped with a single-character escape (such as \n) if possible, otherwise \ooo, where ooo is a three-digit octal code.

Note that Unicode is not supported: We assume the value of every character is in the range 0..0377.

Parameters:
sb - a place to put the result.
s - the string to be quoted.
quote - the quote character (' or ").
Returns:
sb.

rel2str

static final String rel2str(long t)
Format a relative time value as a readable String. The result is a string of of the form days+hh:mm:ss.mmm, where leading components are omitted if they are zero. For example,

Parameters:
t - the number to be converted, in milliseconds.
Returns:
the resulting String.

parseRelTime

static long parseRelTime(String s)
Helper function for relTime(String). Convert a relative time pattern of the form days+hh:mm:ss[.msec] into a number of milliseconds.

Parameters:
s - the string to parse.
Returns:
a number of milliseconds, or -1 for errors.

parseAbsTime

static Date parseAbsTime(String s)
Helper function for absTime(String). Convert an absolute time pattern of the form yyyymmddThhmmss to a Date.

Parameters:
s - the string to parse.
Returns:
the corresponding Date, or null for errors.