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>>
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 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 set is destroyed. Subsequent use of the closed set
is prohibited and will result in IllegalStateException
.
- See Also:
KeySetIndexProxy
,View
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ValueSetIndexProxy.Entry<E>
An entry of a value set index: a hash-value pair. -
Field Summary
-
Method Summary
Modifier and Type Method Description void
add(E e)
Adds a new element to the set.void
clear()
Removes all of the elements from this set.boolean
contains(E e)
Returns true if this set contains the specified element.boolean
containsByHash(HashCode elementHash)
Returns true if this set contains an element with the specified hash.IndexAddress
getAddress()
Returns the index address: its unique identifier in the database.Iterator<HashCode>
hashes()
Creates an iterator over the hashes of the elements in this set.Iterator<ValueSetIndexProxy.Entry<E>>
iterator()
Returns an iterator over the entries of this set.static <E> ValueSetIndexProxy<E>
newInGroupUnsafe(String groupName, byte[] indexId, View view, Serializer<E> serializer)
Creates a new value set in a collection group with the given name.static <E> ValueSetIndexProxy<E>
newInstance(String name, View view, Serializer<E> serializer)
Creates a new value set.static <E extends com.google.protobuf.MessageLite>
ValueSetIndexProxy<E>newInstance(String name, View view, Class<E> valueType)
Creates a new value set storing protobuf messages.void
remove(E e)
Removes the element from this set.void
removeByHash(HashCode elementHash)
Removes an element from this set by its hash.Stream<ValueSetIndexProxy.Entry<E>>
stream()
Returns a stream of the entries in this set.String
toString()
Methods inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
getNativeHandle, isValidHandle
-
Method Details
-
newInstance
public static <E extends com.google.protobuf.MessageLite> ValueSetIndexProxy<E> newInstance(String name, View view, Class<E> valueType)Creates a new value set storing protobuf messages.- Type Parameters:
E
- the type of values in this set; must be a protobuf message that has a public static#parseFrom(byte[])
method- Parameters:
name
- a unique alphanumeric non-empty identifier of this set 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.valueType
- the class of values-protobuf messages- Throws:
IllegalStateException
- if the view is not validIllegalArgumentException
- if the name is empty
-
newInstance
public static <E> ValueSetIndexProxy<E> newInstance(String name, View view, Serializer<E> serializer)Creates a new value set.- Type Parameters:
E
- the type of values in this set- Parameters:
name
- a unique alphanumeric non-empty identifier of this set 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
- a serializer of values- Throws:
IllegalStateException
- if the view is not validIllegalArgumentException
- if the name is empty- See Also:
StandardSerializers
-
newInGroupUnsafe
public static <E> ValueSetIndexProxy<E> newInGroupUnsafe(String groupName, byte[] indexId, View view, Serializer<E> serializer)Creates a new value set in a collection group with the given name.See a caveat on index identifiers.
- Type Parameters:
E
- the type of values in this set- Parameters:
groupName
- a name of the collection groupindexId
- an identifier of this collection in the group, see the caveatsview
- a database viewserializer
- a serializer of set values- Returns:
- a new value set
- Throws:
IllegalStateException
- if the view is not validIllegalArgumentException
- if the name or index id is empty- See Also:
StandardSerializers
-
add
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
Returns true if this set contains the specified element.- Throws:
IllegalStateException
- if this set is not valid- See Also:
containsByHash(HashCode)
-
containsByHash
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
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
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 interfaceIterable<E>
- Returns:
- an iterator over the entries of this set
- Throws:
IllegalStateException
- if this set is not valid
-
stream
Returns a stream of the entries in this set. An entry is a hash-value pair. The entries are ordered by hashes lexicographically.- Throws:
IllegalStateException
- if this set is not valid
-
remove
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
-
removeByHash
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 validUnsupportedOperationException
- if this set is read-only
-
getAddress
Description copied from interface:StorageIndex
Returns the index address: its unique identifier in the database. It consists of the name and, in case this index belongs to an index family, a family identifier.- Specified by:
getAddress
in interfaceStorageIndex
-
toString
-