Interface EntryIndex<T>
-
- Type Parameters:
T- the type of an element in this entry
- All Superinterfaces:
StorageIndex
- All Known Subinterfaces:
ProofEntryIndex<T>
- All Known Implementing Classes:
EntryIndexProxy,ProofEntryIndexProxy
public interface EntryIndex<T> extends StorageIndex
An Entry is a database index that may or may not contain a single value.An Entry is analogous to
Optional, but provides modifying ("destructive") operations when created with aFork. Such methods are specified to throwUnsupportedOperationExceptionif the entry is created with aSnapshot— a read-only database access.All method arguments are non-null by default.
When the access goes out of scope, this entry is destroyed. Subsequent use of the closed entry is prohibited and will result in
IllegalStateException.- See Also:
Access
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Tget()If value is present in the entry, returns it, otherwise, throwsNoSuchElementException.booleanisPresent()Returns true if this entry exists in the database.TorElse(T valueIfAbsent)Returns the value of this entry, if it is present; otherwise, the given value.voidremove()Removes a value from this entry.voidset(T value)Sets a new value of the entry, overwriting the previous value.Optional<T>toOptional()Converts the entry toOptional.-
Methods inherited from interface com.exonum.binding.core.storage.indices.StorageIndex
getAddress, getName
-
-
-
-
Method Detail
-
set
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:
UnsupportedOperationException- if the entry is read-onlyIllegalStateException- if the index is invalid
-
isPresent
boolean isPresent()
Returns true if this entry exists in the database.- Throws:
IllegalStateException- if the index is invalid.
-
get
T get()
If value is present in the entry, returns it, otherwise, throwsNoSuchElementException.- Throws:
NoSuchElementException- if a value is not present in the EntryIllegalStateException- if the index is invalidIllegalArgumentException- if the supplied serializer cannot decode the value
-
orElse
T orElse(T valueIfAbsent)
Returns the value of this entry, if it is present; otherwise, the given value.- Parameters:
valueIfAbsent- a value to return if there is none in this entry- Throws:
IllegalStateException- if the index is invalidIllegalArgumentException- if the supplied serializer cannot decode the value
-
remove
void remove()
Removes a value from this entry.- Throws:
UnsupportedOperationException- if the entry is read-only.IllegalStateException- if the index is invalid
-
toOptional
Optional<T> toOptional()
Converts the entry toOptional.Be aware that this method represents a state of the entry at the time of calling. And the returned value won't reflect the entry changes:
entry.set("foo"); Optional<String> optionalEntry = entry.toOptional(); entry.remove(); optionalEntry.get(); // -> returns "foo"- Returns:
Optional.of(value)if value is present in the entry, otherwise returnsOptional.empty()
-
-