ref_send API 2.17
defensive programming in Java

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:
java.io.Serializable, java.lang.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.
 boolean equals(java.lang.Object x)
          Test for equality with another object.
 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
get, hashCode, iterator, length, toArray, toString
 
Methods inherited from class java.lang.Object
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:
java.lang.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

equals

public boolean equals(java.lang.Object x)
Description copied from class: ConstArray
Test for equality with another object.

Overrides:
equals in class ConstArray<E>
Returns:
true if the other object is a ConstArray with the same contents as this array (determined by calling equals() on array elements)

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:
java.lang.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

ref_send API 2.17
defensive programming in Java

Submit a bug or feature, or get help

Copyright 1998-2009 Waterken Inc. under the terms of the MIT X license.