package org.computelab.config;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public final class ConfigBuilder {

    private final List<Config> configs = new ArrayList<>();

    public ConfigBuilder addJsonConfig(final String json) {
        final String configName = JsonConfig.class.getSimpleName();
        configs.add(new JsonConfig(configName, json));
        return this;
    }

    public ConfigBuilder addJsonConfig(final String configName, final String json) {
        configs.add(new JsonConfig(configName, json));
        return this;
    }

    public ConfigBuilder addPropertiesConfig(final Properties properties) {
        final String configName = PropertiesConfig.class.getSimpleName();
        configs.add(new PropertiesConfig(configName, properties));
        return this;
    }

    public ConfigBuilder addPropertiesConfig(final String configName,
            final Properties properties) {
        configs.add(new PropertiesConfig(configName, properties));
        return this;
    }

    public ConfigBuilder addPropertiesConfig(final Properties properties,
            final String splitRegex) {
        final String configName = PropertiesConfig.class.getSimpleName();
        configs.add(new PropertiesConfig(configName, properties, splitRegex));
        return this;
    }

    public ConfigBuilder addPropertiesConfig(final String configName,
            final Properties properties, final String splitRegex) {
        configs.add(new PropertiesConfig(configName, properties, splitRegex));
        return this;
    }

    public ConfigBuilder addSystemEnvConfig() {
        final String configName = SystemEnvConfig.class.getSimpleName();
        configs.add(new SystemEnvConfig(configName));
        return this;
    }

    public ConfigBuilder addSystemEnvConfig(final String configName) {
        configs.add(new SystemEnvConfig(configName));
        return this;
    }

    public ConfigBuilder addSystemEnvConfig(final String configName,
            final String splitRegex) {
        configs.add(new SystemEnvConfig(configName, splitRegex));
        return this;
    }

    public ConfigBuilder addSystemPropertyConfig() {
        final String configName = SystemPropertyConfig.class.getSimpleName();
        configs.add(new SystemPropertyConfig(configName));
        return this;
    }

    public ConfigBuilder addSystemPropertyConfig(final String configName) {
        configs.add(new SystemPropertyConfig(configName));
        return this;
    }

    public ConfigBuilder addSystemPropertyConfig(final String configName,
            final String splitRegex) {
        configs.add(new SystemPropertyConfig(configName, splitRegex));
        return this;
    }

    public Config build() {
        return new StackedConfig(StackedConfig.class.getSimpleName(), configs);
    }

    public Config build(final String configName) {
        return new StackedConfig(configName, configs);
    }
}

@@ -275,34 +275,29 @@
     
-final String configName = 
+return addJsonConfig(
 Json
@@ -328,84 +328,15 @@
 me()
-;%0A        configs.add(new JsonConfig(configName, json));%0A        return this
+, json)
 ;%0A  
@@ -596,34 +596,35 @@
     
-final String configName = 
+return addPropertiesConfig(
 Prop
@@ -661,61 +661,8 @@
 me()
-;%0A        configs.add(new PropertiesConfig(configName
 , pr
@@ -674,32 +674,10 @@
 ies)
-)
 ;%0A
-        return this;%0A
     
@@ -744,36 +744,24 @@
  configName,
-%0A           
  final Prope
@@ -924,367 +924,98 @@
 fig(
-final Properties properties,%0A            final String splitRegex) %7B%0A        final String configName = PropertiesConfig.class.getSimpleName();%0A        configs.add(new PropertiesConfig(configName, properties, splitRegex));%0A        return this;%0A    %7D%0A%0A    public ConfigBuilder addPropertiesConfig(final String configName,%0A            final Properties properties,
+%0A            final String configName,%0A            final Properties properties,%0A           
  fin
@@ -1205,34 +1205,34 @@
     
-final String configName = 
+return addSystemEnvConfig(
 Syst
@@ -1268,83 +1268,9 @@
 me()
-;%0A        configs.add(new SystemEnvConfig(configName));%0A        return this
+)
 ;%0A  
@@ -1491,36 +1491,24 @@
  configName,
-%0A           
  final Strin
@@ -1682,102 +1682,39 @@
     
-final String configName = SystemPropertyConfig.class.getSimpleName();%0A        configs.add(new 
+return addSystemPropertyConfig(
 Syst
@@ -1733,44 +1733,33 @@
 nfig
-(config
+.class.getSimple
 Name
+(
 ));%0A
-        return this;%0A
     
@@ -1993,36 +1993,24 @@
  configName,
-%0A           
  final Strin

Simplify method calls