diff --git a/scm-core/src/main/java/sonia/scm/store/StoreFactory.java b/scm-core/src/main/java/sonia/scm/store/StoreFactory.java index adf432d4e2..aae11bb201 100644 --- a/scm-core/src/main/java/sonia/scm/store/StoreFactory.java +++ b/scm-core/src/main/java/sonia/scm/store/StoreFactory.java @@ -1,10 +1,72 @@ package sonia.scm.store; +import sonia.scm.repository.Repository; + public interface StoreFactory { - STORE getStore(final StoreParameters storeParameters); + STORE getStore(final StoreParameters storeParameters); - default StoreParameters.WithType forType(Class type) { - return new StoreParameters<>(this).new WithType(type); + default FloatingStoreParameters.WithType forType(Class type) { + return new FloatingStoreParameters<>(this).new WithType(type); + } +} + +final class FloatingStoreParameters implements StoreParameters { + + private Class type; + private String name; + private Repository repository; + + private final StoreFactory factory; + + FloatingStoreParameters(StoreFactory 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.WithTypeAndName withName(String name){ + return new WithTypeAndName(name); + } + + } + public class WithTypeAndName { + + private WithTypeAndName(String name) { + FloatingStoreParameters.this.name = name; + } + + public FloatingStoreParameters.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); + } } } diff --git a/scm-core/src/main/java/sonia/scm/store/StoreParameters.java b/scm-core/src/main/java/sonia/scm/store/StoreParameters.java index 8abda1c86d..c1bb2473ea 100644 --- a/scm-core/src/main/java/sonia/scm/store/StoreParameters.java +++ b/scm-core/src/main/java/sonia/scm/store/StoreParameters.java @@ -8,62 +8,11 @@ import sonia.scm.repository.Repository; * @author Mohamed Karray * @since 2.0.0 */ -public class StoreParameters { +public interface StoreParameters{ - private Class type; - private String name; - private Repository repository; + Class getType(); - private final StoreFactory factory; + String getName(); - StoreParameters(StoreFactory 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.WithTypeAndName withName(String name){ - return new WithTypeAndName(name); - } - - } - public class WithTypeAndName { - - private WithTypeAndName(String name) { - StoreParameters.this.name = name; - } - - public StoreParameters.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(); }