|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.iapi.util
Class ByteArray

java.lang.Objectorg.apache.derby.iapi.util.ByteArray
- public final class ByteArray
- extends java.lang.Object
ByteArray wraps java byte arrays (byte[]) to allow byte arrays to be used as keys in hashtables. This is required because the equals function on byte[] directly uses reference equality.
This class also allows the trio of array, offset and length to be carried around as a single object.
| Field Summary | |
private byte[] |
array
|
private int |
length
|
private int |
offset
|
| Constructor Summary | |
ByteArray()
|
|
ByteArray(byte[] array)
|
|
ByteArray(byte[] array,
int offset,
int length)
Create an instance of this class that wraps ths given array. |
|
| Method Summary | |
private static boolean |
equals(byte[] a,
int aOffset,
int aLength,
byte[] b,
int bOffset,
int bLength)
Compare two byte arrays using value equality. |
boolean |
equals(java.lang.Object other)
Value equality for byte arrays. |
byte[] |
getArray()
|
int |
getLength()
|
int |
getOffset()
|
int |
hashCode()
Get a value that represents this Object, as uniquely as possible within the confines of an int. |
void |
readExternal(java.io.ObjectInput in)
Read this object from a stream of stored objects. |
void |
setBytes(byte[] array)
|
void |
setBytes(byte[] array,
int length)
|
void |
setBytes(byte[] array,
int offset,
int length)
|
void |
setLength(int newLength)
|
void |
writeExternal(java.io.ObjectOutput out)
Write the byte array out w/o compression |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
array
private byte[] array
offset
private int offset
length
private int length
| Constructor Detail |
ByteArray
public ByteArray(byte[] array,
int offset,
int length)
- Create an instance of this class that wraps ths given array.
This class does not make a copy of the array, it just saves
the reference.
ByteArray
public ByteArray(byte[] array)
ByteArray
public ByteArray()
| Method Detail |
setBytes
public void setBytes(byte[] array)
setBytes
public void setBytes(byte[] array,
int length)
setBytes
public void setBytes(byte[] array,
int offset,
int length)
equals
public boolean equals(java.lang.Object other)
- Value equality for byte arrays.
hashCode
public int hashCode()
- Description copied from class:
java.lang.Object - Get a value that represents this Object, as uniquely as
possible within the confines of an int.
There are some requirements on this method which subclasses must follow:
- Semantic equality implies identical hashcodes. In other
words, if
a.equals(b)is true, thena.hashCode() == b.hashCode()must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal. - It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.
Notice that since
hashCodeis used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.The default implementation returns
System.identityHashCode(this) - Semantic equality implies identical hashcodes. In other
words, if
getArray
public final byte[] getArray()
getOffset
public final int getOffset()
getLength
public final int getLength()
setLength
public final void setLength(int newLength)
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException
- Read this object from a stream of stored objects.
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Write the byte array out w/o compression
equals
private static boolean equals(byte[] a,
int aOffset,
int aLength,
byte[] b,
int bOffset,
int bLength)
- Compare two byte arrays using value equality.
Two byte arrays are equal if their length is
identical and their contents are identical.
|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.derby.iapi.util.ByteArray