Calculator Calculable
جمعه, ۱۶ آبان ۱۳۹۹، ۰۱:۲۳ ق.ظ
package ir.javacup.calc; import java.math.BigDecimal; import java.util.*; public class CalculatorProxy implements Calculable { private final Calculable calculator; private Map <String,BigDecimal> sofar=new HashMap<>(); public CalculatorProxy(Calculable calculator) { this.calculator = calculator; } @Override public BigDecimal doOperation(BigDecimal... operands) { String s=""; BigDecimal ans=new BigDecimal(0); for(BigDecimal k:operands) { s=s+","+k.toString(); } if(sofar.containsKey(s)) return sofar.get(s); else { ans=calculator.doOperation(operands); sofar.put(s, ans); return ans; } } }
۹۹/۰۸/۱۶