Skip to content

Commit 84101b9

Browse files
committed
FileSignature now supports .equals and .hashCode without serialization.
1 parent bcd40d5 commit 84101b9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/src/main/java/com/diffplug/spotless/FileSignature.java

+29
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ synchronized Sig sign(File fileInput) throws IOException {
174174
}
175175
}
176176

177+
@Override
178+
public boolean equals(Object other) {
179+
if (other instanceof FileSignature) {
180+
return Arrays.equals(signatures, ((FileSignature) other).signatures);
181+
} else {
182+
return false;
183+
}
184+
}
185+
186+
@Override
187+
public int hashCode() {
188+
return Arrays.hashCode(signatures);
189+
}
190+
177191
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
178192
private static final class Sig implements Serializable {
179193
private static final long serialVersionUID = 6727302747168655222L;
@@ -193,6 +207,21 @@ private static final class Sig implements Serializable {
193207
this.hash = hash;
194208
this.lastModified = lastModified;
195209
}
210+
211+
@Override
212+
public boolean equals(Object other) {
213+
if (other instanceof Sig) {
214+
Sig o = (Sig) other;
215+
return name.equals(o.name) && size == o.size && Arrays.equals(hash, o.hash);
216+
} else {
217+
return false;
218+
}
219+
}
220+
221+
@Override
222+
public int hashCode() {
223+
return Arrays.hashCode(hash) | name.hashCode();
224+
}
196225
}
197226

198227
/** Asserts that child is a subpath of root. and returns the subpath. */

0 commit comments

Comments
 (0)