<commit_before>package io.xrates.rateprovider;

import java.util.Currency;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.lalyos.jfiglet.FigletFont;

import io.xrates.Rates;
import io.xrates.constants.RateProvider;

public abstract class AbstractRateProvider implements IRateProvider {
	private Rates rates = new Rates(); 
	private RateProvider rateProvider;
	private Logger log = LoggerFactory.getLogger(AbstractRateProvider.class.getName());
		
	public double convert(Currency from, Currency to) {
		updateRates();
		return rates.getConversion(from, to);
	}
	
	public RateProvider getRateProvider() {
		return rateProvider;
	}
	
	protected void setRateProvider(RateProvider rateProvider) {
		log.info("Instantiating following service : \n" + FigletFont.convertOneLine(rateProvider.getProviderName()));
		this.rateProvider = rateProvider;
	}
	
	public Rates getRates() {
		return rates;
	}
	
	protected abstract void updateRates();

}<commit_msg>Do not fetch rate if last fetch 5 minutes ago<commit_after>package io.xrates.rateprovider;

import java.util.Currency;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.lalyos.jfiglet.FigletFont;

import io.xrates.Rates;
import io.xrates.constants.RateProvider;

public abstract class AbstractRateProvider implements IRateProvider {
	private Rates rates = new Rates(); 
	private RateProvider rateProvider;
	private long lastUpdated = -1;
	private long stalenessTime = 300000; //Data which is stale up to 5 minutes is fine
	private Logger log = LoggerFactory.getLogger(AbstractRateProvider.class.getName());
		
	public double convert(Currency from, Currency to) {
		long currentTime = System.currentTimeMillis();
		if (currentTime - lastUpdated > stalenessTime) {
			updateRates();
			lastUpdated = currentTime;
		}
		return rates.getConversion(from, to);
	}
	
	public RateProvider getRateProvider() {
		return rateProvider;
	}
	
	protected void setRateProvider(RateProvider rateProvider) {
		log.info("Instantiating following service : \n" + FigletFont.convertOneLine(rateProvider.getProviderName()));
		this.rateProvider = rateProvider;
	}
	
	public Rates getRates() {
		return rates;
	}
	
	protected abstract void updateRates();

}
{'fraction_non_alphanumeric': 0.09029950827000446, 'fraction_numerical': 0.00581135449262405, 'mean_word_length': 5.216666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1791196', 'n_tokens_mistral': 714, 'n_tokens_neox': 655, 'n_words': 170}