javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java
1.1 --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Mon Mar 25 16:47:17 2013 +0100
1.2 +++ b/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Mon Jun 09 09:39:59 2014 +0200
1.3 @@ -36,7 +36,7 @@
1.4 @Property(name = "display", type = double.class),
1.5 @Property(name = "operation", type = String.class),
1.6 @Property(name = "hover", type = boolean.class),
1.7 - @Property(name = "history", type = double.class, array = true)
1.8 + @Property(name = "history", type = HistoryImpl.class, array = true)
1.9 })
1.10 public class Calc {
1.11 static {
1.12 @@ -74,19 +74,22 @@
1.13 c.getDisplay()
1.14 );
1.15 c.setDisplay(newValue);
1.16 - if (!c.getHistory().contains(newValue)) {
1.17 - c.getHistory().add(newValue);
1.18 + if (!containsValue(c.getHistory(), newValue)) {
1.19 + History h = new History();
1.20 + h.setValue(newValue);
1.21 + h.setOperation(c.getOperation());
1.22 + c.getHistory().add(h);
1.23 }
1.24 c.setMemory(0);
1.25 }
1.26
1.27 @OnFunction
1.28 - static void recoverMemory(Calculator c, double data) {
1.29 - c.setDisplay(data);
1.30 + static void recoverMemory(Calculator c, History data) {
1.31 + c.setDisplay(data.getValue());
1.32 }
1.33
1.34 @OnFunction
1.35 - static void removeMemory(Calculator c, double data) {
1.36 + static void removeMemory(Calculator c, History data) {
1.37 c.getHistory().remove(data);
1.38 }
1.39
1.40 @@ -131,4 +134,13 @@
1.41 static boolean emptyHistory(List<?> history) {
1.42 return history.isEmpty();
1.43 }
1.44 +
1.45 + private static boolean containsValue(List<History> arr, final double newValue) {
1.46 + for (History history : arr) {
1.47 + if (history.getValue() == newValue) {
1.48 + return true;
1.49 + }
1.50 + }
1.51 + return false;
1.52 + }
1.53 }