/*
 * Copyright 2015 Olivier Grégoire <https://github.com/ogregoire>.
 *
 * 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 be.fror.common.resource;

import com.google.common.io.ByteSource;

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author Olivier Grégoire &lt;https://github.com/ogregoire&gt;
 */
public class ResourceLoaders {

  private ResourceLoaders() {
  }

  public static ResourceLoader<Properties> propertiesLoader() {
    return StandardPropertiesLoader.PROPERTIES;
  }

  public static ResourceLoader<Properties> xmlPropertiesLoader() {
    return StandardPropertiesLoader.XML;
  }

  private enum StandardPropertiesLoader implements ResourceLoader<Properties> {

    PROPERTIES {
          @Override
          public Properties load(ByteSource source) throws IOException {
            Properties properties = new Properties();
            properties.load(source.openStream());
            return properties;
          }

        },
    XML {
          @Override
          public Properties load(ByteSource source) throws IOException {
            Properties properties = new Properties();
            properties.loadFromXML(source.openStream());
            return properties;
          }
        };
  }

  private static final Map<Charset, ResourceLoader<Properties>> charsetPropertiesLoader = new ConcurrentHashMap<>();

  public static ResourceLoader<Properties> propertiesLoader(Charset charset) {
    return charsetPropertiesLoader.computeIfAbsent(charset, (c) -> new CharsetPropertiesLoader(c));
  }

  private static class CharsetPropertiesLoader implements ResourceLoader<Properties> {

    private Charset charset;

    private CharsetPropertiesLoader(Charset charset) {
      this.charset = charset;
    }

    @Override
    public Properties load(ByteSource source) throws IOException {
      Properties properties = new Properties();
      properties.load(source.asCharSource(charset).openStream());
      return properties;
    }

  }

}

@@ -804,89 +804,18 @@
 til.
-Map;%0D%0Aimport java.util.Properties;%0D%0Aimport java.util.concurrent.ConcurrentHashMap
+Properties
 ;%0D%0A%0D
@@ -902,16 +902,22 @@
 %0Apublic 
+final 
 class Re
@@ -1859,128 +1859,8 @@
 %0D%0A%0D%0A
-  private static final Map%3CCharset, ResourceLoader%3CProperties%3E%3E charsetPropertiesLoader = new ConcurrentHashMap%3C%3E();%0D%0A%0D%0A
   pu
@@ -1946,17 +1946,21 @@
  return 
-c
+new C
 harsetPr
@@ -1977,71 +1977,16 @@
 ader
-.computeIfAbsent(charset, (c) -%3E new CharsetPropertiesLoader(c)
+(charset
 );%0D%0A
@@ -2078,24 +2078,24 @@
 rties%3E %7B%0D%0A%0D%0A
-
     private 
@@ -2090,24 +2090,30 @@
     private 
+final 
 Charset char

Add final modifier where needed Remove internal static map