org.joe_e.array
Class ByteArray

java.lang.Object
  extended by org.joe_e.array.ConstArray<E>
      extended by org.joe_e.array.ImmutableArray<E>
          extended by org.joe_e.array.PowerlessArray<Byte>
              extended by org.joe_e.array.ByteArray
All Implemented Interfaces:
Serializable, Iterable<Byte>, Immutable, Powerless, Selfless

public final class ByteArray
extends PowerlessArray<Byte>

An immutable array of byte.

See Also:
Serialized Form

Nested Class Summary
static class ByteArray.Builder
          A ByteArray factory.
static class ByteArray.BuilderOutputStream
          A ByteArray factory that extends OutputStream.
 
Method Summary
static ByteArray array()
          Construct an empty ByteArray
static ByteArray array(byte... bytes)
          Construct a ByteArray.
static ByteArray array(byte value)
          Construct a ByteArray with one element.
static ByteArray array(byte value1, byte value2)
          Construct a ByteArray with two elements.
static ByteArray array(byte value1, byte value2, byte value3)
          Construct a ByteArray with three elements.
static ByteArray array(byte value1, byte value2, byte value3, byte value4)
          Construct a ByteArray with four elements.
 InputStream asInputStream()
          Views this array as an input stream.
static ByteArray.Builder builder()
          Get a ByteArray.Builder.
static ByteArray.Builder builder(int estimate)
          Get a ByteArray.Builder.
 boolean equals(Object other)
          Test for equality with another object
 Byte get(int i)
          Creates a Byte for a specified byte.
 byte getByte(int i)
          Gets the byte at a specified position.
 int hashCode()
          Computes a digest of the array for hashing.
 int length()
          Gets the length of the array.
<T> T[]
toArray(T[] prototype)
          Return a mutable copy of the array
 byte[] toByteArray()
          Creates a mutable copy of the byte array
 String toString()
          Return a string representation of the array
 ByteArray with(byte newByte)
          Creates a ByteArray with an appended byte.
 ByteArray with(Byte newByte)
          Creates a ByteArray with an appended Byte.
 ByteArray without(int i)
          Return a new ByteArray that contains the same elements as this one excluding the element at a specified index
 
Methods inherited from class org.joe_e.array.PowerlessArray
array
 
Methods inherited from class org.joe_e.array.ConstArray
iterator
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

array

public static ByteArray array(byte... bytes)
Construct a ByteArray.

Parameters:
bytes - each byte

array

public static ByteArray array()
Construct an empty ByteArray


array

public static ByteArray array(byte value)
Construct a ByteArray with one element.

Parameters:
value - the value

array

public static ByteArray array(byte value1,
                              byte value2)
Construct a ByteArray with two elements.

Parameters:
value1 - the first value
value2 - the second value

array

public static ByteArray array(byte value1,
                              byte value2,
                              byte value3)
Construct a ByteArray with three elements.

Parameters:
value1 - the first value
value2 - the second value
value3 - the third value

array

public static ByteArray array(byte value1,
                              byte value2,
                              byte value3,
                              byte value4)
Construct a ByteArray with four elements.

Parameters:
value1 - the first value
value2 - the second value
value3 - the third value
value4 - the fourth value

equals

public boolean equals(Object other)
Test for equality with another object

Overrides:
equals in class ConstArray<Byte>
Parameters:
other - the reference object with which to compare.
Returns:
true if the other object is a ConstArray with the same contents as this array
See Also:
Object.hashCode(), HashMap

hashCode

public int hashCode()
Computes a digest of the array for hashing. The hash code is the same as Arrays.hashCode(Object[]) called on a Java array containing the same elements.

Specified by:
hashCode in interface Selfless
Overrides:
hashCode in class ConstArray<Byte>
Returns:
a hash code based on the contents of this array
See Also:
Object.equals(java.lang.Object), System.identityHashCode(java.lang.Object)

toString

public String toString()
Return a string representation of the array

Overrides:
toString in class ConstArray<Byte>
Returns:
a string representation of this array

length

public int length()
Gets the length of the array.

Overrides:
length in class ConstArray<Byte>

get

public Byte get(int i)
Creates a Byte for a specified byte.

Overrides:
get in class ConstArray<Byte>
Parameters:
i - position of the byte to return
Throws:
ArrayIndexOutOfBoundsException - i is out of bounds

toArray

public <T> T[] toArray(T[] prototype)
Return a mutable copy of the array

Overrides:
toArray in class ConstArray<Byte>
Parameters:
prototype - prototype of the array to copy into
Returns:
an array containing the contents of this ConstArray of the same type as prototype
Throws:
ArrayStoreException - if an element cannot be stored in the array

with

public ByteArray with(Byte newByte)
Creates a ByteArray with an appended Byte.

Overrides:
with in class PowerlessArray<Byte>
Parameters:
newByte - the element to append
Returns:
the new array
Throws:
NullPointerException - newByte is null

getByte

public byte getByte(int i)
Gets the byte at a specified position.

Parameters:
i - position of the byte to return
Throws:
ArrayIndexOutOfBoundsException - i is out of bounds

toByteArray

public byte[] toByteArray()
Creates a mutable copy of the byte array


with

public ByteArray with(byte newByte)
Creates a ByteArray with an appended byte.

Parameters:
newByte - the byte to append

asInputStream

public InputStream asInputStream()
Views this array as an input stream.


without

public ByteArray without(int i)
Return a new ByteArray that contains the same elements as this one excluding the element at a specified index

Overrides:
without in class PowerlessArray<Byte>
Parameters:
i - the index of the element to exclude
Returns:
the new array

builder

public static ByteArray.Builder builder()
Get a ByteArray.Builder. This is equivalent to the constructor.

Returns:
a new builder instance, with the default internal array length

builder

public static ByteArray.Builder builder(int estimate)
Get a ByteArray.Builder. This is equivalent to the constructor.

Parameters:
estimate - estimated array length
Returns:
a new builder instance