// Path: library/src/main/java/com/franmontiel/localechanger/matcher/MatchingAlgorithm.java
// public interface MatchingAlgorithm {
// 
//     /**
//      * Method that implements the algorithm to find two matching Locales between a list of supported and system Locales.
//      *
//      * @param supportedLocales a list of your app supported locales
//      * @param systemLocales    a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findDefaultMatch(List<Locale> supportedLocales, List<Locale> systemLocales);
// 
//     /**
//      * Method that implements the algorithm to find a matching Locale between the supported Locale and system Locales.
//      *
//      * @param supportedLocale one of your app supported locales
//      * @param systemLocales   a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findMatch(Locale supportedLocale, List<Locale> systemLocales);
// }
// 
// Path: library/src/main/java/com/franmontiel/localechanger/matcher/MatchingLocales.java
// public final class MatchingLocales {
//     private Locale supportedLocale;
//     private Locale systemLocale;
// 
//     public MatchingLocales(Locale supportedLocale, Locale systemLocale) {
//         this.supportedLocale = supportedLocale;
//         this.systemLocale = systemLocale;
//     }
// 
//     public Locale getSupportedLocale() {
//         return supportedLocale;
//     }
// 
//     public Locale getSystemLocale() {
//         return systemLocale;
//     }
// 
//     public Locale getPreferredLocale(LocalePreference preference) {
//         return preference.equals(LocalePreference.PreferSupportedLocale) ?
//                 supportedLocale :
//                 systemLocale;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         MatchingLocales that = (MatchingLocales) o;
// 
//         return supportedLocale.equals(that.supportedLocale)
//                 && systemLocale.equals(that.systemLocale);
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = supportedLocale.hashCode();
//         result = 31 * result + systemLocale.hashCode();
//         return result;
//     }
// 
//     @Override
//     public String toString() {
//         return supportedLocale.toString() + ", " + systemLocale.toString();
//     }
// }


import com.franmontiel.localechanger.matcher.MatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingLocales;
import java.util.List;
import java.util.Locale;
/*
 * Copyright (c)  2017  Francisco José Montiel Navarro.
 *
 * 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 com.franmontiel.localechanger;



/**
 * Class that uses a {@link MatchingAlgorithm} and a {@link LocalePreference} to resolve a Locale to be set.
 */
class LocaleResolver {

    private List<Locale> supportedLocales;
    private List<Locale> systemLocales;
    private MatchingAlgorithm matchingAlgorithm;
    private LocalePreference preference;

    LocaleResolver(List<Locale> supportedLocales,
                   List<Locale> systemLocales,
                   MatchingAlgorithm matchingAlgorithm,
                   LocalePreference preference) {

        this.supportedLocales = supportedLocales;
        this.systemLocales = systemLocales;
        this.matchingAlgorithm = matchingAlgorithm;
        this.preference = preference;
    }

    DefaultResolvedLocalePair resolveDefault() {

        MatchingLocales matchingPair = matchingAlgorithm.findDefaultMatch(supportedLocales, systemLocales);

        return matchingPair != null ?
                new DefaultResolvedLocalePair(matchingPair.getSupportedLocale(), matchingPair.getPreferredLocale(preference)) :
                new DefaultResolvedLocalePair(supportedLocales.get(0), supportedLocales.get(0));
    }

    Locale resolve(Locale supportedLocale) throws UnsupportedLocaleException {
        if (!supportedLocales.contains(supportedLocale))
            throw new UnsupportedLocaleException("The Locale you are trying to load is not in the supported list provided on library initialization");

// Path: library/src/main/java/com/franmontiel/localechanger/matcher/MatchingAlgorithm.java
// public interface MatchingAlgorithm {
// 
//     /**
//      * Method that implements the algorithm to find two matching Locales between a list of supported and system Locales.
//      *
//      * @param supportedLocales a list of your app supported locales
//      * @param systemLocales    a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findDefaultMatch(List<Locale> supportedLocales, List<Locale> systemLocales);
// 
//     /**
//      * Method that implements the algorithm to find a matching Locale between the supported Locale and system Locales.
//      *
//      * @param supportedLocale one of your app supported locales
//      * @param systemLocales   a list of the configured  locales in system preferences
//      * @return a {@link MatchingLocales} containing the pair of matching locales. If no match is found null is returned
//      */
//     MatchingLocales findMatch(Locale supportedLocale, List<Locale> systemLocales);
// }
// 
// Path: library/src/main/java/com/franmontiel/localechanger/matcher/MatchingLocales.java
// public final class MatchingLocales {
//     private Locale supportedLocale;
//     private Locale systemLocale;
// 
//     public MatchingLocales(Locale supportedLocale, Locale systemLocale) {
//         this.supportedLocale = supportedLocale;
//         this.systemLocale = systemLocale;
//     }
// 
//     public Locale getSupportedLocale() {
//         return supportedLocale;
//     }
// 
//     public Locale getSystemLocale() {
//         return systemLocale;
//     }
// 
//     public Locale getPreferredLocale(LocalePreference preference) {
//         return preference.equals(LocalePreference.PreferSupportedLocale) ?
//                 supportedLocale :
//                 systemLocale;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         MatchingLocales that = (MatchingLocales) o;
// 
//         return supportedLocale.equals(that.supportedLocale)
//                 && systemLocale.equals(that.systemLocale);
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = supportedLocale.hashCode();
//         result = 31 * result + systemLocale.hashCode();
//         return result;
//     }
// 
//     @Override
//     public String toString() {
//         return supportedLocale.toString() + ", " + systemLocale.toString();
//     }
// }


// Path: library/src/main/java/com/franmontiel/localechanger/LocaleResolver.java
import com.franmontiel.localechanger.matcher.MatchingAlgorithm;
import com.franmontiel.localechanger.matcher.MatchingLocales;
import java.util.List;
import java.util.Locale;

/*
 * Copyright (c)  2017  Francisco José Montiel Navarro.
 *
 * 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 com.franmontiel.localechanger;



/**
 * Class that uses a {@link MatchingAlgorithm} and a {@link LocalePreference} to resolve a Locale to be set.
 */
class LocaleResolver {

    private List<Locale> supportedLocales;
    private List<Locale> systemLocales;
    private MatchingAlgorithm matchingAlgorithm;
    private LocalePreference preference;

    LocaleResolver(List<Locale> supportedLocales,
                   List<Locale> systemLocales,
                   MatchingAlgorithm matchingAlgorithm,
                   LocalePreference preference) {

        this.supportedLocales = supportedLocales;
        this.systemLocales = systemLocales;
        this.matchingAlgorithm = matchingAlgorithm;
        this.preference = preference;
    }

    DefaultResolvedLocalePair resolveDefault() {

        MatchingLocales matchingPair = matchingAlgorithm.findDefaultMatch(supportedLocales, systemLocales);

        return matchingPair != null ?
                new DefaultResolvedLocalePair(matchingPair.getSupportedLocale(), matchingPair.getPreferredLocale(preference)) :
                new DefaultResolvedLocalePair(supportedLocales.get(0), supportedLocales.get(0));
    }

    Locale resolve(Locale supportedLocale) throws UnsupportedLocaleException {
        if (!supportedLocales.contains(supportedLocale))
            throw new UnsupportedLocaleException("The Locale you are trying to load is not in the supported list provided on library initialization");

        MatchingLocales matchingPair = null;