<commit_before>package com.ritaja.xchangerate.api;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Seconds;
import org.json.JSONException;
import org.json.JSONObject;

import com.ritaja.xchangerate.util.Currency;

/**
 * Created by rsengupta on 22/08/15.
 */
public abstract class AbstractXchangeRate implements CurrencyConverter {
	private static final String PROPERTIES_FILENAME = "currencyconverter.properties";
	private static final String RATES_FILEPATH = "./src/main/resources/xchangeRates.json";

	// default refresh rate of 1 day
	protected static int REFRESHRATE_SECONDS = 86400;

	private Properties properties;
	private Currency baseCurr;
	private JSONObject ratesDocument = null;

	public AbstractXchangeRate(Currency baseCurrency)
			throws XchangeRateException {
		InputStream inputStream = AbstractXchangeRate.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
		this.properties = new Properties();
		try {
			this.properties.load(inputStream);
			inputStream.close();
		} catch (IOException e) {
			throw new XchangeRateException(e);
		}
		this.baseCurr = baseCurrency;
	}

	/**
	 * saves the exchange rates in a stored resource file
	 *
	 * @param exchangeRates JSONObject of exchange rates from the reply
	 * @throws XchangeRateException
	 */
	protected void saveRates(JSONObject exchangeRates) throws XchangeRateException {
		try {
			FileWriter file = new FileWriter(RATES_FILEPATH);
			file.write(exchangeRates.toString());
			file.flush();
			file.close();
		} catch (IOException e) {
			throw new XchangeRateException(e);
		}
	}

	/**
	 * Parses the exchange rates from the stored resource file
	 * and stores them as a JSONObject
	 *
	 * @throws XchangeRateException
	 */
	private void retrieveRates() throws XchangeRateException {
		// parse the JSON string from the resource file
		String jsonData = "";
		BufferedReader br = null;
		try {
			String line;
			br = new BufferedReader(new FileReader(RATES_FILEPATH));
			while ((line = br.readLine()) != null) {
				jsonData += line + "\n";
			}
		} catch (IOException e) {
			throw new XchangeRateException(e);
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		// covert the parsed string to a JSON object
		try {
			ratesDocument = new JSONObject(jsonData);
		} catch (JSONException e) {
			throw new XchangeRateException(e);
		}
	}

	protected JSONObject getRates() {
		return this.ratesDocument;
	}

	/**
	 * check if this resource file exists
	 *
	 * @return boolean truth value
	 */
	private boolean resourceExists() {
		File f = new File(RATES_FILEPATH);
		if (f.exists() && !f.isDirectory()) {
			return true;
		}
		return false;
	}

	/**
	 * checks if the rates have expired judging from the timestamp of
	 * the stored exchange rate resource file
	 *
	 * @return boolean truth value
	 * @throws XchangeRateException
	 */
	protected boolean checkRatesUsable() throws XchangeRateException {
		if (resourceExists() && ratesDocument == null) {
			retrieveRates();
		} else if (!resourceExists()) {
			return false;
		}
		try {
			DateTime timestamp = new DateTime(Long.parseLong(ratesDocument.get("timestamp").toString(), 10) * 1000);
			DateTime now = new DateTime();
			Days days = Days.daysBetween(timestamp, now);
			if (days.toStandardSeconds().isLessThan(Seconds.seconds(REFRESHRATE_SECONDS))) {
				return false;
			}
		} catch (JSONException e) {
			throw new XchangeRateException(e);
		}

		return true;
	}

	protected Properties getProperties() {
		return this.properties;
	}

	protected Currency getBaseCurrency() {
		return this.baseCurr;
	}
}<commit_msg>removed usnused property file ref<commit_after>package com.ritaja.xchangerate.api;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Seconds;
import org.json.JSONException;
import org.json.JSONObject;

import com.ritaja.xchangerate.util.Currency;

/**
 * Created by rsengupta on 22/08/15.
 */
public abstract class AbstractXchangeRate implements CurrencyConverter {
	private static final String RATES_FILEPATH = "./src/main/resources/xchangeRates.json";

	// default refresh rate of 1 day
	protected static int REFRESHRATE_SECONDS = 86400;

	private Currency baseCurr;
	private JSONObject ratesDocument = null;

	public AbstractXchangeRate(Currency baseCurrency) {
		this.baseCurr = baseCurrency;
	}

	/**
	 * saves the exchange rates in a stored resource file
	 *
	 * @param exchangeRates JSONObject of exchange rates from the reply
	 * @throws XchangeRateException
	 */
	protected void saveRates(JSONObject exchangeRates) throws XchangeRateException {
		try {
			FileWriter file = new FileWriter(RATES_FILEPATH);
			file.write(exchangeRates.toString());
			file.flush();
			file.close();
		} catch (IOException e) {
			throw new XchangeRateException(e);
		}
	}

	/**
	 * Parses the exchange rates from the stored resource file
	 * and stores them as a JSONObject
	 *
	 * @throws XchangeRateException
	 */
	private void retrieveRates() throws XchangeRateException {
		// parse the JSON string from the resource file
		String jsonData = "";
		BufferedReader br = null;
		try {
			String line;
			br = new BufferedReader(new FileReader(RATES_FILEPATH));
			while ((line = br.readLine()) != null) {
				jsonData += line + "\n";
			}
		} catch (IOException e) {
			throw new XchangeRateException(e);
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		// covert the parsed string to a JSON object
		try {
			ratesDocument = new JSONObject(jsonData);
		} catch (JSONException e) {
			throw new XchangeRateException(e);
		}
	}

	protected JSONObject getRates() {
		return this.ratesDocument;
	}

	/**
	 * check if this resource file exists
	 *
	 * @return boolean truth value
	 */
	private boolean resourceExists() {
		File f = new File(RATES_FILEPATH);
		if (f.exists() && !f.isDirectory()) {
			return true;
		}
		return false;
	}

	/**
	 * checks if the rates have expired judging from the timestamp of
	 * the stored exchange rate resource file
	 *
	 * @return boolean truth value
	 * @throws XchangeRateException
	 */
	protected boolean checkRatesUsable() throws XchangeRateException {
		if (resourceExists() && ratesDocument == null) {
			retrieveRates();
		} else if (!resourceExists()) {
			return false;
		}
		try {
			DateTime timestamp = new DateTime(Long.parseLong(ratesDocument.get("timestamp").toString(), 10) * 1000);
			DateTime now = new DateTime();
			Days days = Days.daysBetween(timestamp, now);
			if (days.toStandardSeconds().isLessThan(Seconds.seconds(REFRESHRATE_SECONDS))) {
				return false;
			}
		} catch (JSONException e) {
			throw new XchangeRateException(e);
		}

		return true;
	}

	protected Currency getBaseCurrency() {
		return this.baseCurr;
	}
}
{'fraction_non_alphanumeric': 0.10362116991643454, 'fraction_numerical': 0.005013927576601671, 'mean_word_length': 3.888359428182437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6987422', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2148, 'n_words': 611}