public static boolean compareNoThrow(Object rootA, Object rootB) { try { new DeepComparer().compare(rootA, rootB); return true; } catch (ComparisonException e) { return false; } }
/** * Compare two objects for equality. * * @param rootA * First object. * @param rootB * Second object. * @throws ComparisonException * Thrown if the two trees differ. */ public static void compareAndThrow(Object rootA, Object rootB) throws ComparisonException { new DeepComparer().compare(rootA, rootB); }
/** * Compare two AST subtrees for equality. * * Property and attribute values are compared using the <code>equals</code> * method. * * @param rootA * First subtree. * @param rootB * Second subtree. * @param compareAttributes * Whether to include the node attributes in the comparison. */ public static void compareAndThrow( AstNode<?> rootA, AstNode<?> rootB, boolean compareAttributes, boolean compareLocation) throws ComparisonException { makeComparer(compareAttributes, compareLocation).compare(rootA, rootB); }
/** * Compare two AST subtrees for equality. * * Property and attribute values are compared using the <code>equals</code> * method. * * @param rootA * First subtree. * @param rootB * Second subtree. * @param compareAttributes * Whether to include the node attributes in the comparison. */ public static void compareAndThrow( AstNode<?> rootA, AstNode<?> rootB, boolean compareAttributes, boolean compareLocation) throws ComparisonException { makeComparer(compareAttributes, compareLocation).compare(rootA, rootB); }
/** * Compare two AST subtrees for equality. * * Property and attribute values are compared using the <code>equals</code> * method. * * @param rootA * First subtree. * @param rootB * Second subtree. * @param compareAttributes * Whether to include the node attributes in the comparison. */ public static void compareAndThrow( AstNode<?> rootA, AstNode<?> rootB, boolean compareAttributes, boolean compareLocation) throws ComparisonException { makeComparer(compareAttributes, compareLocation).compare(rootA, rootB); }
@Override public boolean compare(Object _a, Object _b, DeepComparer comparer) throws ComparisonException { if (!((_a instanceof Collection) && (_b instanceof Collection))) return false; Collection<?> a = (Collection<?>) _a; Collection<?> b = (Collection<?>) _b; Iterator<?> e1 = a.iterator(); Iterator<?> e2 = b.iterator(); while (e1.hasNext() && e2.hasNext()) { Object o1 = e1.next(); Object o2 = e2.next(); if ((o1 == null) != (o2 == null)) throw new ComparisonException(a, b); comparer.compare(o1, o2); } if (e1.hasNext() || e2.hasNext()) throw new ComparisonException(a, b); return true; } }
@Override public boolean compare(Object _a, Object _b, DeepComparer comparer) throws ComparisonException { if (!((_a instanceof Map) && (_b instanceof Map))) return false; Map<?, ?> a = (Map<?, ?>) _a; Map<?, ?> b = (Map<?, ?>) _b; if (b.size() != a.size()) throw new ComparisonException(a, b); Iterator<?> i = a.entrySet().iterator(); while (i.hasNext()) { Entry<?, ?> e = (Entry<?, ?>) i.next(); Object key = e.getKey(); Object value = e.getValue(); if (value == null) { if (!(b.get(key) == null && b.containsKey(key))) throw new ComparisonException(a, b); } else { comparer.compare(value, b.get(key)); } } return true; } }
comparer.compare(ac, bc);
comparer.compare(value, b.get(key));
@Override public boolean compare(Object _a, Object _b, DeepComparer comparer) throws ComparisonException { if (!(_a instanceof AstEntityMap)) return false; if (!(_b instanceof AstEntityMap)) throw new ComparisonException(_a, _b); AstEntityMap<?> a = (AstEntityMap<?>) _a; AstEntityMap<?> b = (AstEntityMap<?>) _b; comparer.compare(a.getMap(), b.getMap()); return true; } }