mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-18 21:42:10 +01:00
Add getters with Optional to stores
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user