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
. / \ / \ . . \ / \ / xare resolved by cloning the deepest subtree x in the cycle.
. / \ / \ . . | | | | x xThe 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
Modifier and TypeClassDescriptionprivate static class
BadVDiff.FromGoodNodeTranslation<L extends Label>
Memoization of the VariationTreeNodes a DiffNode was converted to infromGood(VariationDiff)
. -
Field Summary
Modifier and TypeFieldDescriptionprivate final Map<VariationTreeNode<L>,
DiffType> The field for thecoloring
record component.private final VariationTree<L>
The field for thediff
record component.private final Map<VariationTreeNode<L>,
DiffLineNumberRange> The field for thelines
record component.private final Map<VariationTreeNode<L>,
VariationTreeNode<L>> The field for thematching
record component. -
Constructor Summary
ConstructorDescriptionBadVDiff
(VariationTree<L> diff, Map<VariationTreeNode<L>, VariationTreeNode<L>> matching, Map<VariationTreeNode<L>, DiffType> coloring, Map<VariationTreeNode<L>, DiffLineNumberRange> lines) Creates an instance of aBadVDiff
record class. -
Method Summary
Modifier and TypeMethodDescriptioncoloring()
Returns the value of thecoloring
record component.deepCopy()
diff()
Returns the value of thediff
record component.final boolean
Indicates 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 aplain
conversion of the given DiffNode n to a VariationTreeNode.fromGood
(VariationDiff<L> d) Creates a bad diff from a VariationDiff.final int
hashCode()
Returns a hash code value for this object.lines()
Returns the value of thelines
record component.matching()
Returns the value of thematching
record 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 void
prettyPrint
(String indent, StringBuilder b, VariationTreeNode<L> n) toGood()
Inverse offromGood(VariationDiff)
.toGood
(VariationTreeNode<L> n) final String
toString()
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 aBadVDiff
record class.
-
-
Method Details
-
plain
Plain conversion of DiffNodes to VariationTree nodes. Copiesnode type
,formula
,line numbers in the diff
, andlabel
but 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 aplain
conversion 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 thediff
record component.- Returns:
- the value of the
diff
record component
-
matching
Returns the value of thematching
record component.- Returns:
- the value of the
matching
record component
-
coloring
Returns the value of thecoloring
record component.- Returns:
- the value of the
coloring
record component
-
lines
Returns the value of thelines
record component.- Returns:
- the value of the
lines
record component
-