/** * Compare this AbstractConstraint with another, ignoring aliases in member fields and tables. * * @param obj an AbstractConstraint to compare to * @return INDEPENDENT, IMPLIED_BY, IMPLIES, EQUAL, OPPOSITE, EXCLUDES, or OR, depending on the * constraints. */ public int compare(AbstractConstraint obj) { IdentityMap<AbstractTable> id = IdentityMap.getInstance(); return compare(obj, id, id); }
/** * Compare this AbstractConstraint with another, ignoring aliases in member fields and tables. * * @param obj an AbstractConstraint to compare to * @return INDEPENDENT, IMPLIED_BY, IMPLIES, EQUAL, OPPOSITE, EXCLUDES, or OR, depending on the * constraints. */ public int compare(AbstractConstraint obj) { IdentityMap<AbstractTable> id = IdentityMap.getInstance(); return compare(obj, id, id); }
/** * Compares 2 sets of AbstractConstraints * * @param set1 the first set * @param set2 the second set * @param equalsSet a Set that should be passed in empty - it will be populated with those * AbstractConstraints that have an equal in the other set. Note that if the return value is * false, then the contents of this Set is undefined * @return true if every element of set1 is equal or less restrictive * than some element in set2 */ protected static boolean compareConstraints(Set<AbstractConstraint> set1, Set<AbstractConstraint> set2, Set<AbstractConstraint> equalsSet) { IdentityMap<AbstractTable> identity = IdentityMap.getInstance(); return compareConstraints(set1, set2, equalsSet, identity, identity); }
/** * Compares 2 sets of AbstractConstraints * * @param set1 the first set * @param set2 the second set * @param equalsSet a Set that should be passed in empty - it will be populated with those * AbstractConstraints that have an equal in the other set. Note that if the return value is * false, then the contents of this Set is undefined * @return true if every element of set1 is equal or less restrictive * than some element in set2 */ protected static boolean compareConstraints(Set<AbstractConstraint> set1, Set<AbstractConstraint> set2, Set<AbstractConstraint> equalsSet) { IdentityMap<AbstractTable> identity = IdentityMap.getInstance(); return compareConstraints(set1, set2, equalsSet, identity, identity); }
/** * Checks a partial mapping. * * @param map the mapping to check - a Map from Table to Table * @return true if the mapping is valid */ public boolean check(Map<AbstractTable, AbstractTable> map) { Map<AbstractTable, AbstractTable> reverseMap; if (map instanceof IdentityMap<?>) { reverseMap = IdentityMap.getInstance(); } else { reverseMap = new HashMap<AbstractTable, AbstractTable>(); for (Map.Entry<AbstractTable, AbstractTable> entry : map.entrySet()) { reverseMap.put(entry.getValue(), entry.getKey()); } } return QueryOptimiser.compareConstraints(set1, set2, new HashSet<AbstractConstraint>(), map, reverseMap); } }
/** * Checks a partial mapping. * * @param map the mapping to check - a Map from Table to Table * @return true if the mapping is valid */ public boolean check(Map<AbstractTable, AbstractTable> map) { Map<AbstractTable, AbstractTable> reverseMap; if (map instanceof IdentityMap<?>) { reverseMap = IdentityMap.getInstance(); } else { reverseMap = new HashMap<AbstractTable, AbstractTable>(); for (Map.Entry<AbstractTable, AbstractTable> entry : map.entrySet()) { reverseMap.put(entry.getValue(), entry.getKey()); } } return QueryOptimiser.compareConstraints(set1, set2, new HashSet<AbstractConstraint>(), map, reverseMap); } }
assertEquals(AbstractConstraint.INDEPENDENT, aC.compare(bB)); assertEquals(AbstractConstraint.EQUAL, aC.compare(bC)); IdentityMap<AbstractTable> id = IdentityMap.getInstance(); assertEquals(AbstractConstraint.IMPLIES, a.internalCompare(b, id, id)); assertEquals(AbstractConstraint.IMPLIES, b.internalCompare(a, id, id));