public void node(final DiffNode node, final Visit visit) { if (node.getState() == DiffNode.State.ADDED) { node.canonicalSet(head, node.canonicalGet(modified)); } else if (node.getState() == DiffNode.State.REMOVED) { node.canonicalUnset(head); } else if (node.getState() == DiffNode.State.CHANGED) { if (node.hasChildren()) { node.visitChildren(this); visit.dontGoDeeper(); } else { node.canonicalSet(head, node.canonicalGet(modified)); } } } }
"This would cause inifite loops and must never happen."); else if (node.isRootNode()) else if (node.getParentNode() != null && node.getParentNode() != this) "cause infinite loops."); if (node.getParentNode() == null) node.setParentNode(this); children.put(node.getElementSelector(), node); if (state == State.UNTOUCHED && node.hasChanges())
/** * Visit all child nodes but not this one. * * @param visitor The visitor to use. */ public final void visitChildren(final Visitor visitor) { for (final DiffNode child : children.values()) { try { child.visit(visitor); } catch (final StopVisitationException e) { return; } } }
protected boolean filter(final DiffNode node) { return (node.isRootNode() && !node.hasChanges()) || (node.hasChanges() && !node.hasChildren()); }
public void canonicalUnset(Object target) { if (parentNode != null) { target = parentNode.canonicalGet(target); } unset(target); }
public Object canonicalGet(Object target) { if (parentNode != null) { target = parentNode.canonicalGet(target); } return get(target); }
diffNode.visit((node, visit) -> { String itemName = node.getElementSelector().toHumanReadableString(); Object old = node.canonicalGet(oldVersion); Object newV = node.canonicalGet(newVersion); List<ElementSelector> selectors = node.getPath().getElementSelectors(); childDiff.setState(node.getState()); if (node.hasChanges() && !node.hasChildren()) { childDiff.setNewValue(node.canonicalGet(newVersion)); childDiff.setOldValue(node.canonicalGet(oldVersion)); diff.addChild(selectors.subList(1, selectors.size()), childDiff); if (node.isRootNode()) { diff.setState(node.getState());
assertTrue(root.hasChanges()); root.visit(new DiffNode.Visitor() { @Override public void node(DiffNode node, Visit visit) { if (node.hasChanges() && !node.hasChildren()) { node.canonicalSet(person2, node.canonicalGet(person2) + "*");
public boolean isReturnable(final DiffNode node) { if (node.isRootNode()) { return true; } if (node.isUntouched() && node.hasChildren()) { return true; } return stateFilterSettings.get(node.getState()); }
protected String differenceToString(final DiffNode node, final Object base, final Object modified) { final NodePath nodePath = node.getPath(); final String stateMessage = translateState(node.getState(), node.canonicalGet(base), node.canonicalGet(modified)); final String propertyMessage = String.format("Property at path '%s' %s", nodePath, stateMessage); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(propertyMessage); if (node.isCircular()) { stringBuilder.append(" (Circular reference detected: The property has already been processed at another position.)"); } return stringBuilder.toString(); }
public void canonicalSet(Object target, final Object value) { if (parentNode != null) { Object parent = parentNode.canonicalGet(target); if (parent == null) { parent = parentNode.newInstance(); parentNode.canonicalSet(target, parent); } target = parent; } set(target, value); }
sb.append("("); sb.append("state="); sb.append(getState().toString()); if (getValueType() != null) sb.append(", type=").append(getValueType().getCanonicalName()); if (childCount() == 1) sb.append(", ").append(childCount()).append(" child"); else if (childCount() > 1) sb.append(", ").append(childCount()).append(" children"); if (!getCategories().isEmpty()) sb.append(", categorized as ").append(getCategories());
public void onCircularReferenceException(final DiffNode node) { final String message = "Detected circular reference in node at path {}. " + "Going deeper would cause an infinite loop, so I'll stop looking at " + "this instance along the current path."; logger.warn(message, node.getPath()); } };
private static DiffNode newCircularNode(final DiffNode parentNode, final Instances instances, final NodePath circleStartPath) { final DiffNode node = new DiffNode(parentNode, instances.getSourceAccessor(), instances.getType()); node.setState(DiffNode.State.CIRCULAR); node.setCircleStartPath(circleStartPath); node.setCircleStartNode(findNodeMatchingPropertyPath(parentNode, circleStartPath)); return node; } }
public final DiffNode compare(final DiffNode parentNode, final Instances instances) { if (!accepts(instances.getType())) { throw new IllegalArgumentException("The primitive differ can only deal with primitive types."); } final DiffNode node = new DiffNode(parentNode, instances.getSourceAccessor(), instances.getType()); if (shouldTreatPrimitiveDefaultsAsUnassigned(node) && instances.hasBeenAdded()) { node.setState(DiffNode.State.ADDED); } else if (shouldTreatPrimitiveDefaultsAsUnassigned(node) && instances.hasBeenRemoved()) { node.setState(DiffNode.State.REMOVED); } else if (!instances.areEqual()) { node.setState(DiffNode.State.CHANGED); } return node; }
public Introspector introspectorForNode(final DiffNode node) { final Introspector typeIntrospector = typeIntrospectorMap.get(node.getValueType()); if (typeIntrospector != null) { return typeIntrospector; } final Introspector nodePathIntrospector = nodePathIntrospectorHolder.valueForNodePath(node.getPath()); if (nodePathIntrospector != null) { return nodePathIntrospector; } if (defaultIntrospector == null) { defaultIntrospector = new StandardIntrospector(); } return defaultIntrospector; }
public ComparisonStrategy resolveComparisonStrategy(final DiffNode node) final ComparisonStrategy comparisonStrategy = nodePathComparisonStrategies.valueForNodePath(node.getPath()); if (comparisonStrategy != null) final Class<?> valueType = node.getValueType(); if (typeComparisonStrategyMap.containsKey(valueType)) final ObjectDiffProperty objectDiffProperty = node.getPropertyAnnotation(ObjectDiffProperty.class); final ComparisonStrategy comparisonStrategyFromObjectDiffPropertyAnnotation = comparisonStrategyResolver.comparisonStrategyForAnnotation(objectDiffProperty); if (comparisonStrategyFromObjectDiffPropertyAnnotation != null)
protected final void visit(final Visitor visitor, final Visit visit) { try { visitor.node(this, visit); } catch (final StopVisitationException e) { visit.stop(); } if (visit.isAllowedToGoDeeper() && hasChildren()) { visitChildren(visitor); } if (visit.isStopped()) { throw new StopVisitationException(); } }
return isRootNode() ? this : null; return getChild(selector); if (selector == RootElementSelector.getInstance()) child = isRootNode() ? this : null; child = getChild(selector); return child.getChild(selectors.subList(1, selectors.size()));