/*
 * Copyright (C) 2016 Charles Brophy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.granite.configuration;

import java.io.Serializable;
import java.util.Map;
import java.util.logging.Logger;

import static com.google.common.base.Preconditions.checkNotNull;

public final class ApplicationConfiguration implements Serializable {

    private final Map<String, String> configMap;

    ApplicationConfiguration(final Map<String, String> configMap){
        this.configMap = checkNotNull(configMap, "configMap");
    }

    public Map<String, String> getConfigMap() {
        return configMap;
    }

    public long getInt(final String configKey){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        checkNotNull(configValueString ,"Required config key %s not present", configKey);

        return Integer.valueOf(configValueString);
    }

    public int getInt(final String configKey, final int defaultValue){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        return configValueString == null ? defaultValue : Integer.valueOf(configValueString);
    }

    public long getLong(final String configKey){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        checkNotNull(configValueString ,"Required config key %s not present", configKey);

        return Long.valueOf(configValueString);
    }

    public long getLong(final String configKey, final long defaultValue){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        return configValueString == null ? defaultValue : Long.valueOf(configValueString);
    }

    public double getDouble(final String configKey){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        checkNotNull(configValueString ,"Required config key %s not present", configKey);

        return Double.valueOf(configValueString);
    }

    public double getDouble(final String configKey, final double defaultValue){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        return configValueString == null ? defaultValue : Double.valueOf(configValueString);
    }


    public String getString(final String configKey){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        checkNotNull(configValueString ,"Required config key %s not present", configKey);

        return configValueString;
    }

    public String getString(final String configKey, final String defaultValue){
        checkNotNull(configKey, "configKey");

        final String configValueString = configMap.get(configKey);

        return configValueString == null ? defaultValue : configValueString;
    }

    public void printConfig(){
        if(configMap.isEmpty()){
            Logger.getGlobal().info("No configuration loaded");
        }

        configMap
                .keySet()
                .forEach(key -> Logger.getGlobal().info(String.format("%s = %s", key, configMap.get(key))));
    }

}

@@ -1177,254 +1177,51 @@
     
-checkNotNull(configKey, %22configKey%22);%0A%0A        final String configValueString = configMap.get(configKey);%0A%0A        checkNotNull(configValueString ,%22Required config key %25s not present%22, configKey);%0A%0A        return Integer.valueOf(configValueString
+return Integer.valueOf(getString(configKey)
 );%0A 
@@ -1301,55 +1301,8 @@
 e)%7B%0A
-        checkNotNull(configKey, %22configKey%22);%0A%0A
     
@@ -1334,37 +1334,33 @@
 lueString = 
-configMap.get
+getString
 (configKey);
@@ -1523,251 +1523,48 @@
     
-checkNotNull(configKey, %22configKey%22);%0A%0A        final String configValueString = configMap.get(configKey);%0A%0A        checkNotNull(configValueString ,%22Required config key %25s not present%22, configKey);%0A%0A        return Long.valueOf(configValueString
+return Long.valueOf(getString(configKey)
 );%0A 
@@ -1647,55 +1647,8 @@
 e)%7B%0A
-        checkNotNull(configKey, %22configKey%22);%0A%0A
     
@@ -1680,37 +1680,33 @@
 lueString = 
-configMap.get
+getString
 (configKey);
@@ -1870,46 +1870,139 @@
     
-checkNotNull(configKey, %22configKey%22);%0A
+return Double.valueOf(getString(configKey));%0A    %7D%0A%0A    public double getDouble(final String configKey, final double defaultValue)%7B
 %0A   
@@ -2035,37 +2035,33 @@
 lueString = 
-configMap.get
+getString
 (configKey);
@@ -2066,37 +2066,31 @@
 );%0A%0A        
-checkNotNull(
+return 
 configValueS
@@ -2099,46 +2099,117 @@
 ing 
-,%22Required config key %25s not present%22,
+== null ? defaultValue : Double.valueOf(configValueString);%0A    %7D%0A%0A    public boolean getBoolean(final String
  con
@@ -2207,34 +2207,33 @@
 tring configKey)
-;%0A
+%7B
 %0A        return 
@@ -2224,38 +2224,39 @@
 %0A        return 
-Double
+Boolean
 .valueOf(configV
@@ -2248,33 +2248,36 @@
 valueOf(
-configValueString
+getString(configKey)
 );%0A    %7D
@@ -2289,32 +2289,34 @@
  public 
-double getDouble
+boolean getBoolean
 (final S
@@ -2330,38 +2330,39 @@
 onfigKey, final 
-double
+boolean
  defaultValue)%7B%0A
@@ -2365,55 +2365,8 @@
 e)%7B%0A
-        checkNotNull(configKey, %22configKey%22);%0A%0A
     
@@ -2398,37 +2398,33 @@
 lueString = 
-configMap.get
+getString
 (configKey);
@@ -2475,38 +2475,39 @@
  defaultValue : 
-Double
+Boolean
 .valueOf(configV
@@ -2526,17 +2526,16 @@
 %0A    %7D%0A%0A
-%0A
     publ

Add getBoolean. Re-use value lookup logic