// Path: app/src/main/java/dynoapps/exchange_rates/data/RatesHolder.java
// public class RatesHolder {
// 
//     private static final int MAX_RATES_COUNT = 10;
// 
//     private static RatesHolder instance;
//     private SparseArray<List<RatesEvent>> rateEventsSparse;
// 
//     public static RatesHolder getInstance() {
//         if (instance == null)
//             instance = new RatesHolder();
//         return instance;
//     }
// 
//     public RatesEvent getLatestEvent(int source_type) {
//         if (rateEventsSparse != null && rateEventsSparse.get(source_type, null) != null) {
//             List<RatesEvent> events = rateEventsSparse.get(source_type);
//             return events.get(events.size() - 1);
//         }
//         return null;
//     }
// 
//     public <T extends BaseRate> void addRate(List<T> rates, long fetchTime, int type) {
//         if (rateEventsSparse == null) {
//             rateEventsSparse = new SparseArray<>();
//         }
//         RatesEvent ratesEvent = new RatesEvent<>(rates, type, fetchTime);
//         List<RatesEvent> ratesEvents = rateEventsSparse.get(type);
//         if (ratesEvents == null) ratesEvents = new ArrayList<>();
//         ratesEvents.add(ratesEvent);
//         if (ratesEvents.size() > MAX_RATES_COUNT) {
//             ratesEvents.remove(0);
//         }
//         rateEventsSparse.put(type, ratesEvents);
//     }
// 
//     public <T extends BaseRate> void addRate(List<T> rates, int type) {
//         if (rateEventsSparse == null) {
//             rateEventsSparse = new SparseArray<>();
//         }
//         RatesEvent ratesEvent = new RatesEvent<>(rates, type, System.currentTimeMillis());
//         List<RatesEvent> ratesEvents = rateEventsSparse.get(type);
//         if (ratesEvents == null) ratesEvents = new ArrayList<>();
//         ratesEvents.add(ratesEvent);
//         rateEventsSparse.put(type, ratesEvents);
//     }
// }
// 
// 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/BloombergRate.java
// public class BloombergRate extends AvgRate {
// 
//     @Override
//     public void toRateType() {
//         if (TextUtils.isEmpty(type)) rateType = UNKNOWN;
//         int rateType = UNKNOWN;
//         switch (type) {
//             case "USDTRY Curncy":
//                 rateType = USD;
//                 break;
//             case "EURTRY Curncy":
//                 rateType = EUR;
//                 break;
//             case "EURUSD Curncy":
//                 rateType = EUR_USD;
//                 break;
//             case "XAU Curncy":
//                 rateType = ONS;
//                 break;
//         }
//         this.rateType = rateType;
//     }
// 
//     @Override
//     public void setRealValues() {
//         if (rateType == UNKNOWN) return;
//         avg_val = avg_val.replace(".", "").replace(',', '.');
//         val_real_avg = Float.parseFloat(avg_val);
//     }
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/EnparaRate.java
// public class EnparaRate extends BuySellRate {
// 
//     @Override
//     public void toRateType() {
//         int rateType = UNKNOWN;
//         String plain_type = type.replace("\n", "");
//         plain_type = plain_type.toLowerCase();
//         if (plain_type.contains("parite")) {
//             rateType = EUR_USD;
//         } else if (plain_type.contains("usd")) {
//             rateType = USD;
//         } else if (plain_type.contains("eur")) {
//             rateType = EUR;
//         } else if (plain_type.contains("altın (gram)")) {
//             rateType = ONS_TRY;
//         }
//         this.rateType = rateType;
//     }
// 
//     @Override
//     public void setRealValues() {
//         String val = valueSell.replace(" TL", "").replace(",", ".").trim();
//         valueSellReal = Float.valueOf(val);
// 
//         val = valueBuy.replace(" TL", "").replace(",", ".").trim();
//         valueBuyReal = Float.valueOf(val);
//     }
// }


import android.provider.Telephony;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import dynoapps.exchange_rates.data.RatesHolder;
import dynoapps.exchange_rates.model.rates.BaseRate;
import dynoapps.exchange_rates.model.rates.BloombergRate;
import dynoapps.exchange_rates.model.rates.EnparaRate;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
package dynoapps.exchange_rates.converters;





public class BloombergConverter implements Converter<ResponseBody, List<BaseRate>> {

    private static final BloombergConverter INSTANCE = new BloombergConverter();
    private static final String HOST = "https://www.bloomberght.com";

    private BloombergConverter() {
    }


