Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit a9a2ca4

Browse files
committed
Remove Guava dependency
1 parent c38d216 commit a9a2ca4

9 files changed

+522
-591
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ A fork of [java-diff-utils](https://code.google.com/p/java-diff-utils/)
22

33
# Changelog
44

5+
## 2.1.0
6+
7+
- Removes the dependency on Guava
8+
59
## 2.0.0
610

7-
- Change groupId and artifactId to prevent conflit with origin library: now 'com.github.java-diff-utils:java-diff-utils' instead of 'jp.skypencil.java-diff-utils:diffutils'
11+
- Change groupId and artifactId to prevent conflict with origin library: now 'com.github.java-diff-utils:java-diff-utils' instead of 'jp.skypencil.java-diff-utils:diffutils'
812
- Adds the ability to differentiate the inserted and deleted tags and class-names in inline-diff
913
- Default class-name is now `null` for deleted and inserted data, and "`change`" for change data
1014
- Default tag for deleted data is `del`

build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ repositories {
3434
}
3535

3636
dependencies {
37-
compile group: 'com.google.guava', name: 'guava', version:'18.0'
3837
compile group: 'com.google.code.findbugs', name: 'jsr305', version:'3.0.0'
3938
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version:'1.3'
4039
testCompile group: 'junit', name: 'junit', version:'4.12'

src/main/java/difflib/ChangeDelta.java

+9-11
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,22 @@
1919

2020
/**
2121
* Describes the change-delta between original and revised texts.
22-
*
23-
* @author <a href="[email protected]">Dmitry Naumenko</a>
2422
* @param T The type of the compared elements in the 'lines'.
23+
* @author <a href="[email protected]">Dmitry Naumenko</a>
2524
*/
2625
public class ChangeDelta<T> extends Delta<T> {
27-
26+
2827
/**
2928
* Creates a change delta with the two given chunks.
3029
* @param original The original chunk. Must not be {@code null}.
31-
* @param revised The original chunk. Must not be {@code null}.
30+
* @param revised The original chunk. Must not be {@code null}.
3231
*/
33-
public ChangeDelta(Chunk<T> original, Chunk<T>revised) {
34-
super(original, revised);
32+
public ChangeDelta(Chunk<T> original, Chunk<T> revised) {
33+
super(original, revised);
3534
}
36-
35+
3736
/**
3837
* {@inheritDoc}
39-
*
4038
* @throws PatchFailedException
4139
*/
4240
@Override
@@ -53,7 +51,7 @@ public void applyTo(List<T> target) throws PatchFailedException {
5351
i++;
5452
}
5553
}
56-
54+
5755
/**
5856
* {@inheritDoc}
5957
*/
@@ -70,7 +68,7 @@ public void restore(List<T> target) {
7068
i++;
7169
}
7270
}
73-
71+
7472
/**
7573
* {@inheritDoc}
7674
*/
@@ -81,7 +79,7 @@ public void verify(List<T> target) throws PatchFailedException {
8179
+ "delta original position > target size");
8280
}
8381
}
84-
82+
8583
@Override
8684
public String toString() {
8785
return "[ChangeDelta, position: " + getOriginal().getPosition() + ", lines: "

src/main/java/difflib/Chunk.java

+23-41
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,48 @@
1515
*/
1616
package difflib;
1717

18-
import static com.google.common.base.Preconditions.checkArgument;
19-
18+
import javax.annotation.Nonnegative;
2019
import java.util.Arrays;
2120
import java.util.List;
2221

23-
import javax.annotation.Nonnegative;
24-
2522
/**
26-
* Holds the information about the part of text involved in the diff process
27-
*
28-
* <p>
29-
* Text is represented as <code>Object[]</code> because the diff engine is
30-
* capable of handling more than plain ascci. In fact, arrays or lists of any
31-
* type that implements {@link java.lang.Object#hashCode hashCode()} and
32-
* {@link java.lang.Object#equals equals()} correctly can be subject to
33-
* differencing using this library.
34-
* </p>
35-
*
36-
* @author <a href="[email protected]>Dmitry Naumenko</a>
23+
* Holds the information about the part of text involved in the diff process <p> Text is represented as
24+
* <code>Object[]</code> because the diff engine is capable of handling more than plain ascci. In fact, arrays or lists
25+
* of any type that implements {@link java.lang.Object#hashCode hashCode()} and {@link java.lang.Object#equals equals()}
26+
* correctly can be subject to differencing using this library. </p>
3727
* @param T The type of the compared elements in the 'lines'.
28+
* @author <a href="[email protected]>Dmitry Naumenko</a>
3829
*/
3930
public class Chunk<T> {
4031
@Nonnegative
4132
private final int position;
4233
private List<T> lines;
43-
34+
4435
/**
4536
* Creates a chunk and saves a copy of affected lines
46-
*
47-
* @param position
48-
* the start position
49-
* @param lines
50-
* the affected lines
37+
* @param position the start position
38+
* @param lines the affected lines
5139
*/
5240
public Chunk(@Nonnegative int position, List<T> lines) {
53-
checkArgument(position >= 0);
41+
if (position < 0) throw new IllegalArgumentException();
5442
this.position = position;
5543
this.lines = lines;
5644
}
57-
45+
5846
/**
5947
* Creates a chunk and saves a copy of affected lines
60-
*
61-
* @param position
62-
* the start position (zero-based numbering)
63-
* @param lines
64-
* the affected lines
48+
* @param position the start position (zero-based numbering)
49+
* @param lines the affected lines
6550
*/
6651
public Chunk(@Nonnegative int position, T[] lines) {
67-
checkArgument(position >= 0);
52+
if (position < 0) throw new IllegalArgumentException();
6853
this.position = position;
6954
this.lines = Arrays.asList(lines);
7055
}
71-
56+
7257
/**
73-
* Verifies that this chunk's saved text matches the corresponding text in
74-
* the given sequence.
75-
*
76-
* @param target
77-
* the sequence to verify against.
58+
* Verifies that this chunk's saved text matches the corresponding text in the given sequence.
59+
* @param target the sequence to verify against.
7860
*/
7961
public void verify(List<T> target) throws PatchFailedException {
8062
if (last() > target.size()) {
@@ -87,7 +69,7 @@ public void verify(List<T> target) throws PatchFailedException {
8769
}
8870
}
8971
}
90-
72+
9173
/**
9274
* @return the start position of chunk in the text (zero-based numbering)
9375
*/
@@ -111,15 +93,15 @@ public List<T> getLines() {
11193
public int size() {
11294
return lines.size();
11395
}
114-
96+
11597
/**
11698
* Returns the index of the last line of the chunk. (zero-based numbering)
11799
*/
118100
@Nonnegative
119101
public int last() {
120102
return getPosition() + size() - 1;
121103
}
122-
104+
123105
/*
124106
* (non-Javadoc)
125107
*
@@ -134,7 +116,7 @@ public int hashCode() {
134116
result = prime * result + size();
135117
return result;
136118
}
137-
119+
138120
/*
139121
* (non-Javadoc)
140122
*
@@ -158,10 +140,10 @@ public boolean equals(Object obj) {
158140
return false;
159141
return true;
160142
}
161-
143+
162144
@Override
163145
public String toString() {
164146
return "[position: " + position + ", size: " + size() + ", lines: " + lines + "]";
165147
}
166-
148+
167149
}

src/main/java/difflib/DiffRow.java

+13-17
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
*/
1616
package difflib;
1717

18-
import static com.google.common.base.Preconditions.checkNotNull;
19-
2018
import javax.annotation.Nonnull;
2119
import javax.annotation.Nullable;
2220

2321
/**
24-
* Describes the diff row in form [tag, oldLine, newLine) for showing the
25-
* difference between two texts
26-
*
22+
* Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two texts
2723
* @author <a href="[email protected]">Dmitry Naumenko</a>
2824
*/
2925
public class DiffRow {
@@ -33,62 +29,62 @@ public class DiffRow {
3329
private String oldLine;
3430
@Nullable
3531
private String newLine;
36-
32+
3733
public DiffRow(@Nonnull Tag tag, @Nullable String oldLine, @Nullable String newLine) {
38-
this.tag = checkNotNull(tag);
34+
this.tag = tag;
3935
this.oldLine = oldLine;
4036
this.newLine = newLine;
4137
}
42-
38+
4339
public static enum Tag {
4440
INSERT, DELETE, CHANGE, EQUAL, SKIP
4541
}
46-
42+
4743
/**
4844
* @return the tag
4945
*/
5046
@Nonnull
5147
public Tag getTag() {
5248
return tag;
5349
}
54-
50+
5551
/**
5652
* @param tag the tag to set
5753
*/
5854
public void setTag(Tag tag) {
5955
this.tag = tag;
6056
}
61-
57+
6258
/**
6359
* @return the oldLine
6460
*/
6561
@Nullable
6662
public String getOldLine() {
6763
return oldLine;
6864
}
69-
65+
7066
/**
7167
* @param oldLine the oldLine to set
7268
*/
7369
public void setOldLine(@Nullable String oldLine) {
7470
this.oldLine = oldLine;
7571
}
76-
72+
7773
/**
7874
* @return the newLine
7975
*/
8076
@Nullable
8177
public String getNewLine() {
8278
return newLine;
8379
}
84-
80+
8581
/**
8682
* @param newLine the newLine to set
8783
*/
8884
public void setNewLine(@Nullable String newLine) {
8985
this.newLine = newLine;
9086
}
91-
87+
9288
/*
9389
* (non-Javadoc)
9490
*
@@ -103,7 +99,7 @@ public int hashCode() {
10399
result = prime * result + ((tag == null) ? 0 : tag.hashCode());
104100
return result;
105101
}
106-
102+
107103
/*
108104
* (non-Javadoc)
109105
*
@@ -135,7 +131,7 @@ public boolean equals(Object obj) {
135131
return false;
136132
return true;
137133
}
138-
134+
139135
public String toString() {
140136
return "[" + this.tag + "," + this.oldLine + "," + this.newLine + "]";
141137
}

0 commit comments

Comments
 (0)