org.joe_e.array
Class IntArray

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<Integer>
              extended by org.joe_e.array.IntArray
All Implemented Interfaces:
Serializable, Iterable<Integer>, Immutable, Powerless, Selfless

public final class IntArray
extends PowerlessArray<Integer>

An immutable array of int.

See Also:
Serialized Form

Nested Class Summary
static class IntArray.Builder
          A IntArray factory.
 
Method Summary
static IntArray array()
          Construct an empty IntArray
static IntArray array(int... ints)
          Constructs an array of ints.
static IntArray array(int value)
          Construct a IntArray with one element.
static IntArray array(int value1, int value2)
          Construct a IntArray with two elements.
static IntArray array(int value1, int value2, int value3)
          Construct a IntArray with three elements.
static IntArray array(int value1, int value2, int value3, int value4)
          Construct a IntArray with four elements.
static IntArray.Builder builder()
          Get a IntArray.Builder.
static IntArray.Builder builder(int estimate)
          Get a IntArray.Builder.
 boolean equals(Object other)
          Test for equality with another object
 Integer get(int i)
          Creates a Integer for a specified int.
 int getInt(int i)
          Gets the int 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
 int[] toIntArray()
          Creates a mutable copy of the int array
 String toString()
          Return a string representation of the array
 IntArray with(int newInt)
          Creates a IntArray with an appended int.
 IntArray with(Integer newInt)
          Creates a IntArray with an appended Integer.
 IntArray without(int i)
          Return a new IntArray 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 IntArray array(int... ints)
Constructs an array of ints.

Parameters:
ints - each element

array

public static IntArray array()
Construct an empty IntArray


array

public static IntArray array(int value)
Construct a IntArray with one element.

Parameters:
value - the value

array

public static IntArray array(int value1,
                             int value2)
Construct a IntArray with two elements.

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

array

public static IntArray array(int value1,
                             int value2,
                             int value3)
Construct a IntArray with three elements.

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

array

public static IntArray array(int value1,
                             int value2,
                             int value3,
                             int value4)
Construct a IntArray 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<Integer>
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<Integer>
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<Integer>
Returns:
a string representation of this array

length

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

Overrides:
length in class ConstArray<Integer>

get

public Integer get(int i)
Creates a Integer for a specified int.

Overrides:
get in class ConstArray<Integer>
Parameters:
i - position of the element 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<Integer>
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 IntArray with(Integer newInt)
Creates a IntArray with an appended Integer.

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

getInt

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

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

toIntArray

public int[] toIntArray()
Creates a mutable copy of the int array


with

public IntArray with(int newInt)
Creates a IntArray with an appended int.

Parameters:
newInt - the element to append

without

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

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

builder

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

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

builder

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

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