Record Class VariationTree<L extends Label>
java.lang.Object
java.lang.Record
org.variantsync.diffdetective.variation.tree.VariationTree<L>
- Type Parameters:
L
- The type of label stored in this tree.- Record Components:
root
- the root of the variation treesource
- from which source code the variation tree was obtained
public record VariationTree<L extends Label>(VariationTreeNode<L extends Label> root, VariationTreeSource source)
extends Record
Representation of a concrete variation tree with source information.
- Author:
- Benjamin Moosherr
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate final VariationTreeNode<L>
The field for theroot
record component.private final VariationTreeSource
The field for thesource
record component. -
Constructor Summary
ConstructorDescriptionVariationTree
(VariationTreeNode<L> root) Creates aVariationTree
with the given root and an unknown source.VariationTree
(VariationTreeNode<L> root, VariationTreeSource source) Creates aVariationTree
with the given root and source. -
Method Summary
Modifier and TypeMethodDescriptionboolean
anyMatch
(Predicate<VariationTreeNode<L>> condition) Checks whether any node in this tree satisfies the given condition.int
Returns the number of nodes in this Variation Tree.boolean
contains
(VariationTreeNode<L> node) Returns true iff this tree contains the given node.deepCopy()
deepCopy
(Map<VariationTreeNode<L>, VariationTreeNode<L>> oldToNew) Creates a deep copy of this variation tree.final boolean
Indicates whether some other object is "equal to" this one.forAllPreorder
(Consumer<VariationTreeNode<L>> action) Invokes the given callback for each node in this Variation Tree in depth-first order.static VariationTree<DiffLinesLabel>
fromFile
(BufferedReader input, VariationTreeSource source, VariationDiffParseOptions parseOptions) Parses aVariationTree
from source code with C preprocessor annotations.static VariationTree<DiffLinesLabel>
Same asfromFile(Path, VariationDiffParseOptions)
but withVariationDiffParseOptions.Default
parse options.static VariationTree<DiffLinesLabel>
fromFile
(Path path, VariationDiffParseOptions parseOptions) Same asfromFile(BufferedReader, VariationTreeSource, VariationDiffParseOptions)
but registerspath
as source.static <L extends Label>
VariationTree<L>fromProjection
(Projection<L> projection, VariationTreeSource source) static <T extends VariationNode<T,
L>, L extends Label>
VariationTree<L>fromVariationNode
(VariationNode<T, L> node, VariationTreeSource source) final int
hashCode()
Returns a hash code value for this object.root()
Returns the value of theroot
record component.source()
Returns the value of thesource
record component.toString()
Returns a string representation of this record class.toVariationDiff
(Function<VariationTreeNode<L>, DiffNode<L>> nodeConverter)
-
Field Details
-
Constructor Details
-
VariationTree
Creates aVariationTree
with the given root and an unknown source. -
VariationTree
Creates aVariationTree
with the given root and source.
-
-
Method Details
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(Path path) throws IOException, DiffParseException Same asfromFile(Path, VariationDiffParseOptions)
but withVariationDiffParseOptions.Default
parse options.- Throws:
IOException
DiffParseException
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(Path path, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException Same asfromFile(BufferedReader, VariationTreeSource, VariationDiffParseOptions)
but registerspath
as source.- Throws:
IOException
DiffParseException
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(BufferedReader input, VariationTreeSource source, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException Parses aVariationTree
from source code with C preprocessor annotations.- Parameters:
input
- the source code to be parsedparseOptions
-PatchDiffParseOptions
for the parsing process.- Returns:
- a new
VariationTree
representinginput
- Throws:
IOException
- ifinput
throwsIOException
DiffParseException
- if some preprocessor annotations can't be parsed
-
fromProjection
public static <L extends Label> VariationTree<L> fromProjection(Projection<L> projection, VariationTreeSource source) -
fromVariationNode
public static <T extends VariationNode<T,L>, VariationTree<L> fromVariationNodeL extends Label> (VariationNode<T, L> node, VariationTreeSource source) -
toVariationDiff
-
toCompletelyUnchangedVariationDiff
-
forAllPreorder
Invokes the given callback for each node in this Variation Tree in depth-first order.- Parameters:
action
- callback- Returns:
- this
-
anyMatch
Checks whether any node in this tree satisfies the given condition. The condition might not be invoked on every node in case a node is found.- Parameters:
condition
- A condition to check on each node.- Returns:
- True iff the given condition returns true for at least one node in this tree.
-
contains
Returns true iff this tree contains the given node. Containment check is done on referential and not on textual equality (i.e., nodes are compared using ==).- Parameters:
node
- The node to check for containment.
-
computeSize
public int computeSize()Returns the number of nodes in this Variation Tree. -
deepCopy
-
deepCopy
Creates a deep copy of this variation tree.The map
oldToNew
should be empty as it will be filled by this method. After the method call, the map keys will contain all nodes in this tree. The corresponding values will be the nodes in the returned tree, where each pair (k, v) denotes that v was cloned from k.- Parameters:
oldToNew
- A map that memorizes the translation of individual nodes.- Returns:
- A deep copy of this tree.
-
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)
. -
root
Returns the value of theroot
record component.- Returns:
- the value of the
root
record component
-
source
Returns the value of thesource
record component.- Returns:
- the value of the
source
record component
-