// Path: cfg4j-core/src/main/java/org/cfg4j/source/ConfigurationSource.java
// public interface ConfigurationSource {
// 
//   /**
//    * Get configuration set for a given {@code environment} from this source in a form of {@link Properties}.
//    * Provided {@link Environment} will be used to determine which environment to use.
//    *
//    * @param environment environment to use
//    * @return configuration set for {@code environment}
//    * @throws MissingEnvironmentException when requested environment couldn't be found
//    * @throws IllegalStateException       when unable to fetch configuration
//    */
//   Properties getConfiguration(Environment environment);
// 
//   /**
//    * Initialize this source. This method has to be called before any other method of this instance.
//    *
//    * @throws IllegalStateException        when source was improperly configured
//    * @throws SourceCommunicationException when unable to communicate with source
//    */
//   void init();
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/SourceCommunicationException.java
// public class SourceCommunicationException extends RuntimeException {
// 
//   /**
//    * Indicates problem when communicating with {@link ConfigurationSource}.
//    *
//    * @param msg the detail message
//    * @param e   the cause
//    */
//   public SourceCommunicationException(String msg, Exception e) {
//     super("Unable to communicate with configuration source: " + msg, e);
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/Environment.java
// public interface Environment {
// 
//   /**
//    * Name of the environment. Should not be null.
//    *
//    * @return environment name. Not null.
//    */
//   String getName();
// 
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/MissingEnvironmentException.java
// public class MissingEnvironmentException extends RuntimeException {
// 
//   private static final String MISSING_ENV_MSG = "Missing environment: ";
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    */
//   public MissingEnvironmentException(String envName) {
//     super(MISSING_ENV_MSG + envName);
//   }
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    * @param cause root cause
//    */
//   public MissingEnvironmentException(String envName, Throwable cause) {
//     super(MISSING_ENV_MSG + envName, cause);
//   }
// }


import static java.util.Objects.requireNonNull;
import org.cfg4j.source.ConfigurationSource;
import org.cfg4j.source.SourceCommunicationException;
import org.cfg4j.source.context.environment.Environment;
import org.cfg4j.source.context.environment.MissingEnvironmentException;
import java.util.Arrays;
import java.util.Properties;
  @Override
  public Properties getConfiguration(Environment environment) {

    boolean allMissEnvironment = true;

    for (ConfigurationSource source : sources) {
      try {
        return source.getConfiguration(environment);
      } catch (MissingEnvironmentException e) {
        // NOP
      } catch (IllegalStateException e) {
        allMissEnvironment = false;
      }
    }

    if (allMissEnvironment) {
      throw new MissingEnvironmentException(environment.getName());
    }

    throw new IllegalStateException();
  }

  @Override
  public void init() {
    boolean atLeastOneSuccess = false;

    for (ConfigurationSource source : sources) {
      try {
        source.init();
        atLeastOneSuccess = true;
// Path: cfg4j-core/src/main/java/org/cfg4j/source/ConfigurationSource.java
// public interface ConfigurationSource {
// 
//   /**
//    * Get configuration set for a given {@code environment} from this source in a form of {@link Properties}.
//    * Provided {@link Environment} will be used to determine which environment to use.
//    *
//    * @param environment environment to use
//    * @return configuration set for {@code environment}
//    * @throws MissingEnvironmentException when requested environment couldn't be found
//    * @throws IllegalStateException       when unable to fetch configuration
//    */
//   Properties getConfiguration(Environment environment);
// 
//   /**
//    * Initialize this source. This method has to be called before any other method of this instance.
//    *
//    * @throws IllegalStateException        when source was improperly configured
//    * @throws SourceCommunicationException when unable to communicate with source
//    */
//   void init();
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/SourceCommunicationException.java
// public class SourceCommunicationException extends RuntimeException {
// 
//   /**
//    * Indicates problem when communicating with {@link ConfigurationSource}.
//    *
//    * @param msg the detail message
//    * @param e   the cause
//    */
//   public SourceCommunicationException(String msg, Exception e) {
//     super("Unable to communicate with configuration source: " + msg, e);
//   }
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/Environment.java
// public interface Environment {
// 
//   /**
//    * Name of the environment. Should not be null.
//    *
//    * @return environment name. Not null.
//    */
//   String getName();
// 
// }
// 
// Path: cfg4j-core/src/main/java/org/cfg4j/source/context/environment/MissingEnvironmentException.java
// public class MissingEnvironmentException extends RuntimeException {
// 
//   private static final String MISSING_ENV_MSG = "Missing environment: ";
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    */
//   public MissingEnvironmentException(String envName) {
//     super(MISSING_ENV_MSG + envName);
//   }
// 
//   /**
//    * Environment named {@code envName} is missing.
//    *
//    * @param envName environment name
//    * @param cause root cause
//    */
//   public MissingEnvironmentException(String envName, Throwable cause) {
//     super(MISSING_ENV_MSG + envName, cause);
//   }
// }


// Path: cfg4j-core/src/main/java/org/cfg4j/source/compose/FallbackConfigurationSource.java
import static java.util.Objects.requireNonNull;
import org.cfg4j.source.ConfigurationSource;
import org.cfg4j.source.SourceCommunicationException;
import org.cfg4j.source.context.environment.Environment;
import org.cfg4j.source.context.environment.MissingEnvironmentException;
import java.util.Arrays;
import java.util.Properties;

  @Override
  public Properties getConfiguration(Environment environment) {

    boolean allMissEnvironment = true;

    for (ConfigurationSource source : sources) {
      try {
        return source.getConfiguration(environment);
      } catch (MissingEnvironmentException e) {
        // NOP
      } catch (IllegalStateException e) {
        allMissEnvironment = false;
      }
    }

    if (allMissEnvironment) {
      throw new MissingEnvironmentException(environment.getName());
    }

    throw new IllegalStateException();
  }

  @Override
  public void init() {
    boolean atLeastOneSuccess = false;

    for (ConfigurationSource source : sources) {
      try {
        source.init();
        atLeastOneSuccess = true;
      } catch (IllegalStateException | SourceCommunicationException e) {