no.sesat.search.query.parser
Class AbstractClause

java.lang.Object
  extended by no.sesat.search.query.parser.AbstractClause
All Implemented Interfaces:
Serializable, no.sesat.commons.visitor.Visitable, Clause
Direct Known Subclasses:
AbstractLeafClause, AbstractUnaryClause

public abstract class AbstractClause
extends Object
implements Clause

Basic implementation of the Clause interface. Provides basic implementation of the predicates lists, defaulting to empty lists. Also provides weak reference hashmaps to keep record and reuse the Clauses already in use in the JVM. Objects of this class are immutable

Version:
$Id: AbstractClause.java 7225 2009-04-09 00:32:20Z ssmiweve $
See Also:
Serialized Form

Field Summary
static no.sesat.commons.ref.ReferenceMap.Type DFAULT_REFERENCE_MAP_TYPE
           
protected static String ERR_FAILED_FINDING_OR_USING_CONSTRUCTOR
          Error message when reflection cannot find the required constructor.
protected static String ERR_MUST_ALWAYS_USE_ARGED_CONSTRUCTOR
          Error message when trying to use the incorrect constructor.
 
Constructor Summary
protected AbstractClause(String term, Set<TokenPredicate> knownPredicates, Set<TokenPredicate> possiblePredicates)
          Create clause with the given term, known and possible predicates.
 
Method Summary
 void accept(no.sesat.commons.visitor.Visitor visitor)
           
protected static
<T extends AbstractClause>
T
addClauseInUse(String key, T clause, no.sesat.commons.ref.ReferenceMap<String,T> weakCache)
          Note there is an identical and immutable Clause ready to use in the JVM.
protected static
<T extends AbstractClause>
T
findClauseInUse(String key, no.sesat.commons.ref.ReferenceMap<String,T> weakCache)
          See if there is an identical and immutable Clause already in use in the JVM.
protected static boolean findPredicates(TokenEvaluationEngine engine)
          Find the predicates that are applicable to the clause.
 Set<TokenPredicate> getKnownPredicates()
          Get the set of knownPredicates for this Clause.
 Set<TokenPredicate> getPossiblePredicates()
          Get the set of possiblePredicates for this Clause.
 String getTerm()
          Get the term for this Clause.
 int hashCode()
          Provide a replicatable hashCode so the same segment inside the ConcurrentHashMap is used for any accidently duplicate created clauses.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ERR_FAILED_FINDING_OR_USING_CONSTRUCTOR

protected static final String ERR_FAILED_FINDING_OR_USING_CONSTRUCTOR
Error message when reflection cannot find the required constructor.

See Also:
Constant Field Values

ERR_MUST_ALWAYS_USE_ARGED_CONSTRUCTOR

protected static final String ERR_MUST_ALWAYS_USE_ARGED_CONSTRUCTOR
Error message when trying to use the incorrect constructor.

See Also:
Constant Field Values

DFAULT_REFERENCE_MAP_TYPE

public static final no.sesat.commons.ref.ReferenceMap.Type DFAULT_REFERENCE_MAP_TYPE
Constructor Detail

AbstractClause

protected AbstractClause(String term,
                         Set<TokenPredicate> knownPredicates,
                         Set<TokenPredicate> possiblePredicates)
Create clause with the given term, known and possible predicates.

Parameters:
term - the term (query string) for this clause.
knownPredicates - the set of known predicates for this clause.
possiblePredicates - the set of possible predicates for this clause.
Method Detail

findClauseInUse

protected static final <T extends AbstractClause> T findClauseInUse(String key,
                                                                    no.sesat.commons.ref.ReferenceMap<String,T> weakCache)
See if there is an identical and immutable Clause already in use in the JVM.

Type Parameters:
T -
Parameters:
key - the unique (for this AbstractClause subtype) key for the Clause we are looking for.
weakCache - the map containing the key to WeakReference (of the Clause) mappings.
Returns:
the AbstractClause in use already, matching the key. May be null.

addClauseInUse

protected static final <T extends AbstractClause> T addClauseInUse(String key,
                                                                   T clause,
                                                                   no.sesat.commons.ref.ReferenceMap<String,T> weakCache)
Note there is an identical and immutable Clause ready to use in the JVM.

Type Parameters:
T -
Parameters:
key - the unique (for this AbstractClause subtype) key for the Clause we are about to add to the mappings.
clause - the Clause we are about to add to the mappings.
weakCache - the map containing the key to WeakReference (of the Clause) mappings.
Returns:
If the weakCache contained an clause for the key, then this is returned. Otherwise the clasue entered as a parameter is returned.

findPredicates

protected static final boolean findPredicates(TokenEvaluationEngine engine)
Find the predicates that are applicable to the clause. (Only the clause's term is known and is kept in state inside the TokenEvaluationEngine). Add known predicates to knownPredicates. Add possible (requires further checking against the whole query heirarchy) predicates to possiblePredicates.

Parameters:
engine - the factory handing out evaluators against TokenPredicates. Also holds state information about the current term/clause we are finding predicates against. to the current clause we are finding predicates for.
Returns:

getTerm

public String getTerm()
Get the term for this Clause. Does not include any field values (eg "firstname:").

Specified by:
getTerm in interface Clause
Returns:
the term for this clause.

getKnownPredicates

public Set<TokenPredicate> getKnownPredicates()
Get the set of knownPredicates for this Clause. The set is unmodifiable.

Specified by:
getKnownPredicates in interface Clause
Returns:
set of knownPredicates.

getPossiblePredicates

public Set<TokenPredicate> getPossiblePredicates()
Get the set of possiblePredicates for this Clause. The set is unmodifiable.

Specified by:
getPossiblePredicates in interface Clause
Returns:
set of possiblePredicates.

accept

public void accept(no.sesat.commons.visitor.Visitor visitor)
Specified by:
accept in interface no.sesat.commons.visitor.Visitable

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Provide a replicatable hashCode so the same segment inside the ConcurrentHashMap is used for any accidently duplicate created clauses. The ConcurrentHashMap is used in this package's implementation of the flyweight pattern. It is intended for equals(..) to use instance reference equality, ie Object.equals(..).

Overrides:
hashCode in class Object
Returns:


Copyright © 2005-2009 Schibsted ASA. All Rights Reserved.