refactored some packages

This commit is contained in:
wumpz
2017-04-03 14:06:50 +02:00
parent 3363b2ceb0
commit 23539d9257
7 changed files with 32 additions and 58 deletions

View File

@@ -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;
}
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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()

View File

@@ -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

View File

@@ -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.*;

View File

@@ -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;