E
- the type of elements in this setpublic final class ValueSetIndexProxy<E> extends AbstractNativeProxy implements java.lang.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
.
KeySetIndexProxy
,
View
Modifier and Type | Class and Description |
---|---|
static class |
ValueSetIndexProxy.Entry<E>
An entry of a value set index: a hash-value pair.
|
nativeHandle
Modifier and Type | Method and 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(com.exonum.binding.common.hash.HashCode elementHash)
Returns true if this set contains an element with the specified hash.
|
java.lang.String |
getName()
Returns the name of this index.
|
java.util.Iterator<com.exonum.binding.common.hash.HashCode> |
hashes()
Creates an iterator over the hashes of the elements in this set.
|
java.util.Iterator<ValueSetIndexProxy.Entry<E>> |
iterator()
Returns an iterator over the entries of this set.
|
static <E> ValueSetIndexProxy<E> |
newInGroupUnsafe(java.lang.String groupName,
byte[] indexId,
View view,
com.exonum.binding.common.serialization.Serializer<E> serializer)
Creates a new value set in a collection group
with the given name.
|
static <E extends com.google.protobuf.MessageLite> |
newInstance(java.lang.String name,
View view,
java.lang.Class<E> valueType)
Creates a new value set storing protobuf messages.
|
static <E> ValueSetIndexProxy<E> |
newInstance(java.lang.String name,
View view,
com.exonum.binding.common.serialization.Serializer<E> serializer)
Creates a new value set.
|
void |
remove(E e)
Removes the element from this set.
|
void |
removeByHash(com.exonum.binding.common.hash.HashCode elementHash)
Removes an element from this set by its hash.
|
java.lang.String |
toString() |
getNativeHandle, isValidHandle
public static <E extends com.google.protobuf.MessageLite> ValueSetIndexProxy<E> newInstance(java.lang.String name, View view, java.lang.Class<E> valueType)
E
- the type of values in this set; must be a protobuf message
that has a public static #parseFrom(byte[])
methodname
- 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 messagesjava.lang.IllegalStateException
- if the view is not validjava.lang.IllegalArgumentException
- if the name is emptypublic static <E> ValueSetIndexProxy<E> newInstance(java.lang.String name, View view, com.exonum.binding.common.serialization.Serializer<E> serializer)
E
- the type of values in this setname
- 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 valuesjava.lang.IllegalStateException
- if the view is not validjava.lang.IllegalArgumentException
- if the name is emptyStandardSerializers
public static <E> ValueSetIndexProxy<E> newInGroupUnsafe(java.lang.String groupName, byte[] indexId, View view, com.exonum.binding.common.serialization.Serializer<E> serializer)
See a caveat on index identifiers.
E
- the type of values in this setgroupName
- a name of the collection groupindexId
- an identifier of this collection in the group, see the caveatsview
- a database viewserializer
- a serializer of set valuesjava.lang.IllegalStateException
- if the view is not validjava.lang.IllegalArgumentException
- if the name or index id is emptyStandardSerializers
public void add(E e)
e
- an element to addjava.lang.IllegalStateException
- if this set is not validjava.lang.UnsupportedOperationException
- if this set is read-onlypublic void clear()
java.lang.IllegalStateException
- if this set is not validjava.lang.UnsupportedOperationException
- if this set is read-onlypublic boolean contains(E e)
java.lang.IllegalStateException
- if this set is not validcontainsByHash(HashCode)
public boolean containsByHash(com.exonum.binding.common.hash.HashCode elementHash)
elementHash
- a hash of an elementjava.lang.IllegalStateException
- if this set is not validpublic java.util.Iterator<com.exonum.binding.common.hash.HashCode> hashes()
Any destructive operation on the same Fork
this set uses
(but not necessarily on this set) will invalidate the iterator.
java.lang.IllegalStateException
- if this set is not validpublic java.util.Iterator<ValueSetIndexProxy.Entry<E>> iterator()
Any destructive operation on the same Fork
this set uses
(but not necessarily on this set) will invalidate the iterator.
iterator
in interface java.lang.Iterable<ValueSetIndexProxy.Entry<E>>
java.lang.IllegalStateException
- if this set is not validpublic void remove(E e)
e
- an element to remove.java.lang.IllegalStateException
- if this set is not validjava.lang.UnsupportedOperationException
- if this set is read-onlypublic void removeByHash(com.exonum.binding.common.hash.HashCode elementHash)
elementHash
- the hash of an element to remove.java.lang.IllegalStateException
- if this set is not validjava.lang.UnsupportedOperationException
- if this set is read-onlypublic final java.lang.String getName()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2018 Exonum. All rights reserved.