Class KeySetIndexProxy<E>
- java.lang.Object
-
- com.exonum.binding.core.proxy.AbstractNativeProxy
-
- com.exonum.binding.core.storage.indices.KeySetIndexProxy<E>
-
- Type Parameters:
E- the type of elements in this set
- All Implemented Interfaces:
StorageIndex,Iterable<E>
public final class KeySetIndexProxy<E> extends AbstractNativeProxy implements Iterable<E>
A key set is an index that contains no duplicate elements (keys). This implementation does not permit null elements.The elements are stored as keys in the underlying database in the lexicographical order. As each operation accepting an element needs to pass the entire element to the underlying database as a key, it's better, in terms of performance, to use this index with small elements. If you need to store large elements and can perform operations by hashes of the elements, consider using a
ValueSetIndexProxy.The "destructive" methods of the set, i.e., the ones that change its contents, are specified to throw
UnsupportedOperationExceptionif 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:
ValueSetIndexProxy,Access
-
-
Field Summary
-
Fields inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
nativeHandle
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(E e)Adds a new element to the set.voidclear()Removes all of the elements from this set.booleancontains(E e)Returns true if this set contains the specified element.IndexAddressgetAddress()Returns the index address: its identifier in the database.Iterator<E>iterator()Creates an iterator over the set elements.static <E> KeySetIndexProxy<E>newInstance(IndexAddress address, AbstractAccess access, com.exonum.binding.common.serialization.Serializer<E> serializer)Creates a new key set proxy.voidremove(E e)Removes the element from this set.Stream<E>stream()Returns a stream of the set elements.StringtoString()-
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 java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface com.exonum.binding.core.storage.indices.StorageIndex
getName
-
-
-
-
Method Detail
-
newInstance
public static <E> KeySetIndexProxy<E> newInstance(IndexAddress address, AbstractAccess access, com.exonum.binding.common.serialization.Serializer<E> serializer)
Creates a new key set proxy.Warning: do not invoke this method from service code, use
Access.getKeySet(IndexAddress, Serializer).- Type Parameters:
E- the type of keys in this set- Parameters:
address- an index addressaccess- a database access. Must be valid. If an access is read-only, "destructive" operations are not permitted.serializer- a serializer of set keys- Throws:
IllegalStateException- if the access is not validIllegalArgumentException- 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 validUnsupportedOperationException- if this set is read-only
-
clear
public void clear()
Removes all of the elements from this set. The set will be empty after this method returns.- Throws:
IllegalStateException- if this set is not validUnsupportedOperationException- if this set is read-only
-
contains
public boolean contains(E e)
Returns true if this set contains the specified element.- Throws:
IllegalStateException- if this set is not valid
-
iterator
public Iterator<E> iterator()
Creates an iterator over the set elements. The elements are ordered lexicographically.- Specified by:
iteratorin interfaceIterable<E>- Returns:
- an iterator over the elements of this set
- Throws:
IllegalStateException- if this set is not valid
-
stream
public Stream<E> stream()
Returns a stream of the set elements. The elements are ordered lexicographically.- 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 validUnsupportedOperationException- if this set is read-only
-
getAddress
public IndexAddress getAddress()
Description copied from interface:StorageIndexReturns 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:
getAddressin interfaceStorageIndex
-
-