Interface ListIndex<T>
- Type Parameters:
T
- the type of elements in this list
- All Superinterfaces:
java.lang.Iterable<T>
,StorageIndex
- All Known Implementing Classes:
ListIndexProxy
,ProofListIndexProxy
public interface ListIndex<T> extends StorageIndex, java.lang.Iterable<T>
A list index proxy is a contiguous list of 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 view.
When the corresponding view goes out of scope, this list is destroyed. Subsequent use
of the closed list is prohibited and will result in IllegalStateException
.
This interface prohibits null elements. All method arguments are non-null by default.
-
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.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.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.void
truncate(long newSize)
Truncates the list, reducing its size tonewSize
.Methods inherited from interface com.exonum.binding.core.storage.indices.StorageIndex
getAddress, getName
-
Method Details
-
add
Adds a new element to the end of the list.- Parameters:
e
- an element to append to the list- Throws:
java.lang.IllegalStateException
- if this list is not validjava.lang.UnsupportedOperationException
- if this list is read-only
-
addAll
Adds all elements from the specified collection to this list.If the collection contains an invalid element, this list is not modified.
- Parameters:
elements
- elements to add to this list- Throws:
java.lang.NullPointerException
- if the source collection is null or it contains null elements. In this case this list is not modified.java.lang.IllegalStateException
- if this list is not validjava.lang.UnsupportedOperationException
- if this list is read-only
-
set
Replaces the element at the given index of the list with the specified element.- Parameters:
index
- an index of the element to replacee
- an element to add- Throws:
java.lang.IndexOutOfBoundsException
- if the index is invalidjava.lang.IllegalStateException
- if this list is not validjava.lang.UnsupportedOperationException
- if this list is read-only
-
get
Returns the element at the given index.- Parameters:
index
- an index of the element to return- Returns:
- an element at the given index
- Throws:
java.lang.IndexOutOfBoundsException
- if index is invalidjava.lang.IllegalStateException
- if this list is not valid
-
getLast
T getLast()Returns the last element of the list.- Returns:
- the last element of the list
- Throws:
java.util.NoSuchElementException
- if the list is emptyjava.lang.IllegalStateException
- if this list is not valid
-
removeLast
T removeLast()Removes the last element of the list and returns it.- Returns:
- the last element of the list.
- Throws:
java.util.NoSuchElementException
- if the list is emptyjava.lang.IllegalStateException
- if this list is not validjava.lang.UnsupportedOperationException
- if this list is read-only
-
truncate
void truncate(long newSize)Truncates the list, reducing its size tonewSize
.If
newSize < size()
, keeps the firstnewSize
elements, removing the rest. IfnewSize >= size()
, has no effect.- Parameters:
newSize
- the maximum number of elements to keep- Throws:
java.lang.IllegalArgumentException
- if the new size is negativejava.lang.IllegalStateException
- if this list is not validjava.lang.UnsupportedOperationException
- if this list is read-only
-
clear
void clear()Clears the list.- Throws:
java.lang.IllegalStateException
- if this list is not validjava.lang.UnsupportedOperationException
- if this list is read-only
-
isEmpty
boolean isEmpty()Returns true if the list is empty, false — otherwise.- Throws:
java.lang.IllegalStateException
- if this list is not valid
-
size
long size()Returns the number of elements in the list.- Throws:
java.lang.IllegalStateException
- if this list is not valid
-
iterator
java.util.Iterator<T> iterator()Returns an iterator over the elements of the list.- Specified by:
iterator
in interfacejava.lang.Iterable<T>
- Throws:
java.lang.IllegalStateException
- if this list is not valid
-
stream
java.util.stream.Stream<T> stream()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.- Throws:
java.lang.IllegalStateException
- if this list is not valid
-