condor.classad
Class Constant

Object
  extended bycondor.classad.Expr
      extended bycondor.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.1
Author:
Marvin Solomon
See Also:
Expr

Nested Class Summary
 
Nested classes inherited from class condor.classad.Expr
Expr.Env
 
Field Summary
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, 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
 String annotation()
          Returns the annotation of an UNDEFINED or ERROR value.
static Constant bool(boolean b)
          Convenience function that converts a boolean to Constant.TRUE or Constant.FALSE.
 boolean booleanValue()
          Gets the boolean value of this Constant if possible.
(package private) static String doubleToString(double d)
          Converts a double value to a String.
static Constant error(String msg)
          Convenience function that creates an ERROR constant containing a particular message.
(package private) static StringBuffer escapeString(StringBuffer sb, String s, char quote)
          Appends to sb a quoted version of string, replacing non-printable values by backslash escapes.
protected  Expr eval1(Expr.Env env)
          Evaluates this Expr.
static Constant getInstance(boolean value)
          Returns the boolean constant with value "value", creating one if necessary.
static Constant getInstance(char[] buf, int start, int stop)
          Creates a String Constant from a character array, processing backslash escapes.
static Constant getInstance(Date date)
          Returns the unique absolute time constant corresponding to date "date", in the local timezone, creating one if necessary.
static Constant getInstance(Date date, int tz)
          Returns the unique absolute time constant corresponding to date "date", in the indicated timezone, creating one if necessary.
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 relative time constant with value "value", creating one if necessary.
static Constant getInstance(long t, int z)
          Returns the unique absolute time constant with time "t" and offset "z", creating one if necessary.
static Constant getInstance(String value)
          Returns the unique String constant with value "value", creating one if necessary.
 int intValue()
          Gets the integer value of this Constant if possible.
 boolean isTrue()
          Convenience function to test whether an expression is the constant TRUE.
 long milliseconds()
          Converts a time value to milliseconds.
 int prec()
          The precedence of this expression node (MAXPREC).
 double realValue()
          Gets the double floating point value of this Constant if possible.
(package private) static String relTimeToString(long t)
          Converts a number of milliseconds to a string representation of a relative time.
static Constant stringToAbsTime(String s)
          Parses an absolute time specification.
(package private) static double stringToDouble(String s)
          Parses a string representation of a real value.
static Constant stringToRelTime(String s)
          Parses a relative time specification.
 String stringValue()
          Gets the string value of this Constant if possible.
 StringBuffer toString(StringBuffer sb)
          Converts this Expr to a string, appending the result to the end of "sb".
static Constant undefined(String msg)
          Convenience function that creates an UNDEFINED constant containing a particular message.
(package private) static String unquoteString(char[] buf, int start, int stop)
          Generates a string from an array of characters, processing backslash escapes.
(package private) static String unquoteString(String s)
          Process backslash escapes in a string.
 int zone()
          Returns the time zone of an absolute time value.
 
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

Undef

public static final Constant Undef
A default undefined constant.


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.


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 Timestamp value (milliseconds since the epoch and seconds east of Greenwich)
RELATIVE_TIME
A Long value (number of milliseconds).

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(boolean value)
Returns the boolean constant with value "value", creating one if necessary. Equivalent to bool(value).

Parameters:
value - the length of the time interval in milliseconds
Returns:
Constant.TRUE or Constant.FALSE
See Also:
bool(boolean)

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)
Creates 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, or null for errors.

getInstance

public static final Constant getInstance(Date date)
Returns the unique absolute time constant corresponding to date "date", in the local timezone, creating one if necessary.

Parameters:
date - the date.
Returns:
a new ABSTIME constant.

getInstance

public static final Constant getInstance(Date date,
                                         int tz)
Returns the unique absolute time constant corresponding to date "date", in the indicated timezone, creating one if necessary.

Parameters:
date - the date.
tz - the timezone, as a number of seconds east of Greenwich.
Returns:
a new ABSTIME constant.

getInstance

public static final Constant getInstance(long t,
                                         int z)
Returns the unique absolute time constant with time "t" and offset "z", creating one if necessary.

Parameters:
t - offset from the epoch, in milliseconds.
z - seconds east of Greenwich, in seconds.
Returns:
a new ABSTIME constant.

getInstance

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

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

error

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

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

undefined

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

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

bool

public static Constant bool(boolean b)
Convenience function that converts a boolean to Constant.TRUE or Constant.FALSE. Equivalent to getInstance(b).

Parameters:
b - the boolean value.
Returns:
the Constant.
See Also:
getInstance(boolean)

eval1

protected Expr eval1(Expr.Env env)
Evaluates 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.

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

toString

public StringBuffer toString(StringBuffer sb)
Converts this Expr to a string, appending the result to the end of "sb". The representation is the "canonical native format".
Undefined
"UNDEFINED"
Error
"ERROR"
Boolean
"true" or "false"
Integer
[-]d+
Real
[-]d.d+Ed+ or 0, -0, INF, -INF, NaN
String
'"'.*'"'
AbsTime
absTime("yyyy-mm-ddThh:mm:ss[+-]zz:zz")
RelTime
relTime("[-]days+hh:mm:ss.fff")

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

intValue

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

Overrides:
intValue in class Expr
Returns:
the integer value of this Constant.
Throws:
ArithmeticException - if type != INTEGER.

realValue

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

