Skip to content

Commit 5ad524c

Browse files
hansonrhansonr
authored andcommitted
corrects missing hashCode()
1 parent 5a28d57 commit 5ad524c

File tree

1 file changed

+22
-17
lines changed
  • sources/net.sf.j2s.java.core/src/java/io

1 file changed

+22
-17
lines changed

sources/net.sf.j2s.java.core/src/java/io/File.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ public File getAbsoluteFile() {
596596
* @since JDK1.1
597597
*/
598598
public String getCanonicalPath() throws IOException {
599-
return this.path;
599+
return this.path.replace('\\', '/');
600600
// return fs.canonicalize(fs.resolve(this));
601601
}
602602

@@ -1951,23 +1951,28 @@ public boolean equals(Object obj) {
19511951
return false;
19521952
}
19531953

1954-
// /**
1955-
// * Computes a hash code for this abstract pathname. Because equality of
1956-
// * abstract pathnames is inherently system-dependent, so is the computation
1957-
// * of their hash codes. On UNIX systems, the hash code of an abstract
1958-
// * pathname is equal to the exclusive <em>or</em> of the hash code
1959-
// * of its pathname string and the decimal value
1960-
// * <code>1234321</code>. On Microsoft Windows systems, the hash
1961-
// * code is equal to the exclusive <em>or</em> of the hash code of
1962-
// * its pathname string converted to lower case and the decimal
1963-
// * value <code>1234321</code>. Locale is not taken into account on
1964-
// * lowercasing the pathname string.
1965-
// *
1966-
// * @return A hash code for this abstract pathname
1967-
// */
1968-
// public int hashCode() {
1954+
/**
1955+
* Computes a hash code for this abstract pathname. Because equality of
1956+
* abstract pathnames is inherently system-dependent, so is the computation
1957+
* of their hash codes. On UNIX systems, the hash code of an abstract
1958+
* pathname is equal to the exclusive <em>or</em> of the hash code
1959+
* of its pathname string and the decimal value
1960+
* <code>1234321</code>. On Microsoft Windows systems, the hash
1961+
* code is equal to the exclusive <em>or</em> of the hash code of
1962+
* its pathname string converted to lower case and the decimal
1963+
* value <code>1234321</code>. Locale is not taken into account on
1964+
* lowercasing the pathname string.
1965+
*
1966+
* @return A hash code for this abstract pathname
1967+
*/
1968+
public int hashCode() {
1969+
try {
1970+
return this.getCanonicalPath().hashCode() | 1234321;
1971+
} catch (IOException e) {
1972+
return 0;
1973+
}
19691974
// return fs.hashCode(this);
1970-
// }
1975+
}
19711976

19721977
/**
19731978
* Returns the pathname string of this abstract pathname. This is just the

0 commit comments

Comments
 (0)