This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit 2ff16ee48e1d94b2365ab5469b79f5aa76bfb976 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jul 24 11:18:08 2021 -0400 Sort members. --- .../apache/commons/text/diff/CommandVisitor.java | 14 +- .../org/apache/commons/text/diff/EditCommand.java | 18 +-- .../org/apache/commons/text/diff/EditScript.java | 42 ++--- .../commons/text/diff/ReplacementsFinder.java | 20 +-- .../commons/text/diff/StringsComparator.java | 180 ++++++++++----------- 5 files changed, 137 insertions(+), 137 deletions(-) diff --git a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java index 41a8697..6647bcc 100644 --- a/src/main/java/org/apache/commons/text/diff/CommandVisitor.java +++ b/src/main/java/org/apache/commons/text/diff/CommandVisitor.java @@ -124,6 +124,13 @@ package org.apache.commons.text.diff; public interface CommandVisitor<T> { /** + * Method called when a delete command is encountered. + * + * @param object object to delete (this object comes from the first sequence) + */ + void visitDeleteCommand(T object); + + /** * Method called when an insert command is encountered. * * @param object object to insert (this object comes from the second sequence) @@ -137,11 +144,4 @@ public interface CommandVisitor<T> { */ void visitKeepCommand(T object); - /** - * Method called when a delete command is encountered. - * - * @param object object to delete (this object comes from the first sequence) - */ - void visitDeleteCommand(T object); - } diff --git a/src/main/java/org/apache/commons/text/diff/EditCommand.java b/src/main/java/org/apache/commons/text/diff/EditCommand.java index 84cb1cf..65a40a6 100644 --- a/src/main/java/org/apache/commons/text/diff/EditCommand.java +++ b/src/main/java/org/apache/commons/text/diff/EditCommand.java @@ -67,15 +67,6 @@ public abstract class EditCommand<T> { } /** - * Gets the object associated with this command. - * - * @return The object on which the command is applied - */ - protected T getObject() { - return object; - } - - /** * Accepts a visitor. * <p> * This method is invoked for each commands belonging to @@ -86,4 +77,13 @@ public abstract class EditCommand<T> { */ public abstract void accept(CommandVisitor<T> visitor); + /** + * Gets the object associated with this command. + * + * @return The object on which the command is applied + */ + protected T getObject() { + return object; + } + } diff --git a/src/main/java/org/apache/commons/text/diff/EditScript.java b/src/main/java/org/apache/commons/text/diff/EditScript.java index 9e20c3c..60de713 100644 --- a/src/main/java/org/apache/commons/text/diff/EditScript.java +++ b/src/main/java/org/apache/commons/text/diff/EditScript.java @@ -66,13 +66,13 @@ public class EditScript<T> { } /** - * Appends a keep command to the script. + * Appends a delete command to the script. * * @param command command to add */ - public void append(final KeepCommand<T> command) { + public void append(final DeleteCommand<T> command) { commands.add(command); - ++lcsLength; + ++modifications; } /** @@ -86,28 +86,13 @@ public class EditScript<T> { } /** - * Appends a delete command to the script. + * Appends a keep command to the script. * * @param command command to add */ - public void append(final DeleteCommand<T> command) { + public void append(final KeepCommand<T> command) { commands.add(command); - ++modifications; - } - - /** - * Visits the script. The script implements the <em>visitor</em> design - * pattern, this method is the entry point to which the user supplies its - * own visitor, the script will be responsible to drive it through the - * commands in order and call the appropriate method as each command is - * encountered. - * - * @param visitor the visitor that will visit all commands in turn - */ - public void visit(final CommandVisitor<T> visitor) { - for (final EditCommand<T> command : commands) { - command.accept(visitor); - } + ++lcsLength; } /** @@ -132,4 +117,19 @@ public class EditScript<T> { return modifications; } + /** + * Visits the script. The script implements the <em>visitor</em> design + * pattern, this method is the entry point to which the user supplies its + * own visitor, the script will be responsible to drive it through the + * commands in order and call the appropriate method as each command is + * encountered. + * + * @param visitor the visitor that will visit all commands in turn + */ + public void visit(final CommandVisitor<T> visitor) { + for (final EditCommand<T> command : commands) { + command.accept(visitor); + } + } + } diff --git a/src/main/java/org/apache/commons/text/diff/ReplacementsFinder.java b/src/main/java/org/apache/commons/text/diff/ReplacementsFinder.java index a701b12..1e6ede1 100644 --- a/src/main/java/org/apache/commons/text/diff/ReplacementsFinder.java +++ b/src/main/java/org/apache/commons/text/diff/ReplacementsFinder.java @@ -83,6 +83,16 @@ public class ReplacementsFinder<T> implements CommandVisitor<T> { } /** + * Add an object to the pending deletions set. + * + * @param object object to delete + */ + @Override + public void visitDeleteCommand(final T object) { + pendingDeletions.add(object); + } + + /** * Add an object to the pending insertions set. * * @param object object to insert @@ -113,14 +123,4 @@ public class ReplacementsFinder<T> implements CommandVisitor<T> { } } - /** - * Add an object to the pending deletions set. - * - * @param object object to delete - */ - @Override - public void visitDeleteCommand(final T object) { - pendingDeletions.add(object); - } - } diff --git a/src/main/java/org/apache/commons/text/diff/StringsComparator.java b/src/main/java/org/apache/commons/text/diff/StringsComparator.java index 90d53bb..477a8b4 100644 --- a/src/main/java/org/apache/commons/text/diff/StringsComparator.java +++ b/src/main/java/org/apache/commons/text/diff/StringsComparator.java @@ -53,6 +53,61 @@ package org.apache.commons.text.diff; public class StringsComparator { /** + * This class is a simple placeholder to hold the end part of a path + * under construction in a {@link StringsComparator StringsComparator}. + */ + private static class Snake { + + /** Start index. */ + private final int start; + + /** End index. */ + private final int end; + + /** Diagonal number. */ + private final int diag; + + /** + * Constructs a new instance of Snake with specified indices. + * + * @param start start index of the snake + * @param end end index of the snake + * @param diag diagonal number + */ + Snake(final int start, final int end, final int diag) { + this.start = start; + this.end = end; + this.diag = diag; + } + + /** + * Gets the diagonal number of the snake. + * + * @return diagonal number of the snake + */ + public int getDiag() { + return diag; + } + + /** + * Gets the end index of the snake. + * + * @return end index of the snake + */ + public int getEnd() { + return end; + } + + /** + * Gets the start index of the snake. + * + * @return start index of the snake + */ + public int getStart() { + return start; + } + } + /** * First character sequence. */ private final String left; @@ -64,6 +119,7 @@ public class StringsComparator { * Temporary array. */ private final int[] vDown; + /** * Temporary array. */ @@ -92,26 +148,6 @@ public class StringsComparator { } /** - * Gets the {@link EditScript} object. - * <p> - * It is guaranteed that the objects embedded in the {@link InsertCommand - * insert commands} come from the second sequence and that the objects - * embedded in either the {@link DeleteCommand delete commands} or - * {@link KeepCommand keep commands} come from the first sequence. This can - * be important if subclassing is used for some elements in the first - * sequence and the {@code equals} method is specialized. - * </p> - * - * @return The edit script resulting from the comparison of the two - * sequences - */ - public EditScript<Character> getScript() { - final EditScript<Character> script = new EditScript<>(); - buildScript(0, left.length(), 0, right.length(), script); - return script; - } - - /** * Builds an edit script. * * @param start1 the begin of the first sequence to be compared @@ -161,6 +197,25 @@ public class StringsComparator { } /** + * Builds a snake. + * + * @param start the value of the start of the snake + * @param diag the value of the diagonal of the snake + * @param end1 the value of the end of the first sequence to be compared + * @param end2 the value of the end of the second sequence to be compared + * @return The snake built + */ + private Snake buildSnake(final int start, final int diag, final int end1, final int end2) { + int end = start; + while (end - diag < end2 + && end < end1 + && left.charAt(end) == right.charAt(end - diag)) { + ++end; + } + return new Snake(start, end, diag); + } + + /** * Gets the middle snake corresponding to two subsequences of the * main sequences. * <p> @@ -251,78 +306,23 @@ public class StringsComparator { } /** - * Builds a snake. + * Gets the {@link EditScript} object. + * <p> + * It is guaranteed that the objects embedded in the {@link InsertCommand + * insert commands} come from the second sequence and that the objects + * embedded in either the {@link DeleteCommand delete commands} or + * {@link KeepCommand keep commands} come from the first sequence. This can + * be important if subclassing is used for some elements in the first + * sequence and the {@code equals} method is specialized. + * </p> * - * @param start the value of the start of the snake - * @param diag the value of the diagonal of the snake - * @param end1 the value of the end of the first sequence to be compared - * @param end2 the value of the end of the second sequence to be compared - * @return The snake built - */ - private Snake buildSnake(final int start, final int diag, final int end1, final int end2) { - int end = start; - while (end - diag < end2 - && end < end1 - && left.charAt(end) == right.charAt(end - diag)) { - ++end; - } - return new Snake(start, end, diag); - } - - /** - * This class is a simple placeholder to hold the end part of a path - * under construction in a {@link StringsComparator StringsComparator}. + * @return The edit script resulting from the comparison of the two + * sequences */ - private static class Snake { - - /** Start index. */ - private final int start; - - /** End index. */ - private final int end; - - /** Diagonal number. */ - private final int diag; - - /** - * Constructs a new instance of Snake with specified indices. - * - * @param start start index of the snake - * @param end end index of the snake - * @param diag diagonal number - */ - Snake(final int start, final int end, final int diag) { - this.start = start; - this.end = end; - this.diag = diag; - } - - /** - * Gets the start index of the snake. - * - * @return start index of the snake - */ - public int getStart() { - return start; - } - - /** - * Gets the end index of the snake. - * - * @return end index of the snake - */ - public int getEnd() { - return end; - } - - /** - * Gets the diagonal number of the snake. - * - * @return diagonal number of the snake - */ - public int getDiag() { - return diag; - } + public EditScript<Character> getScript() { + final EditScript<Character> script = new EditScript<>(); + buildScript(0, left.length(), 0, right.length(), script); + return script; } }