Class 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 Detail

      • serializer

        protected final com.exonum.binding.common.serialization.CheckingSerializerDecorator<T> serializer
    • 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. Use MapIndex instead 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 empty
        IllegalStateException - 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: EntryIndex
        Sets a new value of the entry, overwriting the previous value.
        Specified by:
        set in interface EntryIndex<T>
        Parameters:
        value - a value to set. Must not be null.
      • isPresent

        public boolean isPresent()
        Description copied from interface: EntryIndex
        Returns true if this entry exists in the database.
        Specified by:
        isPresent in interface EntryIndex<T>
      • orElse

        public T orElse​(T valueIfAbsent)
        Description copied from interface: EntryIndex
        Returns the value of this entry, if it is present; otherwise, the given value.
        Specified by:
        orElse in interface EntryIndex<T>
        Parameters:
        valueIfAbsent - a value to return if there is none in this entry
      • remove

        public void remove()
        Description copied from interface: EntryIndex
        Removes a value from this entry.
        Specified by:
        remove in interface EntryIndex<T>
      • toOptional

        public Optional<T> toOptional()
        Description copied from interface: EntryIndex
        Converts the entry to 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"
          
         
        Specified by:
        toOptional in interface EntryIndex<T>
        Returns:
        Optional.of(value) if value is present in the entry, otherwise returns Optional.empty()
      • getAddress

        public IndexAddress getAddress()
        Description copied from interface: StorageIndex
        Returns 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:
        getAddress in interface StorageIndex