Changeset 8777 for trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java
- Timestamp:
- 2004-12-10T15:48:39+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java
r8738 r8777 27 27 private static int id = 0; 28 28 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(); 33 30 34 // substring for collection_name -> SubstringMatchPredicate referring to it31 // substring for collection_name -> SubstringMatchPredicates referring to it 35 32 private static Map collectionNameMatchPredicates = new TreeMap(); 36 33 … … 59 56 } 60 57 61 if ( key.equals("type")) {62 return result;63 } else if (key.endsWith("ID")) {64 re sult = createIdEqualsPredicate(key, value);58 if (Predicate.isMultiValued(key)) { 59 List list = new ArrayList(); 60 list.add(value); 61 return createPredicate(key, list); 65 62 } else if (key.startsWith("document")) { 66 63 result = createQueryPredicate(key, value); … … 78 75 return null; 79 76 } 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; 82 80 } 83 81 … … 102 100 /** 103 101 * @param key 104 * @param value 102 * @param values 105 103 * @return 106 104 */ 107 private static IdEqualsPredicate createIdEqualsPredicate(String key, String value) {105 private static IdEqualsPredicate createIdEqualsPredicate(String key, List values) { 108 106 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); 112 119 } else { 113 120 predicate = new IdEqualsPredicate(key, value); 114 documentIdEqualsPredicates.put(value, predicate);121 keyToPredicates.put(value, predicate); 115 122 } 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 } 124 124 return predicate; 125 125 } … … 161 161 return Collections.unmodifiableCollection(collectionNameMatchPredicates.values()); 162 162 } 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 } 163 172 164 173 }
Note:
See TracChangeset
for help on using the changeset viewer.