Class ProofEntryIndexProxy<T>

java.lang.Object
com.exonum.binding.core.proxy.AbstractNativeProxy
com.exonum.binding.core.storage.indices.ProofEntryIndexProxy<T>
Type Parameters:
T - the type of an element in this entry
All Implemented Interfaces:
EntryIndex<T>, HashableIndex, ProofEntryIndex<T>, StorageIndex

public final class ProofEntryIndexProxy<T>
extends AbstractNativeProxy
implements ProofEntryIndex<T>
A proxy of a native MerkleDB ProofEntry.

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 CheckingSerializerDecorator<T> serializer  

    Fields inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy

    nativeHandle
  • Method Summary

    Modifier and Type Method Description
    T get()
    If value is present in the entry, returns it, otherwise, throws NoSuchElementException.
    IndexAddress getAddress()
    Returns the index address: its identifier in the database.
    HashCode getIndexHash()
    Returns the index hash which represents the complete state of this entry.
    boolean isPresent()
    Returns true if this entry exists in the database.
    protected byte[] nativeGet​(long nativeHandle)  
    protected byte[] nativeGetIndexHash​(long nativeHandle)  
    protected boolean nativeIsPresent​(long nativeHandle)  
    protected void nativeRemove​(long nativeHandle)  
    protected void nativeSet​(long nativeHandle, byte[] value)  
    static <E> ProofEntryIndexProxy<E> newInstance​(IndexAddress address, AbstractAccess access, Serializer<E> serializer)
    Creates a new Entry.
    T orElse​(T valueIfAbsent)
    Returns the value of this entry, if it is present; otherwise, the given value.
    void remove()
    Removes a value from this entry.
    void set​(T value)
    Sets a new value of the entry, overwriting the previous value.
    java.util.Optional<T> toOptional()
    Converts the entry to Optional.
    java.lang.String toString()  

    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.EntryIndex

    get, isPresent, orElse, remove, set, toOptional

    Methods inherited from interface com.exonum.binding.core.storage.indices.StorageIndex

    getAddress, getName
  • Field Details

  • Method Details

    • newInstance

      public static <E> ProofEntryIndexProxy<E> newInstance​(IndexAddress address, AbstractAccess access, Serializer<E> serializer)
      Creates a new Entry.

      Warning: do not invoke this method from service code, use Access.getProofEntry(IndexAddress, Serializer).

      Parameters:
      address - an index address. Must correspond to a regular index, not a group. Use ProofMapIndexProxy 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:
      java.lang.IllegalArgumentException - if the name is empty
      java.lang.IllegalStateException - if the access proxy is invalid
      See Also:
      StandardSerializers
    • getIndexHash

      public HashCode getIndexHash()
      Description copied from interface: ProofEntryIndex
      Returns the index hash which represents the complete state of this entry. Any modifications to this entry affect the index hash.

      The entry index hash is computed as SHA-256 of the entry binary representation, or a hash of zeroes if the entry is not set.

      Specified by:
      getIndexHash in interface HashableIndex
      Specified by:
      getIndexHash in interface ProofEntryIndex<T>
    • 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>
    • get

      public T get()
      Description copied from interface: EntryIndex
      If value is present in the entry, returns it, otherwise, throws NoSuchElementException.
      Specified by:
      get 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 java.util.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
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object