mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-02 20:59:10 +01:00
Use PermissionDescriptor instead of String
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package sonia.scm.store;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class InMemoryConfigurationEntryStore<V> implements ConfigurationEntryStore<V> {
|
||||
|
||||
private final Map<String, V> values = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Collection<V> getMatchingValues(Predicate<V> predicate) {
|
||||
return values.values().stream().filter(predicate).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String put(V item) {
|
||||
String key = UUID.randomUUID().toString();
|
||||
values.put(key, item);
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String id, V item) {
|
||||
values.put(id, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, V> getAll() {
|
||||
return Collections.unmodifiableMap(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
values.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(String id) {
|
||||
values.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(String id) {
|
||||
return values.get(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package sonia.scm.store;
|
||||
|
||||
public class InMemoryConfigurationEntryStoreFactory implements ConfigurationEntryStoreFactory {
|
||||
|
||||
|
||||
|
||||
|
||||
private ConfigurationEntryStore store;
|
||||
|
||||
public static ConfigurationEntryStoreFactory create() {
|
||||
return new InMemoryConfigurationEntryStoreFactory(new InMemoryConfigurationEntryStore());
|
||||
}
|
||||
|
||||
public InMemoryConfigurationEntryStoreFactory() {
|
||||
}
|
||||
|
||||
public InMemoryConfigurationEntryStoreFactory(ConfigurationEntryStore store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ConfigurationEntryStore<T> getStore(TypedStoreParameters<T> storeParameters) {
|
||||
if (store != null) {
|
||||
return store;
|
||||
}
|
||||
return new InMemoryConfigurationEntryStore<>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user