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
.
View
nativeHandle
Modifier and Type | Method and Description |
---|---|
T |
get()
If value is present in the entry, returns it, otherwise,
throws
NoSuchElementException . |
java.lang.String |
getName()
Returns the name of this index.
|
boolean |
isPresent()
Returns true if this entry exists in the database.
|
static <E extends com.google.protobuf.MessageLite> |
newInstance(java.lang.String name,
View view,
java.lang.Class<E> elementType)
Creates a new Entry storing protobuf messages.
|
static <E> EntryIndexProxy<E> |
newInstance(java.lang.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.
|
java.lang.String |
toString() |
getNativeHandle, isValidHandle
public static <E extends com.google.protobuf.MessageLite> EntryIndexProxy<E> newInstance(java.lang.String name, View view, java.lang.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 messagejava.lang.IllegalArgumentException
- if the name is emptyjava.lang.IllegalStateException
- if the view proxy is invalidpublic static <E> EntryIndexProxy<E> newInstance(java.lang.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 serializerjava.lang.IllegalArgumentException
- if the name is emptyjava.lang.IllegalStateException
- if the view proxy is invalidStandardSerializers
public void set(T value)
value
- a value to set. Must not be null.java.lang.UnsupportedOperationException
- if the entry is read-onlyjava.lang.IllegalStateException
- if the proxy is invalidpublic boolean isPresent()
java.lang.IllegalStateException
- if the proxy is invalid.public T get()
NoSuchElementException
.java.util.NoSuchElementException
- if a value is not present in the Entryjava.lang.IllegalStateException
- if the proxy is invalidjava.lang.IllegalArgumentException
- if the supplied serializer cannot decode the valuepublic void remove()
java.lang.UnsupportedOperationException
- if the entry is read-only.java.lang.IllegalStateException
- if the proxy is invalidpublic final java.lang.String getName()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2018 Exonum. All rights reserved.