Class ValueSetIndexProxy<E>

  • Type Parameters:
    E - the type of elements in this set
    All Implemented Interfaces:
    StorageIndex, Iterable<ValueSetIndexProxy.Entry<E>>

    public final class ValueSetIndexProxy<E>
    extends AbstractNativeProxy
    implements Iterable<ValueSetIndexProxy.Entry<E>>
    A value set is an index that contains no duplicate elements (values). This implementation does not permit null elements.

    The elements are stored in the underlying database as values, whereas their cryptographic hashes are used as keys, making this set implementation more suitable for storing large elements. If your application has small elements and does not need to perform set operations by hashes of the elements, consider using a KeySetIndexProxy.

    The "destructive" methods of the set, i.e., the ones that change its contents, are specified to throw UnsupportedOperationException if the set has been created with a read-only database access.

    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 access goes out of scope, this set is destroyed. Subsequent use of the closed set is prohibited and will result in IllegalStateException.

    See Also:
    KeySetIndexProxy, Access
    • Method Detail

      • newInstance

        public static <E> ValueSetIndexProxy<E> newInstance​(IndexAddress address,
                                                            AbstractAccess access,
                                                            com.exonum.binding.common.serialization.Serializer<E> serializer)
        Creates a new value set.

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

        Type Parameters:
        E - the type of values in this set
        Parameters:
        address - an index address
        access - a database access. Must be valid. If an access is read-only, "destructive" operations are not permitted.
        serializer - a serializer of values
        Throws:
        IllegalStateException - if the access is not valid
        IllegalArgumentException - if the name is empty
        See Also:
        StandardSerializers
      • add

        public void add​(E e)
        Adds a new element to the set. The method has no effect if the set already contains such element.
        Parameters:
        e - an element to add
        Throws:
        IllegalStateException - if this set is not valid
        UnsupportedOperationException - if this set is read-only
      • containsByHash

        public boolean containsByHash​(com.exonum.binding.common.hash.HashCode elementHash)
        Returns true if this set contains an element with the specified hash.
        Parameters:
        elementHash - a hash of an element
        Throws:
        IllegalStateException - if this set is not valid
      • hashes

        public Iterator<com.exonum.binding.common.hash.HashCode> hashes()
        Creates an iterator over the hashes of the elements in this set. The hashes are ordered lexicographically.
        Returns:
        an iterator over the hashes of the elements in this set
        Throws:
        IllegalStateException - if this set is not valid
      • iterator

        public Iterator<ValueSetIndexProxy.Entry<E>> iterator()
        Returns an iterator over the entries of this set. An entry is a hash-value pair. The entries are ordered by hashes lexicographically.
        Specified by:
        iterator in interface Iterable<E>
        Returns:
        an iterator over the entries of this set
        Throws:
        IllegalStateException - if this set is not valid
      • remove

        public void remove​(E e)
        Removes the element from this set. If it's not in the set, does nothing.
        Parameters:
        e - an element to remove.
        Throws:
        IllegalStateException - if this set is not valid
        UnsupportedOperationException - if this set is read-only
      • removeByHash

        public void removeByHash​(com.exonum.binding.common.hash.HashCode elementHash)
        Removes an element from this set by its hash. If there is no such element in the set, does nothing.
        Parameters:
        elementHash - the hash of an element to remove.
        Throws:
        IllegalStateException - if this set is not valid
        UnsupportedOperationException - if this set is read-only
      • 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