com.github.opennano.reflectionassert.diffs.ParentDiff Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reflection-assert Show documentation
Show all versions of reflection-assert Show documentation
performs deep comparisons of objects via field reflection
package com.github.opennano.reflectionassert.diffs;
import java.util.List;
import java.util.stream.Collectors;
import com.github.opennano.reflectionassert.report.DiffView;
import com.github.opennano.reflectionassert.report.DiffVisitor;
/** represents an internal node in a diff tree */
public final class ParentDiff extends Diff {
private List childDiffs;
public ParentDiff(String path, List childDiffs) {
super(path, null, null);
this.childDiffs = childDiffs;
}
@Override
public DiffType getType() {
return null;
}
public ParentDiff cloneAndRepath(String originalRootPath, String newRootPath) {
// recursively clones all nodes under this one, updating the base path along the way
ParentDiff clone = (ParentDiff) super.cloneAndRepath(originalRootPath, newRootPath);
clone.childDiffs =
childDiffs
.stream()
.map(diff -> diff.cloneAndRepath(originalRootPath, newRootPath))
.collect(Collectors.toList());
return clone;
}
@Override
public void accept(DiffView view, DiffVisitor visitor) {
childDiffs.forEach(diff -> visitor.visit(diff));
}
}