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 Detail

      • 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:
        UnsupportedOperationException - if the entry is read-only
        IllegalStateException - if the index is invalid
      • isPresent

        boolean isPresent()
        Returns true if this entry exists in the database.
        Throws:
        IllegalStateException - if the index is invalid.
      • 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:
        IllegalStateException - if the index is invalid
        IllegalArgumentException - if the supplied serializer cannot decode the value
      • toOptional

        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()