    @Override
    public List<BaseRate> convert(@NonNull ResponseBody value)  throws IOException {
        ArrayList<BaseRate> rates = new ArrayList<>();
        String responseBody = value.string();

        final Elements shotElements = Jsoup.parse(responseBody, HOST).getElementsByClass("data-info");
        for (Element element : shotElements) {
            BaseRate rate = parseRate(element);
            rates.add(rate);
        }
        return rates;
    }


// Path: app/src/main/java/dynoapps/exchange_rates/data/RatesHolder.java
// public class RatesHolder {
// 
//     private static final int MAX_RATES_COUNT = 10;
// 
//     private static RatesHolder instance;
//     private SparseArray<List<RatesEvent>> rateEventsSparse;
// 
//     public static RatesHolder getInstance() {
//         if (instance == null)
//             instance = new RatesHolder();
//         return instance;
//     }
// 
//     public RatesEvent getLatestEvent(int source_type) {
//         if (rateEventsSparse != null && rateEventsSparse.get(source_type, null) != null) {
//             List<RatesEvent> events = rateEventsSparse.get(source_type);
//             return events.get(events.size() - 1);
//         }
//         return null;
//     }
// 
//     public <T extends BaseRate> void addRate(List<T> rates, long fetchTime, int type) {
//         if (rateEventsSparse == null) {
//             rateEventsSparse = new SparseArray<>();
//         }
//         RatesEvent ratesEvent = new RatesEvent<>(rates, type, fetchTime);
//         List<RatesEvent> ratesEvents = rateEventsSparse.get(type);
//         if (ratesEvents == null) ratesEvents = new ArrayList<>();
//         ratesEvents.add(ratesEvent);
//         if (ratesEvents.size() > MAX_RATES_COUNT) {
//             ratesEvents.remove(0);
//         }
//         rateEventsSparse.put(type, ratesEvents);
//     }
// 
//     public <T extends BaseRate> void addRate(List<T> rates, int type) {
//         if (rateEventsSparse == null) {
//             rateEventsSparse = new SparseArray<>();
//         }
//         RatesEvent ratesEvent = new RatesEvent<>(rates, type, System.currentTimeMillis());
//         List<RatesEvent> ratesEvents = rateEventsSparse.get(type);
//         if (ratesEvents == null) ratesEvents = new ArrayList<>();
//         ratesEvents.add(ratesEvent);
//         rateEventsSparse.put(type, ratesEvents);
//     }
// }
// 
// 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/BloombergRate.java
// public class BloombergRate extends AvgRate {
// 
//     @Override
//     public void toRateType() {
//         if (TextUtils.isEmpty(type)) rateType = UNKNOWN;
//         int rateType = UNKNOWN;
//         switch (type) {
//             case "USDTRY Curncy":
//                 rateType = USD;
//                 break;
//             case "EURTRY Curncy":
//                 rateType = EUR;
//                 break;
//             case "EURUSD Curncy":
//                 rateType = EUR_USD;
//                 break;
//             case "XAU Curncy":
//                 rateType = ONS;
//                 break;
//         }
//         this.rateType = rateType;
//     }
// 
//     @Override
//     public void setRealValues() {
//         if (rateType == UNKNOWN) return;
//         avg_val = avg_val.replace(".", "").replace(',', '.');
//         val_real_avg = Float.parseFloat(avg_val);
//     }
// }
// 
// Path: app/src/main/java/dynoapps/exchange_rates/model/rates/EnparaRate.java
// public class EnparaRate extends BuySellRate {
// 
//     @Override
//     public void toRateType() {
//         int rateType = UNKNOWN;
//         String plain_type = type.replace("\n", "");
//         plain_type = plain_type.toLowerCase();
//         if (plain_type.contains("parite")) {
//             rateType = EUR_USD;
//         } else if (plain_type.contains("usd")) {
//             rateType = USD;
//         } else if (plain_type.contains("eur")) {
//             rateType = EUR;
//         } else if (plain_type.contains("altın (gram)")) {
//             rateType = ONS_TRY;
//         }
//         this.rateType = rateType;
//     }
// 
//     @Override
//     public void setRealValues() {
//         String val = valueSell.replace(" TL", "").replace(",", ".").trim();
//         valueSellReal = Float.valueOf(val);
// 
//         val = valueBuy.replace(" TL", "").replace(",", ".").trim();
//         valueBuyReal = Float.valueOf(val);
//     }
// }


// Path: app/src/main/java/dynoapps/exchange_rates/converters/BloombergConverter.java
import android.provider.Telephony;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import dynoapps.exchange_rates.data.RatesHolder;
import dynoapps.exchange_rates.model.rates.BaseRate;
import dynoapps.exchange_rates.model.rates.BloombergRate;
import dynoapps.exchange_rates.model.rates.EnparaRate;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;

package dynoapps.exchange_rates.converters;





public class BloombergConverter implements Converter<ResponseBody, List<BaseRate>> {

    private static final BloombergConverter INSTANCE = new BloombergConverter();
    private static final String HOST = "https://www.bloomberght.com";

    private BloombergConverter() {
    }


    @Override
    public List<BaseRate> convert(@NonNull ResponseBody value)  throws IOException {
        ArrayList<BaseRate> rates = new ArrayList<>();
        String responseBody = value.string();

        final Elements shotElements = Jsoup.parse(responseBody, HOST).getElementsByClass("data-info");
        for (Element element : shotElements) {
            BaseRate rate = parseRate(element);
            rates.add(rate);
        }
        return rates;
    }


    private BloombergRate parseRate(Element element) {