Author: ssmiweve
Date: 2008-04-02 12:54:11 +0200 (Wed, 02 Apr 2008)
New Revision: 6329

Modified:
   
branches/2.16/query-api/src/main/java/no/sesat/search/query/token/TokenPredicate.java
Log:
SEARCH-4421 - Anonymous TokenPredicates
 Documentation.

Modified: 
branches/2.16/query-api/src/main/java/no/sesat/search/query/token/TokenPredicate.java
===================================================================
--- 
branches/2.16/query-api/src/main/java/no/sesat/search/query/token/TokenPredicate.java
       2008-04-02 10:15:17 UTC (rev 6328)
+++ 
branches/2.16/query-api/src/main/java/no/sesat/search/query/token/TokenPredicate.java
       2008-04-02 10:54:11 UTC (rev 6329)
@@ -60,15 +60,15 @@
         }
     }
 
-    /**
+    /** The name of the TokenPredicate. Must be uppercase. Must be unique 
across all skins.
      * 
-     * @return
+     * @return TokenPredicate name.
      */
     String name();
 
-    /**
+    /** The type of the TokenPredicate. TokenEvaluationEngine will use this to 
determine which TokenEvaluator to use.
      *
-     * @return
+     * @return the type
      */
     Type getType();
     
@@ -85,6 +85,10 @@
      *         TokTokenEvaluationEngineastListName evaluates to true.
      */
     boolean evaluate(Object evalFactory);