Overrides:
realValue in class Expr
Returns:
the real value of this Constant converted to double.
Throws:
ArithmeticException - if type != INTEGER and type != REAL.

stringValue

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

Overrides:
stringValue in class Expr
Returns:
the String value of this Constant.
Throws:
ArithmeticException - if type != STRING.

booleanValue

public boolean booleanValue()
                     throws ArithmeticException
Gets the boolean value of this Constant if possible.

Returns:
the boolean value of this Constant.
Throws:
ArithmeticException - if TYPE != BOOLEAN.
See Also:
isTrue()

isTrue

public boolean isTrue()
Convenience function to test whether an expression is the constant TRUE. Note that unlike booleanValue(), 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.
See Also:
booleanValue()

milliseconds

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

Returns:
the number of milliseconds (RELATIVE_TIME) or the number of milliseconds since 1970-01-01 UTC (ABSOLUTE_TIME).
Throws:
ArithmeticException - if this Constant is not a time value.

zone

public int zone()
         throws ArithmeticException
Returns the time zone of an absolute time value.

Returns:
the zone, in seconds east of Greenwich
Throws:
ArithmeticException - if type != ABSOLUTE_TIME.

annotation

public String annotation()
                  throws ArithmeticException
Returns the annotation of an UNDEFINED or ERROR value.

Returns:
the annotation.
Throws:
ArithmeticException - if type != ERROR and type != UNDEFINED.

doubleToString

static final String doubleToString(double d)
Converts a double value to a String. The canonical unparsing of a real literal is one of the strings INF, -INF, or NaN, or a normalized "scientific" representation such as 6.020000000000000E+24, or -0.000000000000000E+00, as produced by the C printf format "%1.15E": an optional leading minus sign, one digit before the decimal point (which must be non-zero unless the value is plus or minus zero), 15 digits following the decimal point, the letter 'E', a (mandatory) sign, and exponent of at least two digits.

Parameters:
d - the value to convert.
Returns:
a String representation of d.

stringToDouble

static final double stringToDouble(String s)
Parses a string representation of a real value. The string may be any of the specific strings INF, -INF, or Nan in any combination of upper and lower case, or any string that can be handled by Double.parseDouble.

Parameters:
s - the string to parse.
Returns:
the corresponding double value.
Throws:
NumberFormatException - if s cannot be parsed.

unquoteString

static final String unquoteString(char[] buf,
                                  int start,
                                  int stop)
Generates 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, or null on errors.

unquoteString

static final String unquoteString(String s)
Process backslash escapes in a string.

Parameters:
s - the string to be processed.
Returns:
the converted String, or null on errors.

escapeString

static StringBuffer escapeString(StringBuffer sb,
                                 String s,
                                 char quote)
Appends 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.

relTimeToString

static final String relTimeToString(long t)
Converts a number of milliseconds to a string representation of a relative time. The result is a string of the form [-]days+hh:mm:ss.fff, where leading components and the fraction .fff are omitted if they are zero. There is no provision for leap seconds (each minute is assumed to be 60 seconds). For example,

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

stringToRelTime

public static Constant stringToRelTime(String s)
Parses a relative time specification. This method accepts strings generated by relTimeToString(long), but also accepts minor variations in format.

The default format is [-]days+hh:mm:ss.fff, where leading components and the fraction .fff are omitted if they are zero. In the default syntax, days is a sequence of digits starting with a non-zero digit, hh, mm, and ss are strings of exactly two digits (padded on the left with zeros if necessary) with values less than 24, 60, and 60, respectively and fff is a string of exactly three digits. In the relaxed syntax,

For example, one day, two minutes and three milliseconds may have any of the forms

Parameters:
s - the string to parse.
Returns:
a RelTime constant or an Error constant.

stringToAbsTime

public static Constant stringToAbsTime(String s)
Parses an absolute time specification. This method accepts strings generated by Timestam.toString(), but also accepts minor variations in format.

The default format is yyyy-mm-ddThh:mm:sszzzzzz where zzzzzz is a time zone in the format +hh:mm or -hh:mm, but variations are allowed.

More precisely, the string must match the regular expression
  D* dddd [D* dd [D* dd [D* dd [D* dd [D* dd D*]]]]] [-dd:dd|+dd:dd|z|Z]
 
Where 'd' stands for a digit and 'D' stands for a non-digit.

For example, in the United States central time zone, the date and time 9 am Jan 25, 2003 CST may be written in any of the forms

2003-01-25T09:00:00-06:00
output of Timestamp.toString()
2003-01-25 09:00:00 -0600
different separators
20030125090000-0600
compact format
2003-01-25 16:00:00 +0100
different time zone
2003-01-25 15:00Z
omitted seconds, UTC time zone
2003-01-25 09:00:00
default time zone (local)
2003-01-25 09
omitted minutes and seconds
and the date Jan 25, 2003 (implcitly midnight, UTC) may be written
2003-01-24T18:00:00-0600
output of Timestamp.toString()
2003-01-25T00:00:00
default time zone: UTC
2003-01-25
omitted time of day
2003/01/25
different separators
20030125
compact format
The following strings are invalid.
2003-01-25T09:00:00-06
incomplete time zone
2003-01-25T09:00:00- 0600
space in time zone
2003-1-25
missing digit in dd field

Parameters:
s - the string to parse.
Returns:
an AbsTime constant or an Error constant.