Class EntryIndexProxy<T>
- java.lang.Object
-
- com.exonum.binding.core.proxy.AbstractNativeProxy
-
- com.exonum.binding.core.storage.indices.EntryIndexProxy<T>
-
- Type Parameters:
T- the type of an element in this entry
- All Implemented Interfaces:
EntryIndex<T>,StorageIndex
public final class EntryIndexProxy<T> extends AbstractNativeProxy
A proxy of a native MerkleDB Entry.This class is not thread-safe and and its instances shall not be shared between threads.
-
-
Field Summary
Fields Modifier and Type Field Description protected com.exonum.binding.common.serialization.CheckingSerializerDecorator<T>serializer-
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 Tget()If value is present in the entry, returns it, otherwise, throwsNoSuchElementException.IndexAddressgetAddress()Returns the index address: its identifier in the database.booleanisPresent()Returns true if this entry exists in the database.protected byte[]nativeGet(long nativeHandle)protected byte[]nativeGetIndexHash(long nativeHandle)protected booleannativeIsPresent(long nativeHandle)protected voidnativeRemove(long nativeHandle)protected voidnativeSet(long nativeHandle, byte[] value)static <E> EntryIndexProxy<E>newInstance(IndexAddress address, AbstractAccess access, com.exonum.binding.common.serialization.Serializer<E> serializer)Creates a new Entry.TorElse(T valueIfAbsent)Returns the value of this entry, if it is present; otherwise, the given value.voidremove()Removes a value from this entry.voidset(T value)Sets a new value of the entry, overwriting the previous value.Optional<T>toOptional()Converts the entry toOptional.StringtoString()-
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.StorageIndex
getAddress, getName
-
-
-
-
Method Detail
-
newInstance
public static <E> EntryIndexProxy<E> newInstance(IndexAddress address, AbstractAccess access, com.exonum.binding.common.serialization.Serializer<E> serializer)
Creates a new Entry.Warning: do not invoke this method from service code, use
Access.getEntry(IndexAddress, Serializer).- Parameters:
address- an index address. Must correspond to a regular index, not a group. UseMapIndexinstead of groups of entries.access- a database access. Must be valid. If an access is read-only, "destructive" operations are not permitted.serializer- an entry serializer- Throws:
IllegalArgumentException- if the name is emptyIllegalStateException- if the access proxy is invalid- See Also:
StandardSerializers
-
nativeSet
protected void nativeSet(long nativeHandle, byte[] value)
-
nativeIsPresent
protected boolean nativeIsPresent(long nativeHandle)
-
nativeGet
protected byte[] nativeGet(long nativeHandle)
-
nativeGetIndexHash
protected byte[] nativeGetIndexHash(long nativeHandle)
-
nativeRemove
protected void nativeRemove(long nativeHandle)
-
set
public void set(T value)
Description copied from interface:EntryIndexSets a new value of the entry, overwriting the previous value.- Specified by:
setin interfaceEntryIndex<T>- Parameters:
value- a value to set. Must not be null.
-
isPresent
public boolean isPresent()
Description copied from interface:EntryIndexReturns true if this entry exists in the database.- Specified by:
isPresentin interfaceEntryIndex<T>
-
get
public T get()
Description copied from interface:EntryIndexIf value is present in the entry, returns it, otherwise, throwsNoSuchElementException.- Specified by:
getin interfaceEntryIndex<T>
-
orElse
public T orElse(T valueIfAbsent)
Description copied from interface:EntryIndexReturns the value of this entry, if it is present; otherwise, the given value.- Specified by:
orElsein interfaceEntryIndex<T>- Parameters:
valueIfAbsent- a value to return if there is none in this entry
-
remove
public void remove()
Description copied from interface:EntryIndexRemoves a value from this entry.- Specified by:
removein interfaceEntryIndex<T>
-
toOptional
public Optional<T> toOptional()
Description copied from interface:EntryIndexConverts the entry toOptional.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"- Specified by:
toOptionalin interfaceEntryIndex<T>- Returns:
Optional.of(value)if value is present in the entry, otherwise returnsOptional.empty()
-
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
-
-