public abstract class Expression
extends java.lang.Object
implements java.io.Serializable
By making it immutable, it becomes possible to share subexpressions among expressions. This is very important for regular-expression-derivation based validation algorithm, as well as for smaller memory footprint. This sharing is automatically achieved by ExpressionPool.
ReferebceExp, ElementExp, and OtherExp are also placed in the pool, but these are not unified. Since they are not unified, application can derive classes from these expressions and mix them into AGM. This technique is heavily used to introduce schema language specific primitives into AGM. See various sub-packages of this package for examples.
The equals method must be implemented by the derived type. equals method will be used to unify the expressions. equals method can safely assume that its children are already unified (therefore == can be used to test the equality, rather than equals method).
To achieve unification, we overload the equals method so that
o1.equals(o2)
is true if o1 and o2 are identical.
There, those two objects must return the same hash code. For this purpose,
the hash code is calculated statically and cached internally.
Modifier and Type | Class and Description |
---|---|
private static class |
Expression.AnyStringExpression |
private static class |
Expression.EpsilonExpression |
private static class |
Expression.NullSetExpression |
Modifier and Type | Field and Description |
---|---|
static Expression |
anyString
special expression object that represents "any string".
|
private int |
cachedHashCode
Hash code of this object.
|
static Expression |
epsilon
Special expression object that represents epsilon (ε).
|
private java.lang.Boolean |
epsilonReducibility
cached value of epsilon reducibility.
|
private Expression |
expandedExp
Cached value of the expression after ReferenceExps are removed.
|
static Expression |
nullSet
special expression object that represents the empty set (Φ).
|
private static long |
serialVersionUID |
java.lang.Object |
verifierTag
this field can be used by Verifier implementation to speed up
validation.
|
Modifier | Constructor and Description |
---|---|
protected |
Expression()
this constructor can be used for the ununified expressions.
|
protected |
Expression(int hashCode) |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
calcEpsilonReducibility()
computes epsilon reducibility
|
protected abstract int |
calcHashCode()
Computes the hashCode again.
|
abstract boolean |
equals(java.lang.Object o) |
Expression |
getExpandedExp(ExpressionPool pool)
Gets the expression after removing all ReferenceExps, until child
AttributeExp or ElementExp.
|
int |
hashCode() |
protected static int |
hashCode(java.lang.Object o,
int hashKey) |
protected static int |
hashCode(java.lang.Object o1,
java.lang.Object o2,
int hashKey) |
boolean |
isEpsilonReducible()
returns true if this expression accepts empty sequence.
|
Expression |
peelOccurence()
Peels the occurence expressions from this expression.
|
protected java.lang.Object |
readResolve() |
private void |
setHashCode(int hashCode) |
abstract java.lang.Object |
visit(ExpressionVisitor visitor) |
abstract boolean |
visit(ExpressionVisitorBoolean visitor) |
abstract Expression |
visit(ExpressionVisitorExpression visitor) |
abstract void |
visit(ExpressionVisitorVoid visitor) |
java.lang.Object |
visit(RELAXExpressionVisitor visitor) |
boolean |
visit(RELAXExpressionVisitorBoolean visitor) |
Expression |
visit(RELAXExpressionVisitorExpression visitor) |
void |
visit(RELAXExpressionVisitorVoid visitor) |
private java.lang.Boolean epsilonReducibility
private Expression expandedExp
public transient java.lang.Object verifierTag
private transient int cachedHashCode
To memorize every sub expression, hash code is frequently used. And computation of the hash code requires full-traversal of the expression. Therefore, hash code is computed when the object is constructed, and kept cached thereafter.
This field is essentially final, but because of the serialization support, we cannot declare it as such.
public static final Expression epsilon
public static final Expression nullSet
public static final Expression anyString
This object is used as <anyString/> pattern of TREX and <text/> pattern of RELAX NG.
private static final long serialVersionUID
protected Expression(int hashCode)
protected Expression()
public boolean isEpsilonReducible()
If this method is called while creating Expressions, then this method may return approximated value. When this method is used while validation, this method is guaranteed to return the correct value.
protected abstract boolean calcEpsilonReducibility()
public Expression getExpandedExp(ExpressionPool pool)
public final Expression peelOccurence()
In AGM, 'X?','X+' and 'X*' are represented by using other primitives. This method returns the 'X' part by removing occurence related expressions.
public abstract java.lang.Object visit(ExpressionVisitor visitor)
public abstract Expression visit(ExpressionVisitorExpression visitor)
public abstract boolean visit(ExpressionVisitorBoolean visitor)
public abstract void visit(ExpressionVisitorVoid visitor)
public java.lang.Object visit(RELAXExpressionVisitor visitor)
public Expression visit(RELAXExpressionVisitorExpression visitor)
public boolean visit(RELAXExpressionVisitorBoolean visitor)
public void visit(RELAXExpressionVisitorVoid visitor)
public final int hashCode()
hashCode
in class java.lang.Object
private final void setHashCode(int hashCode)
protected abstract int calcHashCode()
This method and the parameter to the constructor has to be the same. This method is used when the object is being read from the stream.
public abstract boolean equals(java.lang.Object o)
equals
in class java.lang.Object
protected static int hashCode(java.lang.Object o1, java.lang.Object o2, int hashKey)
protected static int hashCode(java.lang.Object o, int hashKey)
protected java.lang.Object readResolve()