Hello Bruno,
Thanks for your email.
On Feb 20, 2007, at 3:46 AM, Bruno DOREL wrote:
High all
A little sum up
I made somme changes to Slide code to avoid Uri's leak of memory (I
have used JProfiler to monitor the heap and see several Uri(s)
staying in heap using SLIDE) I suggested to make a change in
ExtendedKeystore to use the "Uri" instead of Object for the
removeObjectFromCache(Uri key ) method
Does anybody tried to compile with this new type of parameter (I
compiled without error) ?
Antoine Levy-Lambert suggested me that this modification doesn't
change any thing because the toString method call is the good one
in any case , ... that rigth ! but I think my code is better
because it limit the type Object at compiler time and throw an
Exception at run time if the key sent is not an Uri
Nevertheless I propose to make a change to the Uri Class these
change will appears as "cosmetic" but I propose it anyway
In Uri class the method equals refer to the toString() method this
is not correct from my point of vue I suggest :
/**
* Tests equivalence of two Uris.
*
* @param obj Object to test
* @return boolean
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Uri)) {
// return (uri.equals(obj.toString()));
return uri.equals(((Uri)obj).uri);
} else {
return false;
}
}
I would not agree with this. Your suggestion would make an infinite
loop. Maybe we want : return uri.toString().equals(obj.toString()) ?
I attach Uri class code as it is today in my project I comment the
Uri instance counter (used in constructor , clone and finalyse )
this simple code show the number of instances of Uri when SLIDE run
Futhermore I made some changes in the class UriPath (not so
"cosmetic")
/**
* Equals .
* @param o Object to
*/
public boolean equals(Object o) {
boolean result = false;
if ((o!= null) && (o instanceof UriPath)) {
result = java.util.Arrays.equals(this.tokens,((UriPath)
o).tokens); <-- my code
/* UriPath other = (UriPath)o;
if (other.tokens.length == this.tokens.length) {
result = true;
for (int i = 0; i < this.tokens.length; i++) {
if (!other.tokens[i].equals(this.tokens[i])) {
result = false;
break;
}
}
}*/
}
return result;
}
/**
* hashcode use all tokens to compute hashcode
*/
public int hashCode() {
if (tokens.length > 0) {
// return tokens[tokens.length - 1].hashCode();
return this.toString().hashCode();
}
else {
return 0;
}
}
Method equals : I change the token arrays comparison made in the
loop and I use the java.util.Arrays class (this is cosmetic)
Method hashCode : as written today this method is not in accordance
with equals method because only the length -1 token is used to
compute the hash
The javadoc for Object.equals() says that it is good, but not
required, that hashCode() return a different values for objects for
which equals() return false.
The preferred method for submitting code changes is to create a bug
report, and attach the output of svn diff for changed classes, and to
tar new files in a separate attachment.
Best regards,
Antoine
I suggest to use the toString().hashcode to use all tokens
Bests regards
B DOREL
<Uri.java>
<UriPath.java>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]