OSDN Git Service

Override equals and hashCode on FileHandle
authorJustin Shapcott <support@mobidevelop.com>
Fri, 11 Oct 2013 04:51:01 +0000 (21:51 -0700)
committerJustin Shapcott <support@mobidevelop.com>
Fri, 11 Oct 2013 04:51:01 +0000 (21:51 -0700)
FileHandles having the same type and path should be considered equal.

gdx/src/com/badlogic/gdx/files/FileHandle.java

index 3332066..3a23039 100644 (file)
@@ -579,6 +579,21 @@ public class FileHandle {
                return file().lastModified();\r
        }\r
 \r
+       @Override\r
+       public boolean equals (Object obj) {\r
+               if (!(obj instanceof FileHandle)) return false;\r
+               FileHandle other = (FileHandle)obj;\r
+               return type == other.type && path().equals(other.path());\r
+       }\r
+\r
+       @Override\r
+       public int hashCode () {\r
+               int hash = 1;\r
+               hash = hash * 37 + type.hashCode();\r
+               hash = hash * 67 + path().hashCode();\r
+               return hash;\r
+       }\r
+\r
        public String toString () {\r
                return file.getPath().replace('\\', '/');\r
        }\r