Record Class BadVDiff<L extends Label>
java.lang.Object
java.lang.Record
org.variantsync.diffdetective.variation.diff.bad.BadVDiff<L>
- Record Components:
diff- The variation tree that models the tree diff.matching- Memorization of which nodes are clones and can be safely merged when converting back to a variation diff.coloring- Memorization of the diff types of all nodes.lines- Memorization of line ranges within text diffs.
public record BadVDiff<L extends Label>(VariationTree<L extends Label> diff, Map<VariationTreeNode<L extends Label>,VariationTreeNode<L extends Label>> matching, Map<VariationTreeNode<L extends Label>,DiffType> coloring, Map<VariationTreeNode<L extends Label>,DiffLineNumberRange> lines)
extends Record
A bad variation diff is a variation diff that has no subtree sharing.
This means that the diff is a tree.
We thus can store the diff as a variation tree with some extra information.
This allows us to prove the variation diff being a tree at the type level.
When converting a variation diff to a bad one, cycles
.
/ \
/ \
. .
\ /
\ /
x
are resolved by cloning the deepest subtree x in the cycle.
.
/ \
/ \
. .
| |
| |
x x
The matching in a bad variation diff stores which nodes have been cloned.
As variation trees do not store any diff-specific information, we remember the nodes difftype in the original variation diff in a coloring map.
(Unproven) Invariants: for all VariationDiff d: fromGood(d).toGood() equals d
- Author:
- Paul Bittner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classBadVDiff.FromGoodNodeTranslation<L extends Label>Memoization of the VariationTreeNodes a DiffNode was converted to infromGood(VariationDiff). -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<VariationTreeNode<L>, DiffType> The field for thecoloringrecord component.private final VariationTree<L> The field for thediffrecord component.private final Map<VariationTreeNode<L>, DiffLineNumberRange> The field for thelinesrecord component.private final Map<VariationTreeNode<L>, VariationTreeNode<L>> The field for thematchingrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionBadVDiff(VariationTree<L> diff, Map<VariationTreeNode<L>, VariationTreeNode<L>> matching, Map<VariationTreeNode<L>, DiffType> coloring, Map<VariationTreeNode<L>, DiffLineNumberRange> lines) Creates an instance of aBadVDiffrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncoloring()Returns the value of thecoloringrecord component.deepCopy()diff()Returns the value of thediffrecord component.final booleanIndicates whether some other object is "equal to" this one.private static <L extends Label>
VariationTreeNode<L> fromGood(DiffNode<L> n, BadVDiff.FromGoodNodeTranslation<L> nodeTranslation, Map<VariationTreeNode<L>, DiffType> coloring, Map<VariationTreeNode<L>, DiffLineNumberRange> lines) Performs aplainconversion of the given DiffNode n to a VariationTreeNode.fromGood(VariationDiff<L> d) Creates a bad diff from a VariationDiff.final inthashCode()Returns a hash code value for this object.lines()Returns the value of thelinesrecord component.matching()Returns the value of thematchingrecord component.mergeToGood(VariationTreeNode<L> before, VariationTreeNode<L> after) Merges two VariationTreeNodes that represent the same node to a single unchanged DiffNode.private static <L extends Label>
VariationTreeNode<L> Plain conversion of DiffNodes to VariationTree nodes.private voidprettyPrint(String indent, StringBuilder b, VariationTreeNode<L> n) toGood()Inverse offromGood(VariationDiff).toGood(VariationTreeNode<L> n) final StringtoString()Returns a string representation of this record class.
-
Field Details
-
Constructor Details
-
BadVDiff
public BadVDiff(VariationTree<L> diff, Map<VariationTreeNode<L>, VariationTreeNode<L>> matching, Map<VariationTreeNode<L>, DiffType> coloring, Map<VariationTreeNode<L>, DiffLineNumberRange> lines) Creates an instance of aBadVDiffrecord class.
-
-
Method Details
-
plain
Plain conversion of DiffNodes to VariationTree nodes. Copiesnode type,formula,line numbers in the diff, andlabelbut no edge information.- Parameters:
n- The node to convert to a plain VariationTreeNode.
-
fromGood
private static <L extends Label> VariationTreeNode<L> fromGood(DiffNode<L> n, BadVDiff.FromGoodNodeTranslation<L> nodeTranslation, Map<VariationTreeNode<L>, DiffType> coloring, Map<VariationTreeNode<L>, DiffLineNumberRange> lines) Performs aplainconversion of the given DiffNode n to a VariationTreeNode. Additionally, stores metadata to invert this operation in the given maps. For further information on these maps, have a look atthe documentation of this class.- Parameters:
nodeTranslation- seeBadVDiff.FromGoodNodeTranslation
-
toGood
-
mergeToGood
Merges two VariationTreeNodes that represent the same node to a single unchanged DiffNode. It is asserted that both given nodes have the sameNodeType, label, formula, and line numbers. -
fromGood
Creates a bad diff from a VariationDiff.- Parameters:
d- The VariationDiff to convert to a bad diff.- See Also:
-
toGood
Inverse offromGood(VariationDiff). Restores the VariationDiff that is represented by this bad tree diff. -
deepCopy
-
prettyPrint
-
prettyPrint
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
diff
Returns the value of thediffrecord component.- Returns:
- the value of the
diffrecord component
-
matching
Returns the value of thematchingrecord component.- Returns:
- the value of the
matchingrecord component
-
coloring
Returns the value of thecoloringrecord component.- Returns:
- the value of the
coloringrecord component
-
lines
Returns the value of thelinesrecord component.- Returns:
- the value of the
linesrecord component
-