T - the type of an element in this entrypublic final class EntryIndexProxy<T> extends AbstractNativeProxy
An Entry is analogous to Optional, but provides modifying ("destructive")
operations when created with a Fork.
Such methods are specified to throw UnsupportedOperationException if
the entry is created with a Snapshot — a read-only database view.
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 view goes out of scope, this entry is destroyed. Subsequent use of the closed entry
is prohibited and will result in IllegalStateException.
ViewnativeHandle| Modifier and Type | Method and Description |
|---|---|
T |
get()
If value is present in the entry, returns it, otherwise,
throws
NoSuchElementException. |
IndexAddress |
getAddress()
Returns the index address: its unique identifier in the database.
|
boolean |
isPresent()
Returns true if this entry exists in the database.
|
static <E extends com.google.protobuf.MessageLite> |
newInstance(String name,
View view,
Class<E> elementType)
Creates a new Entry storing protobuf messages.
|
static <E> EntryIndexProxy<E> |
newInstance(String name,
View view,
com.exonum.binding.common.serialization.Serializer<E> serializer)
Creates a new Entry.
|
void |
remove()
Removes a value from this entry.
|
void |
set(T value)
Sets a new value of the entry, overwriting the previous value.
|
Optional<T> |
toOptional()
Converts the entry to
Optional. |
String |
toString() |
getNativeHandle, isValidHandleclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetNamepublic static <E extends com.google.protobuf.MessageLite> EntryIndexProxy<E> newInstance(String name, View view, Class<E> elementType)
E - the type of entry; must be a protobuf message
that has a static #parseFrom(byte[]) methodname - a unique alphanumeric non-empty identifier of the Entry in the underlying storage:
[a-zA-Z0-9_]view - a database view. Must be valid.
If a view is read-only, "destructive" operations are not permitted.elementType - the class of an element-protobuf messageIllegalArgumentException - if the name is emptyIllegalStateException - if the view proxy is invalidpublic static <E> EntryIndexProxy<E> newInstance(String name, View view, com.exonum.binding.common.serialization.Serializer<E> serializer)
name - a unique alphanumeric non-empty identifier of the Entry in the underlying storage:
[a-zA-Z0-9_]view - a database view. Must be valid.
If a view is read-only, "destructive" operations are not permitted.serializer - an entry serializerIllegalArgumentException - if the name is emptyIllegalStateException - if the view proxy is invalidStandardSerializerspublic void set(T value)
value - a value to set. Must not be null.UnsupportedOperationException - if the entry is read-onlyIllegalStateException - if the proxy is invalidpublic boolean isPresent()
IllegalStateException - if the proxy is invalid.public T get()
NoSuchElementException.NoSuchElementException - if a value is not present in the EntryIllegalStateException - if the proxy is invalidIllegalArgumentException - if the supplied serializer cannot decode the valuepublic void remove()
UnsupportedOperationException - if the entry is read-only.IllegalStateException - if the proxy is invalidpublic Optional<T> toOptional()
Optional.
Be aware that this method represents a state of the entry at the time of calling. And the returned value won't reflect the entry changes:
entry.set("foo");
Optional<String> optionalEntry = entry.toOptional();
entry.remove();
optionalEntry.get(); // -> returns "foo"
Optional.of(value) if value is present in the entry,
otherwise returns Optional.empty()public IndexAddress getAddress()
StorageIndexgetAddress in interface StorageIndexCopyright © 2019 Exonum. All rights reserved.