public Identifier(AbstractUtf8Array utf8) { this(utf8.getBytes()); } public Identifier(byte [] utf8) {
public LowercaseIdentifier(AbstractUtf8Array utf8) { this(utf8.getBytes()); } public LowercaseIdentifier(byte [] utf8) {
/** * This will return the byte at the given position. */ public byte getByte(int index) { return getBytes()[getByteOffset() + index]; }
/** * Wraps the utf8 sequence in a ByteBuffer * @return The wrapping buffer. */ public ByteBuffer wrap() { return ByteBuffer.wrap(getBytes(), getByteOffset(), getByteLength()); }
/** * This will write the utf8 sequence to the given target. */ final public void writeTo(ByteBuffer target) { target.put(getBytes(), getByteOffset(), getByteLength()); }
@Override public int hashCode() { final int l = getByteLength(); final int c = getByteOffset(); final byte [] b = getBytes(); int h = 0; for (int i=0; i < l; i++) { int v = b[c+i]; h ^= v << ((i%4)*8); } return h; } @Override
@Override public int compareTo(AbstractUtf8Array rhs) { final int l = getByteLength(); final int rl = rhs.getByteLength(); if (l < rl) { return -1; } else if (l > rl) { return 1; } else { final byte [] b = getBytes(); final byte [] rb = rhs.getBytes(); final int c = getByteOffset(); final int rc = rhs.getByteOffset(); for (int i=0; i < l; i++) { if (b[c+i] < rb[rc+i]) { return -1; } else if (b[c+i] > rb[rc+i]) { return 1; } } return 0; } }
/** * This will create a string based on the utf8 sequence. * @param utf8 The backing array */ public Utf8String(AbstractUtf8Array utf8) { super(utf8.getBytes(), utf8.getByteOffset(), utf8.getByteLength()); s = utf8.toString(); }
/** * Will convert the utf8 sequence to a Java string * @return The converted Java String */ @Override public String toString() { return Utf8.toString(getBytes(), getByteOffset(), getByteLength()); }