+    
+    
+    
+    // Inner Classes -----------------------------------------------------
 
     /** A formalised breakdown of metadata categories that search terms can 
match.
      *
@@ -93,11 +97,6 @@
      */
     enum Categories implements TokenPredicate {
 
-        // Common predicates.
-
-        /** @deprecated this is silly. there are better ways to accomplish 
this, eg enrichment's baseScore. */
-        //ALWAYSTRUE (Type.GENERIC),
-
         // Categorical TokenPredicates
         // TODO make ExactFast tokens a separate Type referencing the original 
Fast token. SEARCH-4408.
         // TODO determine type automatically. skins maybe choose an 
alternative type. SEARCH-3540.
@@ -421,7 +420,7 @@
         /** JepTokenPredicate. **/
         MATHPREDICATE (Type.JEP);
 
-        // instance fields
+        // implementation to delegate to
         private final TokenPredicateImpl impl;
 
         /**
@@ -430,7 +429,7 @@
          *
          * @param type     the fastListName type.
          */
-        Categories(final Type type) {
+        private Categories(final Type type) {
 
             this.impl = new TokenPredicateImpl(name(), type);
             // replace impl's entry with myself
@@ -453,23 +452,38 @@
 
     }
 
+    /** The default implementation used. Should not be used directly.
+     * The Categories enumerations delegated to this class.
+     * The anonymous TokenPredicates are instances of this class.
+     */
     static class TokenPredicateImpl implements TokenPredicate{
 
+        // Constants -----------------------------------------------------
+        
         private static final String ERR_ARG_NOT_TOKEN_EVALUATOR_FACTORY
                 = "Argument to evaluate must be an instance of a 
TokenEvaluationEngine";
         private static final String ERR_METHOD_CLOSED_TO_OTHER_THREADS
                 = "TokenPredicate.evaluate(..) can only be used by same thread 
that created TokenEvaluationEngine!";
         private static final String ERR_ENGINE_MISSING_STATE = 
"TokenEvaluationEngine must have state assigned";
         
-        private static final Set<TokenPredicate> TOKENS = new 
CopyOnWriteArraySet<TokenPredicate>();
-        private static final Set<TokenPredicate> MAGIC_TOKENS = new 
CopyOnWriteArraySet<TokenPredicate>(); // TODO take out of sesat
-        private static final Set<TokenPredicate> TRIGGER_TOKENS = new 
CopyOnWriteArraySet<TokenPredicate>(); // TODO take out of sesat
-        private static final Map<Type,Set<TokenPredicate>> TOKENS_BY_TYPE = 
new ConcurrentHashMap<Type,Set<TokenPredicate>>();
+        private static final Set<TokenPredicate> TOKENS 
+                = new CopyOnWriteArraySet<TokenPredicate>();
+        private static final Map<Type,Set<TokenPredicate>> TOKENS_BY_TYPE 
+                = new ConcurrentHashMap<Type,Set<TokenPredicate>>();
+       
+        /** @deprecated todo take out of sesat. **/
+        private static final Set<TokenPredicate> MAGIC_TOKENS = new 
CopyOnWriteArraySet<TokenPredicate>();
+        /** @deprecated todo take out of sesat. **/
+        private static final Set<TokenPredicate> TRIGGER_TOKENS = new 
CopyOnWriteArraySet<TokenPredicate>();
         
+        // Attributes -----------------------------------------------------
+        
         private final String name;
         private final Type type;
 
-        public TokenPredicateImpl(final String name, final Type type){
+        // Constructors -----------------------------------------------------
+        
+        private TokenPredicateImpl(final String name, final Type type){
             this.name = name;
             this.type = type;
 
@@ -488,6 +502,8 @@
             TOKENS_BY_TYPE.get(type).add(this);
         }
 
+        // TokenPredicate implementation ------------------------------------
+        
         public String name(){
             return name;
         }
@@ -501,7 +517,9 @@
             return TokenPredicateImpl.evaluate(this, evalFactory);
         }
         
-        public static boolean evaluate(final TokenPredicate token, final 
Object evalFactory) {
+        // private -----------------------------------------------------   
+        
+        private static boolean evaluate(final TokenPredicate token, final 
Object evalFactory) {
 
             // pre-condition checks
             if (! (evalFactory instanceof TokenEvaluationEngine)) {
@@ -553,6 +571,8 @@
 
     }
 
+    /** Runtime exception thrown when evaluation fails.
+     */
     static final class EvaluationException extends RuntimeException{
         public EvaluationException(final VeryFastListQueryException vflqe){
             super(vflqe);
@@ -560,7 +580,8 @@
     }
     
 
-    /** @todo move out to TokenPredicateUtility. **/
+    /** Utility class providing all useful static methods around 
TokenPredicates.
+     * @todo move out to TokenPredicateUtility. **/
     static final class Static{
 
         private static final Map<String,TokenPredicate> ANONYMOUS_TOKENS = new 
ConcurrentHashMap<String,TokenPredicate>();
@@ -571,20 +592,20 @@
             Categories.values();
         }
 
-        /**
+        /** Find a TokenPredicate that's already created.
          *
-         * @param name
-         * @return null if no such a TokenPredicate exists.
+         * @param name the name of the TokenPredicate to find.
+         * @return the TokenPredicate.
          */
         public static TokenPredicate getTokenPredicate(final String name){
 
             return null != Categories.valueOf(name) ? Categories.valueOf(name) 
: getAnonymousTokenPredicate(name);
         }
 
-        /**
+        /** Find a anonymous TokenPredicate that's already created.
          *
-         * @param name
-         * @return
+         * @param name the name of the TokenPredicate to find.
+         * @return the anonymous TokenPredicate.
          */
         public static TokenPredicate getAnonymousTokenPredicate(final String 
name){
 
@@ -593,10 +614,11 @@
 
         /** Creates an anonymous TokenPredicate.
          * Ensure the name doesn't clash with anonymous TokenPredicates from 
other skins.
+         * Existing anonymous TokenPredicate with the same name will be 
replaced.
          *
-         * @param name
-         * @param type
-         * @return
+         * @param name the TokenPredicate name
+         * @param type the TokenPredicate type
+         * @return the newly created anonymous TokenPredicate
          */
         public static TokenPredicate createAnonymousTokenPredicate(final 
String name, final Type type){
 
@@ -605,7 +627,7 @@
         }
 
         /** Utility method to use all TokenPredicates in existence.
-         * @return
+         * @return set of all TokenPredicates. will not return instances that 
are delegates for Categories.
          */
         public static Set<TokenPredicate> getTokenPredicates() {
 
@@ -613,24 +635,24 @@
         }
 
         /** Utility method to use all TokenPredicates belonging to a given 
type.
-         * @param type
-         * @return
+         * @param type the given type
+         * @return set of all TokenPredicates with given type.
          */
         public static Set<TokenPredicate> getTokenPredicates(final Type type) {
             return 
Collections.unmodifiableSet(TokenPredicateImpl.TOKENS_BY_TYPE.get(type));
         }
 
         /** Utility method to use all MagicTokenPredicates in existence.
-         * @return
-         * @deprecated
+         * @return set of all MagicTokenPredicates
+         * @deprecated to be moved out of sesat
          */
         public static Set<TokenPredicate> getMagicTokenPredicates() {
             return 
Collections.unmodifiableSet(TokenPredicateImpl.MAGIC_TOKENS);
         }
 
         /** Utility method to use all TriggerTokenPredicates in existence.
-         * @return
-         * @deprecated
+         * @return set of all TriggerTokenPredicates
+         * @deprecated to be moved out of sesat
          */
         public static Set<TokenPredicate> getTriggerTokenPredicates() {
             return 
Collections.unmodifiableSet(TokenPredicateImpl.TRIGGER_TOKENS);

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to