Class ListIndexProxy<E>
- Type Parameters:
E
- the type of elements in this list
- All Implemented Interfaces:
ListIndex<E>
,StorageIndex
,java.lang.Iterable<E>
public final class ListIndexProxy<E> extends AbstractNativeProxy implements ListIndex<E>
This list implementation does not permit null elements.
The "destructive" methods of the list, i.e., those that change its contents,
are specified to throw UnsupportedOperationException
if
this list has been created with a read-only database access.
All method arguments are non-null by default.
This class is not thread-safe and and its instances shall not be shared between threads.
When the access goes out of scope, this list is destroyed. Subsequent use of the closed list
is prohibited and will result in IllegalStateException
.
- See Also:
Access
-
Field Summary
-
Method Summary
Modifier and Type Method Description void
add(T e)
Adds a new element to the end of the list.void
addAll(java.util.Collection<? extends T> elements)
Adds all elements from the specified collection to this list.void
clear()
Clears the list.T
get(long index)
Returns the element at the given index.IndexAddress
getAddress()
Returns the index address: its identifier in the database.T
getLast()
Returns the last element of the list.boolean
isEmpty()
Returns true if the list is empty, false — otherwise.java.util.Iterator<T>
iterator()
Returns an iterator over the elements of the list.static <E> ListIndexProxy<E>
newInstance(IndexAddress address, AbstractAccess access, Serializer<E> serializer)
Creates a new ListIndexProxy.T
removeLast()
Removes the last element of the list and returns it.void
set(long index, T e)
Replaces the element at the given index of the list with the specified element.long
size()
Returns the number of elements in the list.java.util.stream.Stream<T>
stream()
Returns a stream of elements in this list.java.lang.String
toString()
void
truncate(long newSize)
Truncates the list, reducing its size tonewSize
.Methods inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
getNativeHandle, isValidHandle
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.exonum.binding.core.storage.indices.ListIndex
add, addAll, clear, get, getLast, isEmpty, iterator, removeLast, set, size, stream, truncate
Methods inherited from interface com.exonum.binding.core.storage.indices.StorageIndex
getAddress, getName
-
Method Details
-
newInstance
public static <E> ListIndexProxy<E> newInstance(IndexAddress address, AbstractAccess access, Serializer<E> serializer)Creates a new ListIndexProxy.Warning: do not invoke this method from service code, use
Access.getList(IndexAddress, Serializer)
.- Type Parameters:
E
- the type of elements in this list- Parameters:
address
- an index addressaccess
- a database access. Must be valid. If an access is read-only, "destructive" operations are not permitted.serializer
- a serializer of elements- Throws:
java.lang.IllegalStateException
- if the access is not validjava.lang.IllegalArgumentException
- if the name is empty- See Also:
StandardSerializers
-
add
public final void add(T e)Description copied from interface:ListIndex
Adds a new element to the end of the list. -
addAll
public void addAll(java.util.Collection<? extends T> elements)Description copied from interface:ListIndex
Adds all elements from the specified collection to this list.If the collection contains an invalid element, this list is not modified.
-
set
public final void set(long index, T e)Description copied from interface:ListIndex
Replaces the element at the given index of the list with the specified element. -
get
public final T get(long index)Description copied from interface:ListIndex
Returns the element at the given index. -
getLast
public final T getLast()Description copied from interface:ListIndex
Returns the last element of the list. -
removeLast
public T removeLast()Description copied from interface:ListIndex
Removes the last element of the list and returns it.- Specified by:
removeLast
in interfaceListIndex<T>
- Returns:
- the last element of the list.
-
truncate
public void truncate(long newSize)Description copied from interface:ListIndex
Truncates the list, reducing its size tonewSize
.If
newSize < size()
, keeps the firstnewSize
elements, removing the rest. IfnewSize >= size()
, has no effect. -
clear
public final void clear()Description copied from interface:ListIndex
Clears the list. -
isEmpty
public final boolean isEmpty()Description copied from interface:ListIndex
Returns true if the list is empty, false — otherwise. -
size
public final long size()Description copied from interface:ListIndex
Returns the number of elements in the list. -
iterator
public final java.util.Iterator<T> iterator()Description copied from interface:ListIndex
Returns an iterator over the elements of the list. -
stream
public java.util.stream.Stream<T> stream()Description copied from interface:ListIndex
Returns a stream of elements in this list. The returned stream is fail-fast and late-binding. The stream can be used as long as the source list is valid. -
getAddress
Description copied from interface:StorageIndex
Returns the index address: its identifier in the database.Please note that the implementations may return either relative or absolute address. The address is not required to be equal to the one passed to the index constructor.
- Specified by:
getAddress
in interfaceStorageIndex
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-