// Path: app/src/main/java/dynoapps/exchange_rates/App.java
// public class App extends Application {
//     private static App appInstance;
// 
//     public static App getInstance() {
//         return appInstance;
//     }
// 
//     @NonNull
//     public static Context context() {
//         return appInstance.getApplicationContext();
//     }
// 
//     public AlarmsRepository provideAlarmsRepository() {
//         return AlarmsRepository.getInstance(getApplicationContext());
//     }
// 
//     @SuppressLint("CheckResult")
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         appInstance = this;
// 
//         RxJavaPlugins.setErrorHandler(throwable -> L.e("App", throwable.getLocalizedMessage()));
//     }
// 
//     /**
//      * Enum used to identify the tracker that needs to be used for tracking.
//      * <p/>
//      * A single tracker is usually enough for most purposes. In case you do need multiple trackers,
//      * storing them all in Application object helps ensure that they are created only once per
//      * application instance.
//      */
//     public enum TrackerName {
//         APP_TRACKER, // Tracker used only in this app.
//         GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
//     }
// 
// 
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/BaseRate.java
// public abstract class BaseRate implements IConvertable, IRate {
// 
//     public String type;
// 
//     @RateDef
//     protected int rateType;
// 
//     BaseRate() {
//     }
// 
//     @Override
//     public int getRateType() {
//         return rateType;
//     }
// 
//     public String getFormatted(float val) {
//         return RateUtils.valueToUI(val, rateType);
//     }
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/IRate.java
// public interface IRate {
//     int UNKNOWN = 0;
//     int USD = 1;
//     int EUR = 2;
//     int ONS = 3;
//     int ONS_TRY = 4;
//     int EUR_USD = 5;
// 
//     @RateDef
//     int getRateType();
// 
//     float getValue(int valueType);
// 
//     @Retention(RetentionPolicy.SOURCE)
//     @IntDef({
//             UNKNOWN,
//             USD,
//             EUR,
//             ONS,
//             ONS_TRY,
//             EUR_USD
//     })
//     @interface RateDef {
//     }
// }


import android.text.TextUtils;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.List;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import dynoapps.exchange_rates.App;
import dynoapps.exchange_rates.R;
import dynoapps.exchange_rates.model.rates.BaseRate;
import dynoapps.exchange_rates.model.rates.IRate;
package dynoapps.exchange_rates.util;




/**
 * Created by erdemmac on 01/12/2016.
 */

public class RateUtils {
    private static final Formatter formatter2 = new Formatter(2, 0);
    private static final Formatter formatter5 = new Formatter(5, 2);

    public static <T extends BaseRate> T getRate(List<T> rates, @IRate.RateDef int rateType) {
        if (rates == null) return null;
        for (T rate : rates) {
            if (rate.getRateType() == rateType) {
                return rate;
            }
        }
        return null;
    }

    public static String valueToUI(Float val, @IRate.RateDef int rateType) {
        if (val == null) return "";
        String formatted = formatValue(val, rateType);
        if (rateType == IRate.EUR_USD) {
            return formatted;
        } else if (rateType == IRate.ONS) {
// Path: app/src/main/java/dynoapps/exchange_rates/App.java
// public class App extends Application {
//     private static App appInstance;
// 
//     public static App getInstance() {
//         return appInstance;
//     }
// 
//     @NonNull
//     public static Context context() {
//         return appInstance.getApplicationContext();
//     }
// 
//     public AlarmsRepository provideAlarmsRepository() {
//         return AlarmsRepository.getInstance(getApplicationContext());
//     }
// 
//     @SuppressLint("CheckResult")
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         appInstance = this;
// 
//         RxJavaPlugins.setErrorHandler(throwable -> L.e("App", throwable.getLocalizedMessage()));
//     }
// 
//     /**
//      * Enum used to identify the tracker that needs to be used for tracking.
//      * <p/>
//      * A single tracker is usually enough for most purposes. In case you do need multiple trackers,
//      * storing them all in Application object helps ensure that they are created only once per
//      * application instance.
//      */
//     public enum TrackerName {
//         APP_TRACKER, // Tracker used only in this app.
//         GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
//     }
// 
// 
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/BaseRate.java
// public abstract class BaseRate implements IConvertable, IRate {
// 
//     public String type;
// 
//     @RateDef
//     protected int rateType;
// 
//     BaseRate() {
//     }
// 
//     @Override
//     public int getRateType() {
//         return rateType;
//     }
// 
//     public String getFormatted(float val) {
//         return RateUtils.valueToUI(val, rateType);
//     }
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/IRate.java
// public interface IRate {
//     int UNKNOWN = 0;
//     int USD = 1;
//     int EUR = 2;
//     int ONS = 3;
//     int ONS_TRY = 4;
//     int EUR_USD = 5;
// 
//     @RateDef
//     int getRateType();
// 
//     float getValue(int valueType);
// 
//     @Retention(RetentionPolicy.SOURCE)
//     @IntDef({
//             UNKNOWN,
//             USD,
//             EUR,
//             ONS,
//             ONS_TRY,
//             EUR_USD
//     })
//     @interface RateDef {
//     }
// }


// Path: app/src/main/java/dynoapps/exchange_rates/util/RateUtils.java
import android.text.TextUtils;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.List;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import dynoapps.exchange_rates.App;
import dynoapps.exchange_rates.R;
import dynoapps.exchange_rates.model.rates.BaseRate;
import dynoapps.exchange_rates.model.rates.IRate;

package dynoapps.exchange_rates.util;




/**
 * Created by erdemmac on 01/12/2016.
 */

public class RateUtils {
    private static final Formatter formatter2 = new Formatter(2, 0);
    private static final Formatter formatter5 = new Formatter(5, 2);

    public static <T extends BaseRate> T getRate(List<T> rates, @IRate.RateDef int rateType) {
        if (rates == null) return null;
        for (T rate : rates) {
            if (rate.getRateType() == rateType) {
                return rate;
            }
        }
        return null;
    }

    public static String valueToUI(Float val, @IRate.RateDef int rateType) {
        if (val == null) return "";
        String formatted = formatValue(val, rateType);
        if (rateType == IRate.EUR_USD) {
            return formatted;
        } else if (rateType == IRate.ONS) {
            return App.context().getString(R.string.placeholder_dollar, formatted);