mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-20 22:42:16 +01:00
Use interface for StoreParameters
This commit is contained in:
@@ -1,10 +1,72 @@
|
||||
package sonia.scm.store;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
public interface StoreFactory<STORE> {
|
||||
|
||||
STORE getStore(final StoreParameters<STORE> storeParameters);
|
||||
STORE getStore(final StoreParameters storeParameters);
|
||||
|
||||
default StoreParameters<STORE>.WithType forType(Class type) {
|
||||
return new StoreParameters<>(this).new WithType(type);
|
||||
default FloatingStoreParameters<STORE>.WithType forType(Class type) {
|
||||
return new FloatingStoreParameters<>(this).new WithType(type);
|
||||
}
|
||||
}
|
||||
|
||||
final class FloatingStoreParameters<STORE> implements StoreParameters {
|
||||
|
||||
private Class type;
|
||||
private String name;
|
||||
private Repository repository;
|
||||
|
||||
private final StoreFactory<STORE> factory;
|
||||
|
||||
FloatingStoreParameters(StoreFactory<STORE> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public Class getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Repository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public class WithType {
|
||||
|
||||
WithType(Class type) {
|
||||
FloatingStoreParameters.this.type = type;
|
||||
}
|
||||
|
||||
public FloatingStoreParameters<STORE>.WithTypeAndName withName(String name){
|
||||
return new WithTypeAndName(name);
|
||||
}
|
||||
|
||||
}
|
||||
public class WithTypeAndName {
|
||||
|
||||
private WithTypeAndName(String name) {
|
||||
FloatingStoreParameters.this.name = name;
|
||||
}
|
||||
|
||||
public FloatingStoreParameters<STORE>.WithTypeNameAndRepository forRepository(Repository repository){
|
||||
return new WithTypeNameAndRepository(repository);
|
||||
}
|
||||
public STORE build(){
|
||||
return factory.getStore(FloatingStoreParameters.this);
|
||||
}
|
||||
}
|
||||
|
||||
public class WithTypeNameAndRepository {
|
||||
|
||||
private WithTypeNameAndRepository(Repository repository) {
|
||||
FloatingStoreParameters.this.repository = repository;
|
||||
}
|
||||
public STORE build(){
|
||||
return factory.getStore(FloatingStoreParameters.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,62 +8,11 @@ import sonia.scm.repository.Repository;
|
||||
* @author Mohamed Karray
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class StoreParameters<STORE> {
|
||||
public interface StoreParameters{
|
||||
|
||||
private Class type;
|
||||
private String name;
|
||||
private Repository repository;
|
||||
Class getType();
|
||||
|
||||
private final StoreFactory<STORE> factory;
|
||||
String getName();
|
||||
|
||||
StoreParameters(StoreFactory<STORE> factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public Class getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Repository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public class WithType {
|
||||
|
||||
WithType(Class type) {
|
||||
StoreParameters.this.type = type;
|
||||
}
|
||||
|
||||
public StoreParameters<STORE>.WithTypeAndName withName(String name){
|
||||
return new WithTypeAndName(name);
|
||||
}
|
||||
|
||||
}
|
||||
public class WithTypeAndName {
|
||||
|
||||
private WithTypeAndName(String name) {
|
||||
StoreParameters.this.name = name;
|
||||
}
|
||||
|
||||
public StoreParameters<STORE>.WithTypeNameAndRepository forRepository(Repository repository){
|
||||
return new WithTypeNameAndRepository(repository);
|
||||
}
|
||||
public STORE build(){
|
||||
return factory.getStore(StoreParameters.this);
|
||||
}
|
||||
}
|
||||
|
||||
public class WithTypeNameAndRepository {
|
||||
|
||||
private WithTypeNameAndRepository(Repository repository) {
|
||||
StoreParameters.this.repository = repository;
|
||||
}
|
||||
public STORE build(){
|
||||
return factory.getStore(StoreParameters.this);
|
||||
}
|
||||
}
|
||||
Repository getRepository();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user