org.joe_e.array
Class ImmutableArray<E>

java.lang.Object
  extended by org.joe_e.array.ConstArray<E>
      extended by org.joe_e.array.ImmutableArray<E>
Type Parameters:
E - the element type of objects contained in the array
All Implemented Interfaces:
Serializable, Iterable<E>, Immutable, Selfless
Direct Known Subclasses:
PowerlessArray

public class ImmutableArray<E>
extends ConstArray<E>
implements Immutable

An immutable array containing immutable objects.

See Also:
Serialized Form

Nested Class Summary
static class ImmutableArray.Builder<E>
          An ImmutableArray factory.
 
Method Summary
static
<T> ImmutableArray<T>
array()
          Construct an empty ConstArray.
static
<T> ImmutableArray<T>
array(T... values)
          Construct a ImmutableArray.
static
<T> ImmutableArray<T>
array(T value)
          Construct a ConstArray with one element.
static
<T> ImmutableArray<T>
array(T value1, T value2)
          Construct a ConstArray with two elements.
static
<T> ImmutableArray<T>
array(T value1, T value2, T value3)
          Construct an ImmutableArray with three elements.
static
<T> ImmutableArray<T>
array(T value1, T value2, T value3, T value4)
          Construct an ImmutableArray with four elements.
static
<E> ImmutableArray.Builder<E>
builder()
          Get an ImmutableArray.Builder.
static
<E> ImmutableArray.Builder<E>
builder(int estimate)
          Get an ImmutableArray.Builder.
 ImmutableArray<E> with(E newE)
          Return a new PowerlessArray that contains the same elements as this one but with a new element added to the end.
 ImmutableArray<E> without(int i)
          Return a new ImmutableArray that contains the same elements as this one excluding the element at a specified index
 
Methods inherited from class org.joe_e.array.ConstArray
equals, get, hashCode, iterator, length, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

array

public static <T> ImmutableArray<T> array(T... values)
Construct a ImmutableArray.

Parameters:
values - each value
Throws:
ClassCastException - if the runtime component type of values is not immutable in the overlay type system

array

public static <T> ImmutableArray<T> array()
Construct an empty ConstArray.


array

public static <T> ImmutableArray<T> array(T value)
Construct a ConstArray with one element.

Parameters:
value - the value

array

public static <T> ImmutableArray<T> array(T value1,
                                          T value2)
Construct a ConstArray with two elements.

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

array

public static <T> ImmutableArray<T> array(T value1,
                                          T value2,
                                          T value3)
Construct an ImmutableArray with three elements.

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

array

public static <T> ImmutableArray<T> array(T value1,
                                          T value2,
                                          T value3,
                                          T value4)
Construct an ImmutableArray with four elements.

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

with

public ImmutableArray<E> with(E newE)
Return a new PowerlessArray that contains the same elements as this one but with a new element added to the end.

Overrides:
with in class ConstArray<E>
Parameters:
newE - an element to add
Returns:
the new array
Throws:
ClassCastException - if newE is not immutable

without

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

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

builder

public static <E> ImmutableArray.Builder<E> builder()
Get an ImmutableArray.Builder. This is equivalent to the constructor.

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

builder

public static <E> ImmutableArray.Builder<E> builder(int estimate)
Get an ImmutableArray.Builder. This is equivalent to the constructor.

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