Class ProofListIndexProxy<E>
- java.lang.Object
-
- com.exonum.binding.core.proxy.AbstractNativeProxy
-
- com.exonum.binding.core.storage.indices.ProofListIndexProxy<E>
-
- Type Parameters:
E- the type of elements in this list
- All Implemented Interfaces:
HashableIndex,ListIndex<E>,StorageIndex,Iterable<E>
public final class ProofListIndexProxy<E> extends AbstractNativeProxy implements ListIndex<E>, HashableIndex
A proof list index proxy is a contiguous list of elements, capable of providing cryptographic proofs that it contains a certain element at a particular position. Non-null elements may be added to the end of the list only.The proof list is implemented as a hash tree (Merkle tree).
The "destructive" methods of the list, i.e., those that change its contents, are specified to throw
UnsupportedOperationExceptionif 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
-
Fields inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
nativeHandle
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T e)Adds a new element to the end of the list.voidaddAll(Collection<? extends T> elements)Adds all elements from the specified collection to this list.voidclear()Clears the list.Tget(long index)Returns the element at the given index.IndexAddressgetAddress()Returns the index address: its identifier in the database.com.exonum.binding.common.hash.HashCodegetIndexHash()Returns the index hash which represents the complete state of this index.TgetLast()Returns the last element of the list.ListProofgetProof(long index)Returns a proof of either existence or absence of an element at the specified index in this list.ListProofgetRangeProof(long from, long to)Returns a proof of either existence or absence of some elements in the specified range in this list.booleanisEmpty()Returns true if the list is empty, false — otherwise.Iterator<T>iterator()Returns an iterator over the elements of the list.static <E> ProofListIndexProxy<E>newInstance(IndexAddress address, AbstractAccess access, com.exonum.binding.common.serialization.Serializer<E> serializer)Creates a new ProofListIndexProxy.TremoveLast()Removes the last element of the list and returns it.voidset(long index, T e)Replaces the element at the given index of the list with the specified element.longsize()Returns the number of elements in the list.Stream<T>stream()Returns a stream of elements in this list.StringtoString()voidtruncate(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 java.lang.Iterable
forEach, spliterator
-
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 Detail
-
newInstance
public static <E> ProofListIndexProxy<E> newInstance(IndexAddress address, AbstractAccess access, com.exonum.binding.common.serialization.Serializer<E> serializer)
Creates a new ProofListIndexProxy.Warning: do not invoke this method from service code, use
Access.getProofList(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:
IllegalStateException- if the access is not validIllegalArgumentException- if the name is empty- See Also:
StandardSerializers
-
getProof
public ListProof getProof(long index)
Returns a proof of either existence or absence of an element at the specified index in this list.- Parameters:
index- the element index- Throws:
IndexOutOfBoundsException- if the index is invalidIllegalStateException- if this list is not valid- See Also:
- Blockchain Proofs
-
getRangeProof
public ListProof getRangeProof(long from, long to)
Returns a proof of either existence or absence of some elements in the specified range in this list. If some elements are present in the list, but some — are not (i.e., the requested range exceeds its size), a proof of absence is returned.- Parameters:
from- the index of the first elementto- the index after the last element- Throws:
IndexOutOfBoundsException- if the range is not validIllegalStateException- if this list is not valid
-
getIndexHash
public com.exonum.binding.common.hash.HashCode getIndexHash()
Description copied from interface:HashableIndexReturns the index hash which represents the complete state of this index. Any modifications to the stored entries affect the index hash.How index hash is computed depends on the index data structure implementation.
- Specified by:
getIndexHashin interfaceHashableIndex
-
add
public final void add(T e)
Description copied from interface:ListIndexAdds a new element to the end of the list.
-
addAll
public void addAll(Collection<? extends T> elements)
Description copied from interface:ListIndexAdds 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:ListIndexReplaces the element at the given index of the list with the specified element.
-
get
public final T get(long index)
Description copied from interface:ListIndexReturns the element at the given index.
-
getLast
public final T getLast()
Description copied from interface:ListIndexReturns the last element of the list.
-
removeLast
public T removeLast()
Description copied from interface:ListIndexRemoves the last element of the list and returns it.- Specified by:
removeLastin interfaceListIndex<T>- Returns:
- the last element of the list.
-
truncate
public void truncate(long newSize)
Description copied from interface:ListIndexTruncates the list, reducing its size tonewSize.If
newSize < size(), keeps the firstnewSizeelements, removing the rest. IfnewSize >= size(), has no effect.
-
clear
public final void clear()
Description copied from interface:ListIndexClears the list.
-
isEmpty
public final boolean isEmpty()
Description copied from interface:ListIndexReturns true if the list is empty, false — otherwise.
-
size
public final long size()
Description copied from interface:ListIndexReturns the number of elements in the list.
-
iterator
public final Iterator<T> iterator()
Description copied from interface:ListIndexReturns an iterator over the elements of the list.
-
stream
public Stream<T> stream()
Description copied from interface:ListIndexReturns 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
public IndexAddress getAddress()
Description copied from interface:StorageIndexReturns 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:
getAddressin interfaceStorageIndex
-
-