1313
1414public class VariationUnparser {
1515 /**
16- * Unparse VariationTrees to Text/ String
16+ * Unparse {@link VariationTree}s into a {@link String}.
1717 *
18- * @param tree VariationTree, that be unparsed
19- * @param linesToLabel Function, that return list of String and has a Class T
20- * @return String, the result of unparsing
21- * @param <T> that implements Label
18+ * @param tree that is unparsed
19+ * @param linesToLabel a function that converts lists of lines into labels
20+ * @return the unparsed variation tree
21+ * @param <L> the type of labels of the tree
2222 */
23- public static <T extends Label > String variationTreeUnparser (VariationTree <T > tree , Function <List <String >, T > linesToLabel ) {
23+ public static <L extends Label > String variationTreeUnparser (VariationTree <L > tree , Function <List <String >, L > linesToLabel ) {
2424 if (!tree .root ().getChildren ().isEmpty ()) {
2525 StringBuilder result = new StringBuilder ();
26- Stack <VariationTreeNode <T >> stack = new Stack <>();
26+ Stack <VariationTreeNode <L >> stack = new Stack <>();
2727 for (int i = tree .root ().getChildren ().size () - 1 ; i >= 0 ; i --) {
2828 stack .push (tree .root ().getChildren ().get (i ));
2929 }
3030 while (!stack .empty ()) {
31- VariationTreeNode <T > node = stack .pop ();
31+ VariationTreeNode <L > node = stack .pop ();
3232 if (node .isIf ()) {
3333 stack .push (new VariationTreeNode <>(NodeType .ARTIFACT , null , null ,
3434 linesToLabel .apply (node .getEndIf ())));
@@ -48,47 +48,55 @@ public static <T extends Label> String variationTreeUnparser(VariationTree<T> tr
4848 }
4949
5050 /**
51- * Unparse VariationTrees to Text/ String
51+ * Unparse {@link VariationTree}s into a {@link String}.
5252 *
53- * @param tree VariationTree, that be unparsed
54- * @return String, the result of unparsing
53+ * @param tree that is unparsed
54+ * @param linesToLabel a function that converts lists of lines into labels
55+ * @return the unparsed variation tree
5556 */
5657 public static String variationTreeUnparser (VariationTree <DiffLinesLabel > tree ) {
5758 return variationTreeUnparser (tree , DiffLinesLabel ::withInvalidLineNumbers );
5859 }
5960
6061 /**
61- * Unparse VariationDiffs to Text/ String
62+ * Unparse {@link VariationDiff}s into a {@link String}.
6263 *
63- * @param diff VariationDiff, that be unparsed
64- * @param linesToLabel Function, that return list of String and has a Class T
65- * @return String, the result of unparsing
66- * @param <T> that implements Label
64+ * @param diff that is unparsed
65+ * @param linesToLabel a function that converts lists of lines into labels
66+ * @return the unparsed variation diff
67+ * @param <L> the type of labels of the tree
6768 * @throws IOException
6869 */
69- public static <T extends Label > String variationDiffUnparser (VariationDiff <T > diff , Function <List <String >, T > linesToLabel ) throws IOException {
70+ public static <L extends Label > String variationDiffUnparser (VariationDiff <L > diff , Function <List <String >, L > linesToLabel ) throws IOException {
7071 String tree1 = variationTreeUnparser (diff .project (Time .BEFORE ), linesToLabel );
7172 String tree2 = variationTreeUnparser (diff .project (Time .AFTER ), linesToLabel );
7273 return JGitDiff .textDiff (tree1 , tree2 , SupportedAlgorithm .MYERS );
7374 }
7475
7576 /**
76- * Unparse VariationDiffs to Text/ String
77+ * Unparse {@link VariationDiff}s into a {@link String}.
7778 *
78- * @param diff VariationDiff, that be unparsed
79- * @return String, the result of unparsing
79+ * @param diff that is unparsed
80+ * @return the unparsed variation diff
8081 * @throws IOException
8182 */
8283 public static String variationDiffUnparser (VariationDiff <DiffLinesLabel > diff ) throws IOException {
8384 return variationDiffUnparser (diff , DiffLinesLabel ::withInvalidLineNumbers );
8485 }
8586
86- public static String undiff (String text , Time time ) {
87- if (text .isEmpty ()) {
87+ /**
88+ * Extract the state of the diffed text before or after {@code diff}.
89+ *
90+ * @param diff the diff from which the state is extracted
91+ * @param time that the returned state represents
92+ * @return the state before or after the diff
93+ */
94+ public static String undiff (String diff , Time time ) {
95+ if (diff .isEmpty ()) {
8896 return "" ;
8997 } else {
9098 StringBuilder result = new StringBuilder ();
91- String [] textSplit = text .split ("\n " );
99+ String [] textSplit = diff .split ("\n " );
92100 char zeichen ;
93101 if (Time .AFTER == time ) {
94102 zeichen = '-' ;
0 commit comments