`InterceptorCalculator.java`
`01 package trail.interceptor; 02 03 import javax.ejb.*; 04 import java.util.*; 05 import java.io.Serializable; 06 07 //TODO: Fix the client 08 @Stateful 09 @Interceptors (Tracer.class) 10 public class InterceptorCalculator implements Calculator, Serializable { 11 12 public ArrayList <Integer> starts = new ArrayList <Integer> (); 13 public ArrayList <Integer> ends = new ArrayList <Integer> (); 14 public ArrayList <Double> growthrates = new ArrayList <Double> (); 15 public ArrayList <Double> savings = new ArrayList <Double> (); 16 public ArrayList <Double> results = new ArrayList <Double> (); 17 18 private String trace; 19 20 /* 21 @PostConstruct 22 public void initialize () { 23 // System.err.println("Init is called"); 24 starts = new ArrayList <Integer> (); 25 ends = new ArrayList <Integer> (); 26 growthrates = new ArrayList <Double> (); 27 savings = new ArrayList <Double> (); 28 results = new ArrayList <Double> (); 29 } 30 */ 31 32 public double calculate (int start, int end, double growthrate, double saving) { 33 double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1); 34 double result = saving * 12. * (tmp - 1) / growthrate; 35 36 starts.add(Integer.valueOf(start)); 37 ends.add(Integer.valueOf(end)); 38 growthrates.add(Double.valueOf(growthrate)); 39 savings.add(Double.valueOf(saving)); 40 results.add(Double.valueOf(result)); 41 42 return result; 43 } 44 45 public ArrayList <Integer> getStarts () { 46 return starts; 47 } 48 49 public ArrayList <Integer> getEnds () { 50 return ends; 51 } 52 53 public ArrayList <Double> getGrowthrates () { 54 return growthrates; 55 } 56 57 public ArrayList <Double> getSavings () { 58 return savings; 59 } 60 61 public ArrayList <Double> getResults () { 62 return results; 63 } 64 65 @AroundInvoke 66 public Object limitStateSize (InvocationContext ctx) 67 throws Exception { 68 69 // Remove the earliest entry when the history 70 // list gets too long 71 if (starts.size() > 4) { 72 starts.remove (0); 73 ends.remove (0); 74 growthrates.remove (0); 75 savings.remove (0); 76 results.remove (0); 77 } 78 79 return ctx.proceed(); 80 } 81 82 public void setTrace (String s) { 83 trace = s; 84 } 85 86 public String getTrace () { 87 return trace; 88 } 89 }`