summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-05-08 02:36:30 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-05-22 08:12:51 +0200
commit201bbd6eadabef7f386fa936a505b9312519ab4e (patch)
tree2c9d4c73a03e0cb3d5e96e57a7c3e0aecd6ac50d /org.eclipse.jgit/src/org
parented2e515ddff192ee8fd121e8bb6566b4e5ab33f2 (diff)
downloadjgit-201bbd6eadabef7f386fa936a505b9312519ab4e.tar.gz
jgit-201bbd6eadabef7f386fa936a505b9312519ab4e.zip
Fix FileSnapshot's consideration of file size
* fix equals() and hashCode() methods to consider size * fix toString() to show size Change-Id: I5485db55eda5110121efd65d86c7166b3b2e93d0 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java42
1 files changed, 26 insertions, 16 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
index f26eba3360..cd72c8198e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java
@@ -50,6 +50,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
+import java.util.Objects;
import org.eclipse.jgit.util.FS;
@@ -235,37 +236,46 @@ public class FileSnapshot {
* @return true if the two snapshots share the same information.
*/
public boolean equals(FileSnapshot other) {
- return lastModified == other.lastModified;
+ return lastModified == other.lastModified && size == other.size;
}
/** {@inheritDoc} */
@Override
- public boolean equals(Object other) {
- if (other instanceof FileSnapshot)
- return equals((FileSnapshot) other);
- return false;
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof FileSnapshot)) {
+ return false;
+ }
+ FileSnapshot other = (FileSnapshot) obj;
+ return equals(other);
}
/** {@inheritDoc} */
@Override
public int hashCode() {
- // This is pretty pointless, but override hashCode to ensure that
- // x.hashCode() == y.hashCode() when x.equals(y) is true.
- //
- return (int) lastModified;
+ return Objects.hash(Long.valueOf(lastModified), Long.valueOf(size));
}
/** {@inheritDoc} */
+ @SuppressWarnings("nls")
@Override
public String toString() {
- if (this == DIRTY)
- return "DIRTY"; //$NON-NLS-1$
- if (this == MISSING_FILE)
- return "MISSING_FILE"; //$NON-NLS-1$
- DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", //$NON-NLS-1$
+ if (this == DIRTY) {
+ return "DIRTY";
+ }
+ if (this == MISSING_FILE) {
+ return "MISSING_FILE";
+ }
+ DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS",
Locale.US);
- return "FileSnapshot[modified: " + f.format(new Date(lastModified)) //$NON-NLS-1$
- + ", read: " + f.format(new Date(lastRead)) + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ return "FileSnapshot[modified: " + f.format(new Date(lastModified))
+ + ", read: " + f.format(new Date(lastRead)) + ", size:" + size
+ + "]";
}
private boolean notRacyClean(long read) {