root/src/java/com/omniti/reconnoiter/esper/CounterView.java

Revision c75a2104258a9079bb6ef2dbe68c66e7102bbf16, 1.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 8 years ago)

step 2. .noit:derive and .noit:counter, refs #210

  • Property mode set to 100644
Line 
1 /**************************************************************************************
2  * Copyright (C) 2008 EsperTech, Inc. All rights reserved.                            *
3  * Copyright (C) 2009 OmniTI, Inc. All rights reserved.                               *
4  * http://esper.codehaus.org                                                          *
5  * http://www.espertech.com                                                           *
6  * ---------------------------------------------------------------------------------- *
7  * The software in this package is published under the terms of the GPL license       *
8  * a copy of which has been included with this distribution in the license.txt file.  *
9  **************************************************************************************/
10 package com.omniti.reconnoiter.esper;
11
12 import java.math.BigDecimal;
13
14 import com.omniti.reconnoiter.esper.DeriveView;
15 import com.espertech.esper.core.StatementContext;
16 import com.espertech.esper.epl.expression.ExprNode;
17 import com.espertech.esper.view.View;
18
19 /**
20  * This view is a moving window extending the specified number of elements into the past.
21  */
22 public class CounterView extends DeriveView
23 {
24     public CounterView(StatementContext statementContext, ExprNode expressionX, ExprNode expressionY)
25     {
26         super(statementContext, expressionX, expressionY);
27     }
28     public View cloneView(StatementContext statementContext)
29     {
30         return new CounterView(statementContext, this.expressionX, this.expressionY);
31     }
32     protected BigDecimal[] subtract(BigDecimal[] a, BigDecimal[] b)
33     {
34         BigDecimal[] v = new BigDecimal[2];
35         v[0] = a[0].subtract(b[0]);
36         v[1] = a[1].subtract(b[1]);
37         if(v[1].signum() < 0) v[0] = BigDecimal.ZERO;
38         return v;
39     }
40 }
Note: See TracBrowser for help on using the browser.