mirror of
https://github.com/java-diff-utils/java-diff-utils.git
synced 2026-03-13 10:11:17 +08:00
refactored some packages
This commit is contained in:
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
|
||||
* @param T The type of the compared elements in the 'lines'.
|
||||
*/
|
||||
public class ChangeDelta<T> extends Delta<T> {
|
||||
public final class ChangeDelta<T> extends Delta<T> {
|
||||
|
||||
/**
|
||||
* Creates a change delta with the two given chunks.
|
||||
@@ -32,7 +32,7 @@ public class ChangeDelta<T> extends Delta<T> {
|
||||
* @param revised The original chunk. Must not be {@code null}.
|
||||
*/
|
||||
public ChangeDelta(Chunk<T> original, Chunk<T> revised) {
|
||||
super(original, revised);
|
||||
super(TYPE.CHANGE, original, revised);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,9 +89,4 @@ public class ChangeDelta<T> extends Delta<T> {
|
||||
return "[ChangeDelta, position: " + getOriginal().getPosition() + ", lines: "
|
||||
+ getOriginal().getLines() + " to " + getRevised().getLines() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE getType() {
|
||||
return Delta.TYPE.CHANGE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
|
||||
* @param T The type of the compared elements in the 'lines'.
|
||||
*/
|
||||
public class DeleteDelta<T> extends Delta<T> {
|
||||
public final class DeleteDelta<T> extends Delta<T> {
|
||||
|
||||
/**
|
||||
* Creates a change delta with the two given chunks.
|
||||
@@ -32,7 +32,7 @@ public class DeleteDelta<T> extends Delta<T> {
|
||||
* @param revised The original chunk. Must not be {@code null}.
|
||||
*/
|
||||
public DeleteDelta(Chunk<T> original, Chunk<T> revised) {
|
||||
super(original, revised);
|
||||
super(TYPE.DELETE, original, revised);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,11 +62,6 @@ public class DeleteDelta<T> extends Delta<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE getType() {
|
||||
return Delta.TYPE.DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void verify(List<T> target) throws PatchFailedException {
|
||||
getOriginal().verify(target);
|
||||
|
||||
@@ -25,21 +25,15 @@ import java.util.*;
|
||||
*/
|
||||
public abstract class Delta<T> {
|
||||
|
||||
/**
|
||||
* The original chunk.
|
||||
*/
|
||||
private Chunk<T> original;
|
||||
|
||||
/**
|
||||
* The revised chunk.
|
||||
*/
|
||||
private Chunk<T> revised;
|
||||
private final TYPE deltaType;
|
||||
private final Chunk<T> original;
|
||||
private final Chunk<T> revised;
|
||||
|
||||
/**
|
||||
* Specifies the type of the delta.
|
||||
*
|
||||
*/
|
||||
public enum TYPE {
|
||||
public static enum TYPE {
|
||||
/**
|
||||
* A change in the original.
|
||||
*/
|
||||
@@ -60,13 +54,17 @@ public abstract class Delta<T> {
|
||||
* @param original Chunk describing the original text. Must not be {@code null}.
|
||||
* @param revised Chunk describing the revised text. Must not be {@code null}.
|
||||
*/
|
||||
public Delta(Chunk<T> original, Chunk<T> revised) {
|
||||
public Delta(TYPE deltaType, Chunk<T> original, Chunk<T> revised) {
|
||||
if (deltaType == null) {
|
||||
throw new IllegalArgumentException("deltaType must not be null");
|
||||
}
|
||||
if (original == null) {
|
||||
throw new IllegalArgumentException("original must not be null");
|
||||
}
|
||||
if (revised == null) {
|
||||
throw new IllegalArgumentException("revised must not be null");
|
||||
}
|
||||
this.deltaType = deltaType;
|
||||
this.original = original;
|
||||
this.revised = revised;
|
||||
}
|
||||
@@ -94,12 +92,9 @@ public abstract class Delta<T> {
|
||||
*/
|
||||
public abstract void restore(List<T> target);
|
||||
|
||||
/**
|
||||
* Returns the type of delta
|
||||
*
|
||||
* @return the type enum
|
||||
*/
|
||||
public abstract TYPE getType();
|
||||
public final TYPE getType() {
|
||||
return deltaType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Chunk describing the original text.
|
||||
@@ -108,13 +103,6 @@ public abstract class Delta<T> {
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param original The Chunk describing the original text to set.
|
||||
*/
|
||||
public void setOriginal(Chunk<T> original) {
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Chunk describing the revised text.
|
||||
*/
|
||||
@@ -122,13 +110,6 @@ public abstract class Delta<T> {
|
||||
return revised;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param revised The Chunk describing the revised text to set.
|
||||
*/
|
||||
public void setRevised(Chunk<T> revised) {
|
||||
this.revised = revised;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
|
||||
* @param T The type of the compared elements in the 'lines'.
|
||||
*/
|
||||
public class InsertDelta<T> extends Delta<T> {
|
||||
public final class InsertDelta<T> extends Delta<T> {
|
||||
|
||||
/**
|
||||
* Creates an insert delta with the two given chunks.
|
||||
@@ -32,7 +32,7 @@ public class InsertDelta<T> extends Delta<T> {
|
||||
* @param revised The original chunk. Must not be {@code null}.
|
||||
*/
|
||||
public InsertDelta(Chunk<T> original, Chunk<T> revised) {
|
||||
super(original, revised);
|
||||
super(TYPE.INSERT, original, revised);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,11 +71,6 @@ public class InsertDelta<T> extends Delta<T> {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE getType() {
|
||||
return Delta.TYPE.INSERT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[InsertDelta, position: " + getOriginal().getPosition()
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package difflib;
|
||||
package difflib.rows;
|
||||
|
||||
/**
|
||||
* Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two
|
||||
@@ -13,9 +13,17 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
package difflib;
|
||||
package difflib.rows;
|
||||
|
||||
import difflib.DiffRow.Tag;
|
||||
import difflib.ChangeDelta;
|
||||
import difflib.Chunk;
|
||||
import difflib.DeleteDelta;
|
||||
import difflib.Delta;
|
||||
import difflib.rows.DiffRow.Tag;
|
||||
import difflib.DiffUtils;
|
||||
import difflib.InsertDelta;
|
||||
import difflib.Patch;
|
||||
import difflib.StringUtils;
|
||||
import difflib.myers.Equalizer;
|
||||
import java.util.*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package diffutils;
|
||||
package diffutils.rows;
|
||||
|
||||
import difflib.DiffRow;
|
||||
import difflib.DiffRowGenerator;
|
||||
import difflib.rows.DiffRow;
|
||||
import difflib.rows.DiffRowGenerator;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
Reference in New Issue
Block a user