Add getters with Optional to stores

This commit is contained in:
René Pfeuffer
2018-12-14 14:50:14 +01:00
parent 9666c174b4
commit d02cb60b47
2 changed files with 32 additions and 2 deletions

View File

@@ -33,6 +33,10 @@
package sonia.scm.store;
import java.util.Optional;
import static java.util.Optional.ofNullable;
/**
* ConfigurationStore for configuration objects. <strong>Note:</strong> the default
* implementation use JAXB to marshall the configuration objects.
@@ -50,7 +54,17 @@ public interface ConfigurationStore<T>
*
* @return configuration object from store
*/
public T get();
T get();
/**
* Returns the configuration object from store.
*
*
* @return configuration object from store
*/
default Optional<T> getOptional() {
return ofNullable(get());
}
//~--- set methods ----------------------------------------------------------
@@ -60,5 +74,5 @@ public interface ConfigurationStore<T>
*
* @param obejct configuration object to store
*/
public void set(T obejct);
void set(T object);
}

View File

@@ -32,6 +32,10 @@
package sonia.scm.store;
import java.util.Optional;
import static java.util.Optional.ofNullable;
/**
* Base class for {@link BlobStore} and {@link DataStore}.
*
@@ -67,4 +71,16 @@ public interface MultiEntryStore<T> {
* @return item with the given id
*/
public T get(String id);
/**
* Returns the item with the given id from the store.
*
*
* @param id id of the item to return
*
* @return item with the given id
*/
default Optional<T> getOptional(String id) {
return ofNullable(get(id));
}
}