package com.andela.currencycalculator.calculatorbrain;

import android.content.Context;

import com.andela.currencycalculator.model.currency.Currency;

import java.util.ArrayList;
import java.util.Queue;

/**
 * Created by Spykins on 26/02/2016.
 */
public class CalculatorManager {

    private ArrayList<String> currencyInput;
    CurrencyConverter currencyConverter;

    public CalculatorManager(ArrayList<Currency> currencies){
        currencyConverter = new CurrencyConverter();
        currencyConverter.setAllCurrencyInDb(currencies);
        currencyInput = new ArrayList<>();
    }

    public String exchangeFromCurrencyTo(String convertFrom, String convertTo, String amount){
        return currencyConverter.exchangeFromCurrencyTo(convertFrom,convertTo,amount);
    }

    public boolean isOperator(){
        String lastInputValue = currencyInput.get(currencyInput.size()-1);
        boolean flag = lastInputValue == "+" || lastInputValue == "-" || lastInputValue == "X"
                || lastInputValue == "/";
        return flag;
    }




}

@@ -53,41 +53,8 @@
 n;%0A%0A
-import android.content.Context;%0A%0A
 impo
@@ -143,32 +143,8 @@
 ist;
-%0Aimport java.util.Queue;
 %0A%0A/*
@@ -236,144 +236,263 @@
 ate 
-ArrayList%3CString%3E currencyInput;%0A    CurrencyConverter currencyConverter;%0A%0A    public CalculatorManager(ArrayList%3CCurrency%3E currencies)%7B
+CurrencyConverter currencyConverter;%0A    private CalculatorBrain calculatorFunction;%0A    private boolean isCurrencyMode;%0A%0A%0A    public CalculatorManager(ArrayList%3CCurrency%3E currencies, boolean isCurrencyMode) %7B%0A        this.isCurrencyMode = isCurrencyMode;
 %0A   
@@ -603,51 +603,8 @@
 s);%0A
-        currencyInput = new ArrayList%3C%3E();%0A
     
@@ -699,16 +699,17 @@
  amount)
+ 
 %7B%0A      
@@ -770,16 +770,17 @@
 ertFrom,
+ 
 convertT
@@ -781,16 +781,17 @@
 nvertTo,
+ 
 amount);
@@ -806,35 +806,314 @@
     
-public boolean isOperator()
+/*%0A        This checks the state of the UI when calling the addInputArray%0A        i.e Calculator or Currency Mode...%0A     */%0A    public void addInputIntoArray(String inputNumber) %7B%0A        if (isCurrencyMode) %7B%0A            ((CurrencyMode) calculatorFunction).addInputIntoArray(inputNumber);%0A        %7D else 
 %7B%0A  
@@ -1122,240 +1122,881 @@
     
-String lastInputValue = currencyInput.get(currencyInput.size()-1);%0A        boolean flag = lastInputValue == %22+%22 %7C%7C lastInputValue == %22-%22 %7C%7C lastInputValue == %22X%22%0A                %7C%7C lastInputValue == %22/%22;%0A        return flag;%0A    %7D%0A%0A
+    ((CalculatorMode) calculatorFunction).addInputIntoArray(inputNumber);%0A%0A        %7D%0A    %7D%0A%0A    public void reInitializeArray() %7B%0A        calculatorFunction.reInitializeArray();%0A    %7D%0A%0A    public String performOperation(String outputCurrency) %7B%0A        if (isCurrencyMode) %7B%0A            return ((CurrencyMode) calculatorFunction).getResult(outputCurrency);%0A        %7D%0A        return ((CalculatorMode) calculatorFunction).getResult(outputCurrency);%0A%0A    %7D%0A%0A    public void onPressedOfFunctionKey(String inputNumber) %7B%0A        calculatorFunction.onPressedOfFunctionKey(inputNumber);%0A    %7D%0A%0A    public void switchMode(Boolean isCurrencyMode) %7B%0A        this.isCurrencyMode = isCurrencyMode;%0A        if (isCurrencyMode) %7B%0A            calculatorFunction = new CurrencyMode(currencyConverter);%0A        %7D else %7B%0A            calculatorFunction = new CalculatorMode();%0A        %7D%0A    %7D
 %0A%0A%0A%7D

Reimplement Calculator Manager to use the concrete classes of calculator brain to switch between currency and calculator mode