Skip to content

Commit f88ce15

Browse files
authored
Merge pull request #27 from koppor/use-objects-hash
Use Objects.hash() instead of custom hashCode() method
2 parents d4f1142 + 306f926 commit f88ce15

File tree

3 files changed

+5
-37
lines changed

3 files changed

+5
-37
lines changed

src/main/java/com/github/difflib/patch/AbstractDelta.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,7 @@ protected void verifyChunk(List<T> target) throws PatchFailedException {
6363

6464
@Override
6565
public int hashCode() {
66-
int hash = 3;
67-
hash = 61 * hash + Objects.hashCode(this.source);
68-
hash = 61 * hash + Objects.hashCode(this.target);
69-
hash = 61 * hash + Objects.hashCode(this.type);
70-
return hash;
66+
return Objects.hash(this.source, this.target, this.type);
7167
}
7268

7369
@Override

src/main/java/com/github/difflib/patch/Chunk.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.Arrays;
2323
import java.util.List;
24+
import java.util.Objects;
2425

2526
/**
2627
* Holds the information about the part of text involved in the diff process
@@ -108,26 +109,11 @@ public int last() {
108109
return getPosition() + size() - 1;
109110
}
110111

111-
/*
112-
* (non-Javadoc)
113-
*
114-
* @see java.lang.Object#hashCode()
115-
*/
116112
@Override
117113
public int hashCode() {
118-
final int prime = 31;
119-
int result = 1;
120-
result = prime * result + ((lines == null) ? 0 : lines.hashCode());
121-
result = prime * result + position;
122-
result = prime * result + size();
123-
return result;
114+
return Objects.hash(lines, position, size());
124115
}
125116

126-
/*
127-
* (non-Javadoc)
128-
*
129-
* @see java.lang.Object#equals(java.lang.Object)
130-
*/
131117
@Override
132118
public boolean equals(Object obj) {
133119
if (this == obj) {

src/main/java/com/github/difflib/text/DiffRow.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package com.github.difflib.text;
2121

2222
import java.io.Serializable;
23+
import java.util.Objects;
2324

2425
/**
2526
* Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two texts
@@ -70,26 +71,11 @@ public String getNewLine() {
7071
return newLine;
7172
}
7273

73-
/*
74-
* (non-Javadoc)
75-
*
76-
* @see java.lang.Object#hashCode()
77-
*/
7874
@Override
7975
public int hashCode() {
80-
final int prime = 31;
81-
int result = 1;
82-
result = prime * result + ((newLine == null) ? 0 : newLine.hashCode());
83-
result = prime * result + ((oldLine == null) ? 0 : oldLine.hashCode());
84-
result = prime * result + ((tag == null) ? 0 : tag.hashCode());
85-
return result;
76+
return Objects.hash(newLine, oldLine, tag);
8677
}
8778

88-
/*
89-
* (non-Javadoc)
90-
*
91-
* @see java.lang.Object#equals(java.lang.Object)
92-
*/
9379
@Override
9480
public boolean equals(Object obj) {
9581
if (this == obj) {

0 commit comments

Comments
 (0)