Author: akarasulu
Date: Thu Sep 30 15:38:15 2004
New Revision: 47612
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
Log:
more javadocs
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
Thu Sep 30 15:38:15 2004
@@ -148,12 +148,14 @@
/**
+ * Creates an enumeration over a disjunction expression branch node.
*
+ * @param node the disjunction expression branch node
*/
- public NamingEnumeration enumDisj( ExprNode node ) throws NamingException
+ private NamingEnumeration enumDisj( BranchNode node ) throws
NamingException
{
- ArrayList children = ( ( BranchNode ) node ).getChildren();
- NamingEnumeration [] childEnumerations = new NamingEnumeration
[children.size()];
+ ArrayList children = node.getChildren();
+ NamingEnumeration[] childEnumerations = new NamingEnumeration
[children.size()];
// Recursively create NamingEnumerations for each child expression node
for ( int ii = 0; ii < childEnumerations.length; ii++ )
@@ -166,7 +168,9 @@
/**
+ * Creates an enumeration over a negation expression branch node.
*
+ * @param node a negation expression branch node
*/
private NamingEnumeration enumNeg( final BranchNode node ) throws
NamingException
{
@@ -206,7 +210,9 @@
/**
+ * Creates an enumeration over a conjunction expression branch node.
*
+ * @param node a conjunction expression branch node
*/
private NamingEnumeration enumConj( final BranchNode node ) throws
NamingException
{
Modified:
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
==============================================================================
---
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
(original)
+++
incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
Thu Sep 30 15:38:15 2004
@@ -39,8 +39,14 @@
private LeafEvaluator leafEvaluator;
+ // ------------------------------------------------------------------------
+ // C O N S T R U C T O R S
+ // ------------------------------------------------------------------------
+
+
/**
- * Creates a top level Evaluator where leaves are delegated.
+ * Creates a top level Evaluator where leaves are delegated to a leaf node
+ * evaluator which is already provided.
*
* @param leafEvaluator handles leaf node evaluation.
*/
@@ -51,36 +57,60 @@
/**
- * @see org.apache.eve.db.Evaluator#evaluate(ExprNode, IndexRecord)
+ * Creates a top level Evaluator where leaves are delegated to a leaf node
+ * evaluator which will be created.
+ *
+ * @param db the database this evaluator operates upon
+ * @param normalizerRegistry the normalizer reg used for value
normalization
+ * @param comparatorRegistry the comparator reg used for value comparison
*/
- public boolean evaluate( ExprNode node, IndexRecord record )
- throws NamingException
+ public ExpressionEvaluator( Database db,
+ NormalizerRegistry normalizerRegistry,
+ ComparatorRegistry comparatorRegistry )
{
- if ( node.isLeaf() )
- {
- return leafEvaluator.evaluate( node, record );
- }
+ ScopeEvaluator scopeEvaluator = null;
+ SubstringEvaluator substringEvaluator = null;
- return evaluateBranch( ( BranchNode ) node, record );
+ scopeEvaluator = new ScopeEvaluator( db );
+ substringEvaluator = new SubstringEvaluator( db, normalizerRegistry );
+ leafEvaluator = new LeafEvaluator( db, scopeEvaluator,
+ normalizerRegistry, comparatorRegistry, substringEvaluator );
}
/**
- * Evaluates a BranchNode on an candidate entry using an IndexRecord on the
- * entry.
+ * Gets the leaf evaluator used by this top level expression evaluator.
*
- * @param node the branch node to evaluate
- * @param record the index record for the entry
- * @return true if the entry should be returned false otherwise
- * @throws NamingException if there is a failure while accessing the db
+ * @return the leaf evaluator used by this top level expression evaluator
+ */
+ public LeafEvaluator getLeafEvaluator()
+ {
+ return leafEvaluator;
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Evaluator.evaluate() implementation
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * @see org.apache.eve.db.Evaluator#evaluate(ExprNode, IndexRecord)
*/
- boolean evaluateBranch( BranchNode node, IndexRecord record )
+ public boolean evaluate( ExprNode node, IndexRecord record )
throws NamingException
{
- switch( node.getOperator() )
+ if ( node.isLeaf() )
+ {
+ return leafEvaluator.evaluate( node, record );
+ }
+
+ BranchNode bnode = ( BranchNode ) node;
+
+ switch( bnode.getOperator() )
{
case( BranchNode.OR ):
- Iterator children = node.getChildren().iterator();
+ Iterator children = bnode.getChildren().iterator();
while ( children.hasNext() )
{
@@ -94,7 +124,7 @@
return false;
case( BranchNode.AND ):
- children = node.getChildren().iterator();
+ children = bnode.getChildren().iterator();
while ( children.hasNext() )
{
ExprNode child = ( ExprNode ) children.next();
@@ -107,38 +137,15 @@
return true;
case( BranchNode.NOT ):
- if ( null != node.getChild() )
+ if ( null != bnode.getChild() )
{
- return ! evaluate( node.getChild(), record );
+ return ! evaluate( bnode.getChild(), record );
}
throw new NamingException( "Negation has no child: " + node );
default:
throw new NamingException( "Unrecognized branch node operator: "
- + node.getOperator() );
+ + bnode.getOperator() );
}
- }
-
-
- public LeafEvaluator getLeafEvaluator()
- {
- return leafEvaluator;
- }
-
-
- public static ExpressionEvaluator create( Database db,
- NormalizerRegistry normReg,
- ComparatorRegistry compReg )
- {
- LeafEvaluator leafEvaluator = null;
- ScopeEvaluator scopeEvaluator = null;
- SubstringEvaluator substringEvaluator = null;
-
- scopeEvaluator = new ScopeEvaluator( db );
- substringEvaluator = new SubstringEvaluator( db, normReg );
- leafEvaluator = new LeafEvaluator( db, scopeEvaluator, normReg,
- compReg, substringEvaluator );
-
- return new ExpressionEvaluator( leafEvaluator );
}
}