org.javimmutable.collections.tree_list
Class JImmutableTreeList<T>

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

@Immutable
public class JImmutableTreeList<T>
extends Object
implements JImmutableRandomAccessList<T>

Implementation of PersistentRandomAccessList that uses a 2-3 tree for its implementation. Values are stored and traversed in the same order as they are added using add(). Performance is slower than PersistentLinkedList so if forward order and/or random access are not required using that class may be a better option. All operations should be O(logN).


Nested Class Summary
static class JImmutableTreeList.Builder<T>
           
 
Method Summary
 JImmutableTreeList<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> JImmutableTreeList.Builder<T>
builder()
          Creates a MutableBuilder instance for efficiently constructing JImmutableTreeLists.
 Cursor<T> cursor()
           
 JImmutableTreeList<T> delete(int index)
          Delete value at index (which must be within the current bounds of the list).
 JImmutableRandomAccessList<T> deleteAll()
           
 JImmutableTreeList<T> deleteFirst()
          Removes the first value from the list and reduces size by 1.
 JImmutableTreeList<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()
           
 JImmutableTreeList<T> insert(int index, T value)
          Insert value at index (which must be within 0 to size).
 JImmutableTreeList<T> insert(Iterable<? extends T> values)
          Adds the values to the end of the list in the same order they appear in the Iterable.
 JImmutableTreeList<T> insert(T value)
          Adds a value to the end of the list.
 JImmutableTreeList<T> insertFirst(T value)
          Adds a value to the front of the list.
 JImmutableTreeList<T> insertLast(T value)
          Adds a value to the end of the list.
 boolean isEmpty()
           
 Iterator<T> iterator()
           
static
<T> JImmutableTreeList<T>
of()
           
 int size()
          Retrieve the number of values available in the container.
 String toString()
           
 void verifyDepthsMatch()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

of

public static <T> JImmutableTreeList<T> of()

builder

public static <T> JImmutableTreeList.Builder<T> builder()
Creates a MutableBuilder instance for efficiently constructing JImmutableTreeLists.

Type Parameters:
T -
Returns:

insert

@Nonnull
public JImmutableTreeList<T> insert(int index,
                                            @Nullable
                                            T value)
Description copied from interface: JImmutableRandomAccessList
Insert value at index (which must be within 0 to size). Shifts all values at and after index one position to the right and adds 1 to size of the list.

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

insert

@Nonnull
public JImmutableTreeList<T> insert(@Nullable
                                            T value)
Description copied from interface: JImmutableRandomAccessList
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>
Specified by:
insert in interface JImmutableRandomAccessList<T>
Returns:

insert

@Nonnull
public JImmutableTreeList<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 JImmutableTreeList<T> insertFirst(@Nullable
                                                 T value)
Description copied from interface: JImmutableRandomAccessList
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>
Specified by:
insertFirst in interface JImmutableRandomAccessList<T>
Returns:

insertLast

@Nonnull
public JImmutableTreeList<T> insertLast(@Nullable
                                                T value)
Description copied from interface: JImmutableRandomAccessList
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>
Specified by:
insertLast in interface JImmutableRandomAccessList<T>
Returns:

deleteFirst

@Nonnull
public JImmutableTreeList<T> deleteFirst()
Description copied from interface: JImmutableRandomAccessList
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>
Specified by:
deleteFirst in interface JImmutableRandomAccessList<T>
Returns:
new PersistentList without last value

deleteLast

@Nonnull
public JImmutableTreeList<T> deleteLast()
Description copied from interface: JImmutableRandomAccessList
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>
Specified by:
deleteLast in interface JImmutableRandomAccessList<T>
Returns:
new PersistentList without last value

delete

@Nonnull
public JImmutableTreeList<T> delete(int index)
Description copied from interface: JImmutableRandomAccessList
Delete value at index (which must be within the current bounds of the list). Shifts all values at and after index one position to the left and subtracts 1 from size of the list.

Specified by:
delete in interface JImmutableRandomAccessList<T>
Returns:

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 JImmutableTreeList<T> assign(int index,
                                            @Nullable
                                            T value)
Description copied from interface: JImmutableRandomAccessList
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>
Specified by:
assign in interface JImmutableRandomAccessList<T>
Returns:

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:

isEmpty

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

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

deleteAll

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

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

iterator

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

cursor

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

verifyDepthsMatch

public void verifyDepthsMatch()


Copyright © 2014 Burton Computer Corporation. All rights reserved.