org.javimmutable.collections.list
Class JImmutableArrayList<T>

java.lang.Object
  extended by org.javimmutable.collections.list.JImmutableArrayList<T>
Type Parameters:
T -
All Implemented Interfaces:
Iterable<T>, Cursorable<T>, Indexed<T>, Insertable<T>, JImmutableList<T>

public class JImmutableArrayList<T>
extends Object
implements JImmutableList<T>

JImmutableList implementation using 32-way trees. The underlying trees, like the JImmutableList, only allow values to be inserted or deleted from the head or tail of the list.


Nested Class Summary
static class JImmutableArrayList.Builder<T>
           
 
Method Summary
 JImmutableArrayList<T> assign(int index, T value)
          Replaces the value at the specified index (which must be within current bounds of the list) with the new value.
static
<T> JImmutableArrayList.Builder<T>
builder()
           
 void checkInvariants()
           
 Cursor<T> cursor()
           
 JImmutableArrayList<T> deleteAll()
           
 JImmutableArrayList<T> deleteFirst()
          Removes the first value from the list and reduces size by 1.
 JImmutableArrayList<T> deleteLast()
          Removes the last value from the list and reduces size by 1.
 boolean equals(Object o)
           
 T get(int index)
          Retrieves the value at the specified index (which must be within the bounds of the list).
 List<T> getList()
          Returns an unmodifiable List implementation backed by this list.
 int hashCode()
           
 JImmutableArrayList<T> insert(Iterable<? extends T> values)
          Adds the values to the end of the list in the same order they appear in the Iterable.
 JImmutableArrayList<T> insert(T value)
          Adds a value to the end of the list.
 JImmutableArrayList<T> insertFirst(T value)
          Adds a value to the front of the list.
 JImmutableArrayList<T> insertLast(T value)
          Adds a value to the end of the list.
 boolean isEmpty()
           
 Iterator<T> iterator()
           
static
<T> JImmutableArrayList<T>
of()
           
static
<T> JImmutableArrayList<T>
of(Indexed<? extends T> source, int offset, int limit)
           
static
<T> JImmutableArrayList<T>
of(Indexed<T> source)
           
 int size()
          Retrieve the number of values available in the container.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

of

@Nonnull
public static <T> JImmutableArrayList<T> of()

of

@Nonnull
public static <T> JImmutableArrayList<T> of(Indexed<? extends T> source,
                                                    int offset,
                                                    int limit)

of

@Nonnull
public static <T> JImmutableArrayList<T> of(Indexed<T> source)

builder

@Nonnull
public static <T> JImmutableArrayList.Builder<T> builder()

size

public int size()
Description copied from interface: Indexed
Retrieve the number of values available in the container.

Specified by:
size in interface Indexed<T>
Specified by:
size in interface JImmutableList<T>
Returns:
number of values in the list

get

public T get(int index)
Description copied from interface: JImmutableList
Retrieves the value at the specified index (which must be within the bounds of the list).

Specified by:
get in interface Indexed<T>
Specified by:
get in interface JImmutableList<T>
Returns:

assign

@Nonnull
public JImmutableArrayList<T> assign(int index,
                                             @Nullable
                                             T value)
Description copied from interface: JImmutableList
Replaces the value at the specified index (which must be within current bounds of the list) with the new value.

Specified by:
assign in interface JImmutableList<T>
Returns:

insert

@Nonnull
public JImmutableArrayList<T> insert(@Nullable
                                             T value)
Description copied from interface: JImmutableList
Adds a value to the end of the list. May be invoked on an empty list.

Specified by:
insert in interface Insertable<T>
Specified by:
insert in interface JImmutableList<T>
Returns:

insert

@Nonnull
public JImmutableArrayList<T> insert(@Nonnull
                                             Iterable<? extends T> values)
Description copied from interface: JImmutableList
Adds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list.

Specified by:
insert in interface JImmutableList<T>
Returns:

insertFirst

@Nonnull
public JImmutableArrayList<T> insertFirst(@Nullable
                                                  T value)
Description copied from interface: JImmutableList
Adds a value to the front of the list. May be invoked on an empty list. Synonym for insert()

Specified by:
insertFirst in interface JImmutableList<T>
Returns:

insertLast

@Nonnull
public JImmutableArrayList<T> insertLast(@Nullable
                                                 T value)
Description copied from interface: JImmutableList
Adds a value to the end of the list. May be invoked on an empty list. Synonym for insert().

Specified by:
insertLast in interface JImmutableList<T>
Returns:

deleteFirst

@Nonnull
public JImmutableArrayList<T> deleteFirst()
Description copied from interface: JImmutableList
Removes the first value from the list and reduces size by 1. size() must be greater than zero

Specified by:
deleteFirst in interface JImmutableList<T>
Returns:
new PersistentList without last value

deleteLast

@Nonnull
public JImmutableArrayList<T> deleteLast()
Description copied from interface: JImmutableList
Removes the last value from the list and reduces size by 1. size() must be greater than zero

Specified by:
deleteLast in interface JImmutableList<T>
Returns:
new PersistentList without last value

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface JImmutableList<T>
Returns:
true only if list contains no values

deleteAll

@Nonnull
public JImmutableArrayList<T> deleteAll()
Specified by:
deleteAll in interface JImmutableList<T>
Returns:
an equivalent collection with no values

getList

@Nonnull
public List<T> getList()
Description copied from interface: JImmutableList
Returns an unmodifiable List implementation backed by this list.

Specified by:
getList in interface JImmutableList<T>
Returns:

cursor

@Nonnull
public Cursor<T> cursor()
Specified by:
cursor in interface Cursorable<T>

iterator

public Iterator<T> iterator()
Specified by:
iterator in interface Iterable<T>

checkInvariants

public void checkInvariants()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014 Burton Computer Corporation. All rights reserved.