1 30 31 32 package org.hsqldb.types; 33 34 import org.hsqldb.lib.ArrayUtil; 35 import org.hsqldb.lib.StringConverter; 36 37 47 public class Binary { 48 49 private byte[] data; 50 int hash; 51 52 60 public Binary(byte[] data, boolean clone) { 61 62 if (clone) { 63 data = (byte[]) ArrayUtil.duplicateArray(data); 64 } 65 66 this.data = data; 67 } 68 69 public byte[] getBytes() { 70 return data; 71 } 72 73 public byte[] getClonedBytes() { 74 return (byte[]) data.clone(); 75 } 76 77 public int getBytesLength() { 78 return data.length; 79 } 80 81 public boolean equals(Object other) { 82 83 if (other == this) { 84 return true; 85 } 86 87 if (!(other instanceof Binary)) { 88 return false; 89 } 90 91 if (data.length != ((Binary) other).data.length) { 92 return false; 93 } 94 95 return ArrayUtil.containsAt(data, 0, ((Binary) other).data); 96 } 97 98 public int hashCode() { 99 100 int h = 0; 101 102 if (hash == 0) { 103 for (int i = 0; i < data.length; i++) { 104 h = 31 * h + data[i]; 105 } 106 107 hash = h; 108 } 109 110 return hash; 111 } 112 113 public String toString() { 114 return StringConverter.byteToHex(data); 115 } 116 } 117 | Popular Tags |