Author: markt Date: Tue Dec 4 21:21:11 2012 New Revision: 1417194 URL: http://svn.apache.org/viewvc?rev=1417194&view=rev Log: Replicate the equals() and hashCode() strategy from MessageBytes to silence some FindBugs warnings
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java?rev=1417194&r1=1417193&r2=1417194&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/ByteChunk.java Tue Dec 4 21:21:11 2012 @@ -101,6 +101,10 @@ public final class ByteChunk implements */ public static final Charset DEFAULT_CHARSET = B2CConverter.ISO_8859_1; + private int hashCode=0; + // did we compute the hashcode ? + private boolean hasHashCode = false; + // byte[] private byte[] buff; @@ -141,6 +145,7 @@ public final class ByteChunk implements start=0; end=0; isSet=false; + hasHashCode = false; } public void reset() { @@ -157,6 +162,7 @@ public final class ByteChunk implements start=0; end=0; isSet=true; + hasHashCode = false; } /** @@ -171,6 +177,7 @@ public final class ByteChunk implements start = off; end = start+ len; isSet=true; + hasHashCode = false; } public void setCharset(Charset charset) { @@ -488,6 +495,14 @@ public final class ByteChunk implements // -------------------- equals -------------------- + @Override + public boolean equals(Object obj) { + if (obj instanceof ByteChunk) { + return equals((ByteChunk) obj); + } + return false; + } + /** * Compares the message bytes to the specified String object. * @param s the String to compare @@ -626,6 +641,19 @@ public final class ByteChunk implements // -------------------- Hash code -------------------- + @Override + public int hashCode() { + if (hasHashCode) { + return hashCode; + } + int code = 0; + + code = hash(); + hashCode = code; + hasHashCode = true; + return code; + } + // normal hash. public int hash() { return hashBytes( buff, start, end-start); Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java?rev=1417194&r1=1417193&r2=1417194&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/CharChunk.java Tue Dec 4 21:21:11 2012 @@ -57,6 +57,11 @@ public final class CharChunk implements } // -------------------- + + private int hashCode = 0; + // did we compute the hashcode ? + private boolean hasHashCode = false; + // char[] private char buff[]; @@ -99,6 +104,7 @@ public final class CharChunk implements public void recycle() { // buff=null; isSet=false; // XXX + hasHashCode = false; start=0; end=0; } @@ -113,6 +119,7 @@ public final class CharChunk implements start=0; end=0; isSet=true; + hasHashCode = false; } @@ -125,6 +132,7 @@ public final class CharChunk implements start=off; end=start + len; isSet=true; + hasHashCode = false; } /** Maximum amount of data in this buffer. @@ -455,6 +463,14 @@ public final class CharChunk implements // -------------------- equals -------------------- + @Override + public boolean equals(Object obj) { + if (obj instanceof CharChunk) { + return equals((CharChunk) obj); + } + return false; + } + /** * Compares the message bytes to the specified String object. * @param s the String to compare @@ -578,6 +594,19 @@ public final class CharChunk implements // -------------------- Hash code -------------------- + @Override + public int hashCode() { + if (hasHashCode) { + return hashCode; + } + int code = 0; + + code = hash(); + hashCode = code; + hasHashCode = true; + return code; + } + // normal hash. public int hash() { int code=0; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org