Ignore:
Timestamp:
2004-12-10T15:48:39+13:00 (19 years ago)
Author:
schweer
Message:

started to work on multi-valued predicates; started to rework the filter algorithm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java

    r8738 r8777  
    2727    private static int id = 0;
    2828   
    29     // documentID -> IdEqualsPredicate referring to it
    30     private static Map documentIdEqualsPredicates = new TreeMap();
    31     // collectionID -> IdEqualsPredicate referring to it
    32     private static Map collectionIdEqualsPredicates = new TreeMap();
     29    private static Map idEqualsPredicates = new TreeMap();
    3330   
    34     // substring for collection_name -> SubstringMatchPredicate referring to it
     31    // substring for collection_name -> SubstringMatchPredicates referring to it
    3532    private static Map collectionNameMatchPredicates = new TreeMap();
    3633   
     
    5956        }
    6057       
    61         if (key.equals("type")) {
    62             return result;
    63         } else if (key.endsWith("ID")) {
    64             result = createIdEqualsPredicate(key, value);
     58        if (Predicate.isMultiValued(key)) {
     59            List list = new ArrayList();
     60            list.add(value);
     61            return createPredicate(key, list);
    6562        } else if (key.startsWith("document")) {
    6663            result = createQueryPredicate(key, value);
     
    7875            return null;
    7976        }
    80         // TODO properly handle multi-valued predicates
    81         return createPredicate(key, (String) values.get(0));
     77        Predicate result = createIdEqualsPredicate(key, values);
     78        result.setID(result.saveToDatabase());
     79        return result;
    8280    }
    8381
     
    102100    /**
    103101     * @param key
    104      * @param value
     102     * @param values
    105103     * @return
    106104     */
    107     private static IdEqualsPredicate createIdEqualsPredicate(String key, String value) {
     105    private static IdEqualsPredicate createIdEqualsPredicate(String key, List values) {
    108106        IdEqualsPredicate predicate = null;
    109         if (key.equals("documentID")) {
    110             if (documentIdEqualsPredicates.containsKey(value)) {
    111                 predicate = (IdEqualsPredicate) (documentIdEqualsPredicates.get(value));
     107       
     108        Map keyToPredicates;
     109        if (!idEqualsPredicates.containsKey(key)) {
     110            keyToPredicates = new HashMap();
     111            idEqualsPredicates.put(key, keyToPredicates);
     112        }
     113        keyToPredicates = (Map) idEqualsPredicates.get(key);
     114       
     115        for (Iterator iter = values.iterator(); iter.hasNext();) {
     116            String value = (String) iter.next();
     117            if (keyToPredicates.containsKey(value)) {
     118                predicate = (IdEqualsPredicate) keyToPredicates.get(value);
    112119            } else {
    113120                predicate = new IdEqualsPredicate(key, value);
    114                 documentIdEqualsPredicates.put(value, predicate);
     121                keyToPredicates.put(value, predicate);
    115122            }
    116         } else if (key.equals("collectionID")) {
    117             if (collectionIdEqualsPredicates.containsKey(value)) {
    118                 predicate = (IdEqualsPredicate) collectionIdEqualsPredicates.get(value);
    119             } else {
    120                 predicate = new IdEqualsPredicate(key, value);
    121                 collectionIdEqualsPredicates.put(value, predicate);
    122             }
    123         } // TODO other IDs
     123        }
    124124        return predicate;
    125125    }
     
    161161        return Collections.unmodifiableCollection(collectionNameMatchPredicates.values());
    162162    }
     163
     164    /**
     165     * @param string
     166     * @param string2
     167     * @return
     168     */
     169    public static Predicate getIdEqualsPredicate(String key, String value) {
     170        return (Predicate) ((Map)idEqualsPredicates.get(key)).get(value);
     171    }
    163172   
    164173}
Note: See TracChangeset for help on using the changeset viewer.