Class EntryIndexProxy<T>

  • Type Parameters:
    T - the type of an element in this entry

    public final class EntryIndexProxy<T>
    extends AbstractNativeProxy
    An Entry is a database index that can contain no or 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 view.

    All method arguments are non-null by default.

    This class is not thread-safe and and its instances shall not be shared between threads.

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

    See Also:
    View
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()
      If value is present in the entry, returns it, otherwise, throws NoSuchElementException.
      java.lang.String getName()
      Returns the name of this index.
      boolean isPresent()
      Returns true if this entry exists in the database.
      static <E> EntryIndexProxy<E> newInstance​(java.lang.String name, View view, com.exonum.binding.common.serialization.Serializer<E> serializer)
      Creates a new Entry.
      static <E extends com.google.protobuf.MessageLite>
      EntryIndexProxy<E>
      newInstance​(java.lang.String name, View view, java.lang.Class<E> elementType)
      Creates a new Entry storing protobuf messages.
      void remove()
      Removes a value from this entry.
      void set​(T value)
      Sets a new value of the entry, overwriting the previous value.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • newInstance

        public static <E extends com.google.protobuf.MessageLite> EntryIndexProxy<E> newInstance​(java.lang.String name,
                                                                                                 View view,
                                                                                                 java.lang.Class<E> elementType)
        Creates a new Entry storing protobuf messages.
        Type Parameters:
        E - the type of entry; must be a protobuf message that has a static #parseFrom(byte[]) method
        Parameters:
        name - a unique alphanumeric non-empty identifier of the Entry in the underlying storage: [a-zA-Z0-9_]
        view - a database view. Must be valid. If a view is read-only, "destructive" operations are not permitted.
        elementType - the class of an element-protobuf message
        Throws:
        java.lang.IllegalArgumentException - if the name is empty
        java.lang.IllegalStateException - if the view proxy is invalid
      • newInstance

        public static <E> EntryIndexProxy<E> newInstance​(java.lang.String name,
                                                         View view,
                                                         com.exonum.binding.common.serialization.Serializer<E> serializer)
        Creates a new Entry.
        Parameters:
        name - a unique alphanumeric non-empty identifier of the Entry in the underlying storage: [a-zA-Z0-9_]
        view - a database view. Must be valid. If a view 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 view proxy is invalid
        See Also:
        StandardSerializers
      • set

        public 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 proxy is invalid
      • isPresent

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

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

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

        public final java.lang.String getName()
        Returns the name of this index.
      • toString

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