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
FieldsModifier and TypeFieldDescriptionprivate final VariationTreeNode<L> The field for therootrecord component.private final VariationTreeSourceThe field for thesourcerecord component. -
Constructor Summary
ConstructorsConstructorDescriptionVariationTree(VariationTreeNode<L> root) Creates aVariationTreewith the given root and an unknown source.VariationTree(VariationTreeNode<L> root, VariationTreeSource source) Creates aVariationTreewith the given root and source. -
Method Summary
Modifier and TypeMethodDescriptionbooleananyMatch(Predicate<VariationTreeNode<L>> condition) Checks whether any node in this tree satisfies the given condition.intReturns the number of nodes in this Variation Tree.booleancontains(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 booleanIndicates 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 aVariationTreefrom source code with C preprocessor annotations.static VariationTree<DiffLinesLabel> Same asfromFile(Path, VariationDiffParseOptions)but withVariationDiffParseOptions.Defaultparse options.static VariationTree<DiffLinesLabel> fromFile(Path path, VariationDiffParseOptions parseOptions) Same asfromFile(BufferedReader, VariationTreeSource, VariationDiffParseOptions)but registerspathas 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 inthashCode()Returns a hash code value for this object.root()Returns the value of therootrecord component.source()Returns the value of thesourcerecord component.toString()Returns a string representation of this record class.toVariationDiff(Function<VariationTreeNode<L>, DiffNode<L>> nodeConverter)
-
Field Details
-
Constructor Details
-
VariationTree
Creates aVariationTreewith the given root and an unknown source. -
VariationTree
Creates aVariationTreewith the given root and source.
-
-
Method Details
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(Path path) throws IOException, DiffParseException Same asfromFile(Path, VariationDiffParseOptions)but withVariationDiffParseOptions.Defaultparse options.- Throws:
IOExceptionDiffParseException
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(Path path, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException Same asfromFile(BufferedReader, VariationTreeSource, VariationDiffParseOptions)but registerspathas source.- Throws:
IOExceptionDiffParseException
-
fromFile
public static VariationTree<DiffLinesLabel> fromFile(BufferedReader input, VariationTreeSource source, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException Parses aVariationTreefrom source code with C preprocessor annotations.- Parameters:
input- the source code to be parsedparseOptions-PatchDiffParseOptionsfor the parsing process.- Returns:
- a new
VariationTreerepresentinginput - Throws:
IOException- ifinputthrowsIOExceptionDiffParseException- 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
oldToNewshould 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 therootrecord component.- Returns:
- the value of the
rootrecord component
-
source
Returns the value of thesourcerecord component.- Returns:
- the value of the
sourcerecord component
-