You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2007/10/18 04:20:00 UTC
svn commit: r585789 -
/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java
Author: doogie
Date: Wed Oct 17 19:19:59 2007
New Revision: 585789
URL: http://svn.apache.org/viewvc?rev=585789&view=rev
Log:
ByteWrapper now implements Comparable, hashCode, and equals().
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java?rev=585789&r1=585788&r2=585789&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/ByteWrapper.java Wed Oct 17 19:19:59 2007
@@ -23,7 +23,7 @@
/**
* A very simple class to wrap a byte array for persistence.
*/
-public class ByteWrapper implements Serializable {
+public class ByteWrapper implements Comparable, Serializable {
protected byte[] bytes;
protected ByteWrapper() {}
@@ -42,5 +42,30 @@
public int getLength() {
return bytes.length;
+ }
+
+ public int compareTo(Object obj) {
+ ByteWrapper other = (ByteWrapper) obj;
+ int r = bytes.length - other.bytes.length;
+ if (r != 0) return r;
+ int i = 0;
+ for (i = 0; i < bytes.length; i++) {
+ r = bytes[i] - other.bytes[i];
+ if (r != 0) return r;
+ }
+ return 0;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof ByteWrapper) return compareTo((ByteWrapper) obj) == 0;
+ return false;
+ }
+
+ public int hashCode() {
+ int hashCode = 0;
+ for (byte b: bytes) {
+ hashCode ^= b;
+ }
+ return hashCode;
}
}