condor.classad
Class AttrName

Object
  extended bycondor.classad.AttrName

public class AttrName
extends Object

An attribute name. It behaves like a String except for its equals and hashCode methods, which ignore case. In simple cases, the string is an identifier (a sequence of letters and digits starting with a letter), but in fact, it may contain arbitrary ASCII characters. If it is not a simple identifier, it is displayed surrounded by single quotes (apostrophes) with backslash escapes for unprintable characters and quotes.

The implementation stores the string in two or three forms, the "raw" form, which is the actual sequence of characters, the "canon" form, which is the raw form translated to lower case, and the "pname" form which is the raw form escaped and quoted if necessary to fit the native syntax for an "Identifier". The pname is generated on demand in toString() and cached.

In any one execution, there is only one instance with a given "raw" string. The contructor is private, and instances are created by the factory methods fromString(String), which accepts the "raw" form of the string, and fromText(String), which accepts a version with optional quotes and backslash escapes. For example, fromString("foo") and fromText("foo") return the same instance of AttrName, as do fromString("one two\nthree") and fromText("'one two\\012three'").

The raw and canon strings are "interned" to save space and to speed up comparisons: The equals(Object) method simply compares canon strings for pointer equality.

Version:
2.1
Author:
Marvin Solomon
See Also:
AttrRef

Field Summary
(package private) static AttrName PARENT
          The reseved word PARENT.
 
Method Summary
 boolean equals(Object o)
          Compare this AttrName to another AttrName.
static AttrName fromString(String v)
          Returns the instance corresponding to a given raw String.
static AttrName fromText(String v)
          Returns the instance corresponding to a given NATIVE representation.
 int hashCode()
          Compute a hash code for this string.
 boolean needsQuoting()
          Checks to see whether this AttrName needs to be quoted.
 String rawString()
          Returns the original string without quotes or escapes and original capitalization.
 String toString()
          Converts to a printable String.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PARENT

static final AttrName PARENT
The reseved word PARENT.

Method Detail

toString

public String toString()
Converts to a printable String. The "raw" value is returned as is if it has the form an identifier; otherwise, it is quoted and escaped.

Returns:
a printable version of this AttrName.

needsQuoting

public boolean needsQuoting()
Checks to see whether this AttrName needs to be quoted.

Returns:
false if rawString() matches the syntax of an identifier.

rawString

public String rawString()
Returns the original string without quotes or escapes and original capitalization.

Returns:
the original string.

equals

public boolean equals(Object o)
Compare this AttrName to another AttrName. Since there is a unique instance for any canonicalized value, the comparison is simply pointer equality.

Parameters:
o - the other AttrName
Returns:
true if the strings are equal, ignoring case.
Throws:
ClassCastException - if o is not an instance of AttrName.
NullPointerException - if o is null.

hashCode

public int hashCode()
Compute a hash code for this string. Strings that are equal except for case return the same hash code.

Returns:
the hash code.

fromText

public static AttrName fromText(String v)
Returns the instance corresponding to a given NATIVE representation.

Parameters:
v - the NATIVE representation.
Returns:
the corresponding AttrName instance, or null on errors.

fromString

public static AttrName fromString(String v)
Returns the instance corresponding to a given raw String.

Parameters:
v - the original (mixed case) string.
Returns:
the corresponding AttrName instance, or null on errors.