View Javadoc

1   /*
2    * $Id: StockTick.java 21596 2011-03-21 17:38:02Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.example.cep;
12  
13  import java.text.DecimalFormat;
14  
15  /**
16   * A stock tick event informing of a state change due to some operation;
17   * 
18   * @author etirelli
19   */
20  public class StockTick
21  {
22      private final String symbol;
23      private final double price;
24      private final long timestamp;
25      private double delta;
26      private String str;
27  
28      public StockTick(String symbol, double price, long timestamp)
29      {
30          super();
31          this.symbol = symbol;
32          this.price = price;
33          this.timestamp = timestamp;
34          this.str = createString();
35      }
36  
37      public String getSymbol()
38      {
39          return symbol;
40      }
41  
42      public double getPrice()
43      {
44          return price;
45      }
46  
47      public long getTimestamp()
48      {
49          return timestamp;
50      }
51  
52      public String toString()
53      {
54          return str;
55      }
56  
57      private String createString()
58      {
59          return symbol + " $" + price;
60      }
61  
62      public double getDelta()
63      {
64          return delta;
65      }
66  
67      public void setDelta(double delta)
68      {
69          this.delta = delta;
70          this.str = createString();
71      }
72  
73      public static String percent(double number)
74      {
75          return new DecimalFormat("0.0%").format(number);
76      }
77  }