summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias <t.warneke@gmx.net>2018-10-28 18:08:50 +0100
committerGitHub <noreply@github.com>2018-10-28 18:08:50 +0100
commitf88ce15ff8dfd86f075e531250233d62ab50e6aa (patch)
tree257292d7f71629579d7e59a7bd063b5f724cca1d
parentd4f114226d1e76ddc28f96281d74d836f8651876 (diff)
parent306f92684f864da3e1cca77275f03a8f071c0784 (diff)
Merge pull request #27 from koppor/use-objects-hash
Use Objects.hash() instead of custom hashCode() method
-rw-r--r--src/main/java/com/github/difflib/patch/AbstractDelta.java6
-rw-r--r--src/main/java/com/github/difflib/patch/Chunk.java18
-rw-r--r--src/main/java/com/github/difflib/text/DiffRow.java18
3 files changed, 5 insertions, 37 deletions
diff --git a/src/main/java/com/github/difflib/patch/AbstractDelta.java b/src/main/java/com/github/difflib/patch/AbstractDelta.java
index 30de287..9f1fb45 100644
--- a/src/main/java/com/github/difflib/patch/AbstractDelta.java
+++ b/src/main/java/com/github/difflib/patch/AbstractDelta.java
@@ -63,11 +63,7 @@ public abstract class AbstractDelta<T> {
@Override
public int hashCode() {
- int hash = 3;
- hash = 61 * hash + Objects.hashCode(this.source);
- hash = 61 * hash + Objects.hashCode(this.target);
- hash = 61 * hash + Objects.hashCode(this.type);
- return hash;
+ return Objects.hash(this.source, this.target, this.type);
}
@Override
diff --git a/src/main/java/com/github/difflib/patch/Chunk.java b/src/main/java/com/github/difflib/patch/Chunk.java
index 3812be0..7871c71 100644
--- a/src/main/java/com/github/difflib/patch/Chunk.java
+++ b/src/main/java/com/github/difflib/patch/Chunk.java
@@ -21,6 +21,7 @@ package com.github.difflib.patch;
import java.util.Arrays;
import java.util.List;
+import java.util.Objects;
/**
* Holds the information about the part of text involved in the diff process
@@ -108,26 +109,11 @@ public final class Chunk<T> {
return getPosition() + size() - 1;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((lines == null) ? 0 : lines.hashCode());
- result = prime * result + position;
- result = prime * result + size();
- return result;
+ return Objects.hash(lines, position, size());
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/src/main/java/com/github/difflib/text/DiffRow.java b/src/main/java/com/github/difflib/text/DiffRow.java
index dd8cd9d..95fa61f 100644
--- a/src/main/java/com/github/difflib/text/DiffRow.java
+++ b/src/main/java/com/github/difflib/text/DiffRow.java
@@ -20,6 +20,7 @@ limitations under the License.
package com.github.difflib.text;
import java.io.Serializable;
+import java.util.Objects;
/**
* Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two texts
@@ -70,26 +71,11 @@ public final class DiffRow implements Serializable {
return newLine;
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((newLine == null) ? 0 : newLine.hashCode());
- result = prime * result + ((oldLine == null) ? 0 : oldLine.hashCode());
- result = prime * result + ((tag == null) ? 0 : tag.hashCode());
- return result;
+ return Objects.hash(newLine, oldLine, tag);
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object obj) {
if (this == obj) {