Show
Ignore:
Timestamp:
11/06/09 20:12:35 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1257538355 +0000
git-parent:

[853067a71a061cf7ab27ee767ecdea65d9ddc9cf]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1257538355 +0000
Message:

remove BigDecimal? here -- performance optimization

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/java/com/omniti/reconnoiter/esper/CounterView.java

    rc75a210 r2b223ab  
    99 **************************************************************************************/ 
    1010package com.omniti.reconnoiter.esper; 
    11  
    12 import java.math.BigDecimal; 
    1311 
    1412import com.omniti.reconnoiter.esper.DeriveView; 
     
    3028        return new CounterView(statementContext, this.expressionX, this.expressionY); 
    3129    } 
    32     protected BigDecimal[] subtract(BigDecimal[] a, BigDecimal[] b) 
     30    protected NoitDerivePoint subtract(NoitDerivePoint a, NoitDerivePoint b) 
    3331    { 
    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; 
     32        NoitDerivePoint v = super.subtract(a,b); 
     33        if(v.Ylong < 0 || v.Ydouble < 0.0) v.X = 0; 
    3834        return v; 
    3935    } 
  • src/java/com/omniti/reconnoiter/esper/DeriveView.java

    rc75a210 r2b223ab  
    2222import java.util.Iterator; 
    2323import java.util.Arrays; 
    24 import java.math.BigDecimal; 
    25 import java.math.MathContext; 
    2624 
    2725/** 
     
    3331    protected ExprNode expressionX; 
    3432    protected ExprNode expressionY; 
    35     private boolean isDouble; 
     33    private boolean isDouble; 
    3634    private WeightedValueBean lastWVBean; 
    37     private BigDecimal[] lastpoint; 
     35    private NoitDerivePoint lastpoint; 
    3836 
    3937    /** 
     
    8684            for ( EventBean pointb : newData ) { 
    8785                EventBean eventsPerStream[] = { pointb }; 
    88                 BigDecimal X = new BigDecimal(((Number) expressionX.evaluate(eventsPerStream, true, statementContext)).toString()); 
    89                 BigDecimal Y
     86                NoitDerivePoint point = new NoitDerivePoint(); 
     87                point.X = ((Number) expressionX.evaluate(eventsPerStream, true, statementContext)).longValue()
    9088                if(isDouble) 
    91                   Y = new BigDecimal(((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).doubleValue()); 
     89                  point.Ydouble = ((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).doubleValue(); 
    9290                else 
    93                   Y = new BigDecimal(((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).toString()); 
     91                  point.Ylong = ((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).longValue(); 
    9492 
    95                 BigDecimal[] point = new BigDecimal[] {X,Y}; 
    9693                if (lastpoint != null) { 
    9794                    try { 
    98                         BigDecimal[] sub = subtract(point,lastpoint); 
    99                         lastWVBean = new WeightedValueBean(sub[0], sub[1].divide(sub[0],MathContext.DECIMAL128)); 
     95                        NoitDerivePoint sub = subtract(point,lastpoint); 
     96                        lastWVBean = new WeightedValueBean(sub.X, sub.ror(isDouble)); 
    10097                        EventBean eb = statementContext.getEventAdapterService().adapterForBean(lastWVBean); 
    10198                        derivedNew[i++] = eb; 
     
    116113    } 
    117114 
    118     protected BigDecimal[] subtract(BigDecimal[] a, BigDecimal[] b) 
     115    protected NoitDerivePoint subtract(NoitDerivePoint a, NoitDerivePoint b) 
    119116    { 
    120         BigDecimal[] v = new BigDecimal[2]; 
    121         v[0] = a[0].subtract(b[0]); 
    122         v[1] = a[1].subtract(b[1]); 
     117        NoitDerivePoint v = new NoitDerivePoint(); 
     118        v.X = a.X - b.X; 
     119        v.Ylong = a.Ylong - b.Ylong; 
     120        v.Ydouble = a.Ydouble - b.Ydouble; 
    123121        return v; 
    124122    } 
     
    131129    public final String toString() 
    132130    { 
    133         return this.getClass().getName() + " lastpoint=" + lastpoint[0] + "," + lastpoint[1]; 
     131        return this.getClass().getName() + " lastpoint=" + lastpoint.X + "," + (isDouble ? lastpoint.Ydouble : lastpoint.Ylong); 
     132    } 
     133 
     134    protected class NoitDerivePoint { 
     135        public long X; 
     136        public long Ylong; 
     137        public double Ydouble; 
     138        public double ror(boolean isDouble) { 
     139            if(X == 0) return Double.NaN; 
     140            if(isDouble) return (Ydouble / (double)X); 
     141            else return ((double)Ylong / (double)X); 
     142        } 
    134143    } 
    135144} 
  • src/java/com/omniti/reconnoiter/esper/WeightedValueBean.java

    rc75a210 r2b223ab  
    22 
    33import java.io.Serializable; 
    4 import java.math.BigDecimal; 
    54 
    65/** 
     
    1110public class WeightedValueBean implements Cloneable, Serializable 
    1211{ 
    13     private double weight; 
     12    private long weight; 
    1413    private double value; 
    1514    private static final long serialVersionUID = 7995123761256377184L; 
    1615 
    17     public WeightedValueBean(BigDecimal w, BigDecimal v) { 
    18         weight = (w == null) ? Double.NaN : w.doubleValue()
    19         value = (v == null) ? Double.NaN: v.doubleValue()
     16    public WeightedValueBean(long w, double v) { 
     17        weight = w
     18        value = v
    2019    } 
    2120 
    22     public double getWeight() { return weight; } 
     21    public long getWeight() { return weight; } 
    2322    public double getValue() { return value; } 
    24     public void setWeight(double w) { weight = w; } 
     23    public void setWeight(long w) { weight = w; } 
    2524    public void setValue(double v) { value = v; } 
    2625}