org.javimmutable.collections
Interface JImmutableArray<T>

All Superinterfaces:
Cursorable<JImmutableMap.Entry<Integer,T>>, Indexed<T>, Insertable<JImmutableMap.Entry<Integer,T>>, Iterable<JImmutableMap.Entry<Integer,T>>
All Known Implementing Classes:
AbstractJImmutableArray, Bit32Array, EmptyBit32Array, FullBit32Array, SingleBit32Array, StandardBit32Array, TrieArray

@Immutable
public interface JImmutableArray<T>
extends Indexed<T>, Insertable<JImmutableMap.Entry<Integer,T>>, Iterable<JImmutableMap.Entry<Integer,T>>, Cursorable<JImmutableMap.Entry<Integer,T>>

Immutable sparse array implementation using integers as keys. Keys are traversed in signed integer order by Cursors so negative values are visited before positive values. Implementations are allowed to restrict the range of allowable indexes for performance or other reasons. Implementations should throw IndexOutOfBounds exceptions if presented with an invalid index.

Arrays are sparse meaning that they can contain elements at any valid index with no need to keep them consecutive (like a List). Memory is managed to use no more than necessary for the number of elements currently in the array.


Method Summary
 JImmutableArray<T> assign(int index, T value)
          Sets the value associated with a specific index.
 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.
 Holder<JImmutableMap.Entry<Integer,T>> findEntry(int index)
          Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself.
 T get(int index)
          Return the value associated with index or null if no value is associated.
 Map<Integer,T> getMap()
          Creates an unmodifiable java.util.Map reflecting the values of this PersistentMap.
 T getValueOr(int index, T defaultValue)
          Return the value associated with index or defaultValue if no value is associated.
 boolean isEmpty()
           
 Cursor<Integer> keysCursor()
          Creates a Cursor to access all of the Map's keys.
 int size()
          Return the number of entries in the map.
 Cursor<T> valuesCursor()
          Creates a Cursor to access all of the Map's values.
 
Methods inherited from interface org.javimmutable.collections.Insertable
insert
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface org.javimmutable.collections.Cursorable
cursor
 

Method Detail

get

@Nullable
T get(int index)
Return the value associated with index or null if no value is associated. Note that if null is an acceptable value to the container then this method will be ambiguous and find() should be used instead.

Specified by:
get in interface Indexed<T>
Parameters:
index - identifies the value to retrieve
Returns:
value associated with index or null if no value is associated

getValueOr

@Nullable
T getValueOr(int index,
                      @Nullable
                      T defaultValue)
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
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.

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

findEntry

@Nonnull
Holder<JImmutableMap.Entry<Integer,T>> findEntry(int index)
Search for an Entry within the map and return a Holder indicating if the Entry was found and, if it was found, the Entry itself.

Parameters:
index - index to search for
Returns:
empty Holder if not found, otherwise filled Holder with Entry

assign

@Nonnull
JImmutableArray<T> assign(int index,
                                  @Nullable
                                  T value)
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
JImmutableArray<T> delete(int index)
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

int size()
Return the number of entries in the map.

Specified by:
size in interface Indexed<T>
Returns:

isEmpty

boolean isEmpty()
Returns:
true only if list contains no values

deleteAll

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

getMap

@Nonnull
Map<Integer,T> getMap()
Creates an unmodifiable java.util.Map reflecting the values of this PersistentMap.

Returns:
Map view of this PersistentMap

keysCursor

@Nonnull
Cursor<Integer> keysCursor()
Creates a Cursor to access all of the Map's keys.

Returns:

valuesCursor

@Nonnull
Cursor<T> valuesCursor()
Creates a Cursor to access all of the Map's values.

Returns:


Copyright © 2014 Burton Computer Corporation. All rights reserved.