Esempio n. 1
0
 @SuppressWarnings("unchecked")
 public static <T extends HGQueryCondition> T collapse(HyperGraph graph, Set<HGQueryCondition> S) {
   if (S == null || S.isEmpty()) return null;
   Iterator<HGQueryCondition> I = S.iterator();
   HGQueryCondition c = I.next();
   while (I.hasNext()) if (!c.equals(I.next())) throw new ContradictoryCondition();
   return (T) c;
 }
Esempio n. 2
0
 /**
  * Collect and group different types of conditions in map. The method takes any number of
  * condition Class-es and return a map Class->Set<all conditions of that class>. The test is done
  * using the <code>Class.isAssignableFrom</code> so a given condition could end in multiple map
  * entries if some of the Class arguments inherit from each other. If no condition of a specified
  * Class is found, the map won't contain an entry for that class at all.
  *
  * @param C
  * @param condType
  * @return
  */
 public static Map<Class<?>, Set<HGQueryCondition>> find(
     Collection<HGQueryCondition> C, Class<?>... condType) {
   HashMap<Class<?>, Set<HGQueryCondition>> M = new HashMap<Class<?>, Set<HGQueryCondition>>();
   for (HGQueryCondition c : C) {
     for (int i = 0; i < condType.length; i++)
       if (condType[i].isAssignableFrom(c.getClass())) {
         Set<HGQueryCondition> S = M.get(condType[i]);
         if (S == null) {
           S = new HashSet<HGQueryCondition>();
           M.put(condType[i], S);
         }
         S.add(c);
       }
   }
   return M;
 }