org.javimmutable.collections.array.trie32
Class TrieArray<T>

java.lang.Object
  extended by org.javimmutable.collections.common.AbstractJImmutableArray<T>
      extended by org.javimmutable.collections.array.trie32.TrieArray<T>
All Implemented Interfaces:
Iterable<JImmutableMap.Entry<Integer,T>>, Cursorable<JImmutableMap.Entry<Integer,T>>, Indexed<T>, Insertable<JImmutableMap.Entry<Integer,T>>, JImmutableArray<T>

@Immutable
public class TrieArray<T>
extends AbstractJImmutableArray<T>


Nested Class Summary
static class TrieArray.Builder<T>
           
 
Method Summary
 JImmutableArray<T> assign(int index, T value)
          Sets the value associated with a specific index.
static
<T> TrieArray.Builder<T>
builder()
           
 Cursor<JImmutableMap.Entry<Integer,T>> cursor()
           
 JImmutableArray<T> delete(int index)
          Deletes the entry for the specified index (if any).
 JImmutableArray<T> deleteAll()
           
 Holder<T> find(int index)
          Return a Holder containing the value associated wth the index or an empty Holder if no value is associated with the index.
 T getValueOr(int index, T defaultValue)
          Return the value associated with index or defaultValue if no value is associated.
static
<T> TrieArray<T>
of()
           
static
<T> JImmutableArray<T>
of(Indexed<? extends T> source, int offset, int limit)
          Deprecated. use builder() instead
 int size()
          Return the number of entries in the map.
 
Methods inherited from class org.javimmutable.collections.common.AbstractJImmutableArray
findEntry, get, getMap, insert, isEmpty, iterator, keysCursor, valuesCursor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

builder

public static <T> TrieArray.Builder<T> builder()

of

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

of

@Deprecated
public static <T> JImmutableArray<T> of(Indexed<? extends T> source,
                                                   int offset,
                                                   int limit)
Deprecated. use builder() instead

Efficiently constructs a TrieArray containing the objects from source (in the specified range). In the constructed TrieArray objects will have array indexes starting at 0 (i.e. indexes from the source are not carried over) so if offset is 10 then source.get(10) will map to array.get(0).

Type Parameters:
T -
Parameters:
source -
offset -
limit -
Returns:

getValueOr

@Nullable
public T getValueOr(int index,
                             @Nullable
                             T defaultValue)
Description copied from interface: JImmutableArray
Return the value associated with index or defaultValue if no value is associated. Note that if defaultValue is an acceptable value to the container then this method will be ambiguous and find() should be used instead.

Parameters:
index - identifies the value to retrieve
defaultValue - value to return if no entry exists for index
Returns:
value associated with index or defaultValue if no value is associated

find

@Nonnull
public Holder<T> find(int index)
Description copied from interface: JImmutableArray
Return a Holder containing the value associated wth the index or an empty Holder if no value is associated with the index.

Parameters:
index - identifies the value to retrieve
Returns:
possibly empty Holder containing any value associated with the index

assign

@Nonnull
public JImmutableArray<T> assign(int index,
                                         @Nullable
                                         T value)
Description copied from interface: JImmutableArray
Sets the value associated with a specific index. Index must be non-null but value can be null. If the index already has a value in the map the old value is discarded and the new value is stored in its place. Returns a new PersistentMap reflecting any changes. The original map is always left unchanged.

Parameters:
index - index
value - possibly null value
Returns:
new map reflecting the change

delete

@Nonnull
public JImmutableArray<T> delete(int index)
Description copied from interface: JImmutableArray
Deletes the entry for the specified index (if any). Returns a new map if the value was deleted or the current map if the index was not contained in the map.

Parameters:
index - index
Returns:
same or different map depending on whether index was removed

size

public int size()
Description copied from interface: JImmutableArray
Return the number of entries in the map.

Returns:

deleteAll

@Nonnull
public JImmutableArray<T> deleteAll()
Returns:
an equivalent collection with no values

cursor

@Nonnull
public Cursor<JImmutableMap.Entry<Integer,T>> cursor()


Copyright © 2014 Burton Computer Corporation. All rights reserved.