Interface EntryIndex<T>

Type Parameters:
T - the type of an element in this entry
All Superinterfaces:
StorageIndex
All Known Subinterfaces:
ProofEntryIndex<T>
All Known Implementing Classes:
EntryIndexProxy, ProofEntryIndexProxy

public interface EntryIndex<T>
extends StorageIndex
An Entry is a database index that may or may not contain a single value.

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

All method arguments are non-null by default.

When the access goes out of scope, this entry is destroyed. Subsequent use of the closed entry is prohibited and will result in IllegalStateException.

See Also:
Access
  • Method Summary

    Modifier and Type Method Description
    T get()
    If value is present in the entry, returns it, otherwise, throws NoSuchElementException.
    boolean isPresent()
    Returns true if this entry exists in the database.
    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.

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

    getAddress, getName
  • Method Details

    • set

      void set​(T value)
      Sets a new value of the entry, overwriting the previous value.
      Parameters:
      value - a value to set. Must not be null.
      Throws:
      java.lang.UnsupportedOperationException - if the entry is read-only
      java.lang.IllegalStateException - if the index is invalid
    • isPresent

      boolean isPresent()
      Returns true if this entry exists in the database.
      Throws:
      java.lang.IllegalStateException - if the index is invalid.
    • get

      T get()
      If value is present in the entry, returns it, otherwise, throws NoSuchElementException.
      Throws:
      java.util.NoSuchElementException - if a value is not present in the Entry
      java.lang.IllegalStateException - if the index is invalid
      java.lang.IllegalArgumentException - if the supplied serializer cannot decode the value
    • orElse

      T orElse​(T valueIfAbsent)
      Returns the value of this entry, if it is present; otherwise, the given value.
      Parameters:
      valueIfAbsent - a value to return if there is none in this entry
      Throws:
      java.lang.IllegalStateException - if the index is invalid
      java.lang.IllegalArgumentException - if the supplied serializer cannot decode the value
    • remove

      void remove()
      Removes a value from this entry.
      Throws:
      java.lang.UnsupportedOperationException - if the entry is read-only.
      java.lang.IllegalStateException - if the index is invalid
    • toOptional

      java.util.Optional<T> toOptional()
      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"
        
       
      Returns:
      Optional.of(value) if value is present in the entry, otherwise returns Optional.empty()