[jboss-cvs] JBossAS SVN: r101751 - projects/vfs/trunk/src/main/java/org/jboss/vfs.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 3 01:02:57 EST 2010
Author: david.lloyd at jboss.com
Date: 2010-03-03 01:02:56 -0500 (Wed, 03 Mar 2010)
New Revision: 101751
Modified:
projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
Log:
Replace equals with a better one
Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java 2010-03-03 05:26:44 UTC (rev 101750)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VirtualFile.java 2010-03-03 06:02:56 UTC (rev 101751)
@@ -492,20 +492,24 @@
* @return {@code true} if they are equal
*/
public boolean equals(Object o) {
- if (this == o)
- return true;
- if (!(o instanceof VirtualFile))
+ return o instanceof VirtualFile && equals((VirtualFile) o);
+ }
+
+ /**
+ * Determine whether the given object is equal to this one. Returns true if the argument is a {@code VirtualFile}
+ * from the same {@code VFS} instance with the same name.
+ *
+ * @param o the other virtual file
+ *
+ * @return {@code true} if they are equal
+ */
+ public boolean equals(VirtualFile o) {
+ if (o != this || o == null || hashCode != o.hashCode || ! name.equals(o.name)) {
return false;
- VirtualFile that = (VirtualFile) o;
- if (hashCode != that.hashCode)
- return false;
- if (!name.equals(that.name))
- return false;
+ }
final VirtualFile parent = this.parent;
- if (parent == null)
- return that.parent == null;
- else
- return parent.equals(that.parent);
+ final VirtualFile oparent = o.parent;
+ return parent != null && parent.equals(oparent) || oparent == null;
}
/**
More information about the jboss-cvs-commits
mailing list