001    package com.thaiopensource.datatype.xsd;
002    
003    abstract class BinaryDatatype extends DatatypeBase implements Measure {
004      BinaryDatatype() {
005        // whiteSpace is actually collapse, but we handle it ourselves for efficiency
006        super(WHITE_SPACE_PRESERVE);
007      }
008    
009      public int valueHashCode(Object value) {
010        byte[] v = (byte[])value;
011        int hc = 0;
012        for (int i = 0, len = v.length; i < len; i++)
013          hc = (hc * 33) ^ (v[i] & 0xFF);
014        return hc;
015      }
016    
017      public boolean sameValue(Object value1, Object value2) {
018        byte[] v1 = (byte[])value1;
019        byte[] v2 = (byte[])value2;
020        if (v1.length != v2.length)
021          return false;
022        for (int i = 0, len = v1.length; i < len; i++)
023          if (v1[i] != v2[i])
024            return false;
025        return true;
026      }
027    
028      public int getLength(Object obj) {
029        return ((byte[])obj).length;
030      }
031    
032      Measure getMeasure() {
033        return this;
034      }
035    }