Author: vgritsenko Date: Thu Mar 15 18:15:25 2007 New Revision: 518821 URL: http://svn.apache.org/viewvc?view=rev&rev=518821 Log: rearrange methods / comment
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java?view=diff&rev=518821&r1=518820&r2=518821 ============================================================================== --- xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java (original) +++ xml/xindice/trunk/java/src/org/apache/xindice/core/data/Value.java Thu Mar 15 18:15:25 2007 @@ -73,6 +73,15 @@ } /** + * getLength retrieves the length of the data being stored by the Value. + * + * @return The Value length + */ + public final int getLength() { + return len; + } + + /** * getData retrieves the data being stored by the Value as a byte array. * * @return The Data @@ -88,21 +97,6 @@ } /** - * Returns the byte at the specified index. - * - * @param index byte index - * @return the byte at the specified index. - * @throws ArrayIndexOutOfBoundsException if index is negative number or - * is not less that the length of Value data - */ - public final byte byteAt(int index) { - if (index < 0 || index >= len) { - throw new ArrayIndexOutOfBoundsException(index); - } - return data[pos + index]; - } - - /** * Get a new Value that is part of this Value object. * * @param start beginning index @@ -116,16 +110,39 @@ } /** - * getLength retrieves the length of the data being stored by the Value. + * Returns the byte at the specified index. * - * @return The Value length + * @param index byte index + * @return the byte at the specified index. + * @throws ArrayIndexOutOfBoundsException if index is negative number or + * is not less that the length of Value data */ - public final int getLength() { - return len; + public final byte byteAt(int index) { + if (index < 0 || index >= len) { + throw new ArrayIndexOutOfBoundsException(index); + } + return data[pos + index]; + } + + public final boolean startsWith(Value value) { + if (len < value.len) { + return false; + } + + byte[] ddata = value.data; + int dpos = value.pos; + + for (int i = 0; i < value.len; i++) { + if (data[i + pos] != ddata[i + dpos]) { + return false; + } + } + + return true; } /** - * getInputStream returns an InputStream for the Value. + * Return an InputStream for the value. * * @return An InputStream */ @@ -134,7 +151,7 @@ } /** - * streamTo streams the content of the Value to an OutputStream. + * Stream the content of the value into an OutputStream. * * @param out the OutputStream */ @@ -142,41 +159,28 @@ out.write(data, pos, len); } + /** + * Copy contents of the value into supplied byte array. + * + * @param tdata byte array for the value + * @param tpos starting position + */ public final void copyTo(byte[] tdata, int tpos) { System.arraycopy(data, pos, tdata, tpos, len); } + /** + * Copy <code>len</code> bytes of value's content into supplied + * byte array. + * + * @param tdata byte array for the value + * @param tpos starting position + * @param len count of bytes to copy + */ public final void copyTo(byte[] tdata, int tpos, int len) { System.arraycopy(data, pos, tdata, tpos, len); } - public final String toString() { - try { - return new String(data, pos, len, "utf-8"); - } catch (UnsupportedEncodingException e) { - throw new XindiceRuntimeException("Java doesn't seem to support UTF-8!", e); - } - } - - public int hashCode() { - return toString().hashCode(); - } - - public boolean equals(Value value) { - return len == value.len && compareTo(value) == 0; - } - - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof Value) { - return equals((Value) obj); - } else { - return equals(new Value(obj.toString())); - } - } - public final int compareTo(Value value) { byte[] ddata = value.data; int dpos = value.pos; @@ -206,25 +210,34 @@ public final int compareTo(Object obj) { if (obj instanceof Value) { return compareTo((Value) obj); - } else { - return compareTo(new Value(obj.toString())); } + return compareTo(new Value(obj.toString())); } - public final boolean startsWith(Value value) { - if (len < value.len) { - return false; + public boolean equals(Value value) { + return len == value.len && compareTo(value) == 0; + } + + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof Value) { + return equals((Value) obj); } + return equals(new Value(obj.toString())); + } - byte[] ddata = value.data; - int dpos = value.pos; + public int hashCode() { + // TODO Ain't best way to go about it, but can't change on a whim either + return toString().hashCode(); + } - for (int i = 0; i < value.len; i++) { - if (data[i + pos] != ddata[i + dpos]) { - return false; - } + public final String toString() { + try { + return new String(data, pos, len, "utf-8"); + } catch (UnsupportedEncodingException e) { + throw new XindiceRuntimeException("Java doesn't seem to support UTF-8!", e); } - - return true; } }