private static GeoTimeSerie applyBinOp(WarpScriptBinaryOp op,String name,Map<String,String> labels,GeoTimeSerie x,GeoTimeSerie y){
  long lastbucket=0L;
  long bucketspan=0L;
  int bucketcount=0;
  if (isBucketized(x) && isBucketized(y)) {
    if (x.bucketspan == y.bucketspan) {
      if ((x.lastbucket % x.bucketspan) == (y.lastbucket % y.bucketspan)) {
        lastbucket=Math.max(x.lastbucket,y.lastbucket);
        bucketspan=x.bucketspan;
        long firstbucket=Math.min(x.lastbucket - x.bucketcount * bucketspan,y.lastbucket - y.bucketcount * bucketspan);
        bucketcount=(int)((lastbucket - firstbucket) / bucketspan);
      }
    }
  }
  GeoTimeSerie gts=new GeoTimeSerie(lastbucket,bucketcount,bucketspan,16);
  gts.setName(name);
  gts.setLabels(labels);
  sort(x);
  sort(y);
  int xidx=0;
  int yidx=0;
  Object[] params=new Object[7];
  params[1]=new String[2];
  params[2]=new Map[3];
  params[3]=new long[2];
  params[4]=new long[2];
  params[5]=new long[2];
  params[6]=new Object[2];
  Map<String,String> xlabels=ImmutableMap.copyOf(x.getLabels());
  Map<String,String> ylabels=ImmutableMap.copyOf(y.getLabels());
  labels=ImmutableMap.copyOf(labels);
  while (xidx < x.values || yidx < y.values) {
    while (yidx < y.values && x.ticks[xidx] >= y.ticks[yidx]) {
      long tick=y.ticks[yidx];
      Object xelt=x.ticks[xidx] == y.ticks[yidx] ? GTSHelper.valueAtIndex(x,xidx) : null;
      Object yelt=GTSHelper.valueAtIndex(y,yidx);
      params[0]=tick;
      ((String[])params[1])[0]=x.getName();
      ((Map[])params[2])[0]=xlabels;
      ((long[])params[3])[0]=tick;
      if (null == xelt) {
        ((long[])params[4])[0]=GeoTimeSerie.NO_LOCATION;
        ((long[])params[5])[0]=GeoTimeSerie.NO_ELEVATION;
      }
 else {
        ((long[])params[4])[0]=GTSHelper.locationAtIndex(x,xidx);
        ((long[])params[5])[0]=GTSHelper.elevationAtIndex(x,xidx);
      }
      ((Object[])params[6])[0]=xelt;
      ((String[])params[1])[1]=y.getName();
      ((Map[])params[2])[1]=ylabels;
      ((long[])params[3])[1]=tick;
      ((long[])params[4])[1]=GTSHelper.locationAtIndex(y,yidx);
      ((long[])params[5])[1]=GTSHelper.elevationAtIndex(y,yidx);
      ((Object[])params[6])[1]=yelt;
      ((Map[])params[2])[2]=labels;
      Object[] result=(Object[])op.apply(params);
      Object value=result[3];
      if (null != value) {
        long location=(long)result[1];
        long elevation=(long)result[2];
        GTSHelper.setValue(gts,tick,location,elevation,value,false);
      }
      yidx++;
    }
    xidx++;
    while (xidx < x.values && ((yidx < y.values && x.ticks[xidx] < y.ticks[yidx]) || yidx >= y.values)) {
      long tick=x.ticks[xidx];
      Object xelt=x.ticks[xidx];
      Object yelt=null;
      params[0]=tick;
      ((String[])params[1])[0]=x.getName();
      ((Map[])params[2])[0]=xlabels;
      ((long[])params[3])[0]=tick;
      if (null == xelt) {
        ((long[])params[4])[0]=GeoTimeSerie.NO_LOCATION;
        ((long[])params[5])[0]=GeoTimeSerie.NO_ELEVATION;
      }
 else {
        ((long[])params[4])[0]=GTSHelper.locationAtIndex(x,xidx);
        ((long[])params[5])[0]=GTSHelper.elevationAtIndex(x,xidx);
      }
      ((Object[])params[6])[0]=xelt;
      ((String[])params[1])[1]=y.getName();
      ((Map[])params[2])[1]=ylabels;
      ((long[])params[3])[1]=tick;
      ((long[])params[4])[1]=GeoTimeSerie.NO_LOCATION;
      ((long[])params[5])[1]=GeoTimeSerie.NO_ELEVATION;
      ((Object[])params[6])[1]=yelt;
      ((Map[])params[2])[2]=labels;
      Object[] result=(Object[])op.apply(params);
      Object value=result[3];
      if (null != value) {
        long location=(long)result[1];
        long elevation=(long)result[2];
        GTSHelper.setValue(gts,tick,location,elevation,value,false);
      }
      xidx++;
    }
  }
  return gts;
}

private static GeoTimeSerie applyBinOp ( WarpScriptBinaryOp op , String name , Map < String , String > labels , GeoTimeSerie x , GeoTimeSerie y ) { long lastbucket = 0L ; long bucketspan = 0L ; int bucketcount = 0 ; if ( isBucketized ( x ) && isBucketized ( y ) ) { if ( x . bucketspan == y . bucketspan ) { if ( ( x . lastbucket % x . bucketspan ) == ( y . lastbucket % y . bucketspan ) ) { lastbucket = Math . max ( x . lastbucket , y . lastbucket ) ; bucketspan = x . bucketspan ; long firstbucket = Math . min ( x . lastbucket - x . bucketcount * bucketspan , y . lastbucket - y . bucketcount * bucketspan ) ; bucketcount = ( int ) ( ( lastbucket - firstbucket ) / bucketspan ) ; } } } GeoTimeSerie gts = new GeoTimeSerie ( lastbucket , bucketcount , bucketspan , 16 ) ; gts . setName ( name ) ; gts . setLabels ( labels ) ; sort ( x ) ; sort ( y ) ; int xidx = 0 ; int yidx = 0 ; Object [ ] params = new Object [ 7 ] ; params [ 1 ] = new String [ 2 ] ; params [ 2 ] = new Map [ 3 ] ; params [ 3 ] = new long [ 2 ] ; params [ 4 ] = new long [ 2 ] ; params [ 5 ] = new long [ 2 ] ; params [ 6 ] = new Object [ 2 ] ; Map < String , String > xlabels = ImmutableMap . copyOf ( x . getLabels ( ) ) ; Map < String , String > ylabels = ImmutableMap . copyOf ( y . getLabels ( ) ) ; labels = ImmutableMap . copyOf ( labels ) ; while ( xidx < x . values || yidx < y . values ) { while ( yidx < y . values && x . ticks [ xidx ] >= y . ticks [ yidx ] ) { long tick = y . ticks [ yidx ] ; Object xelt = x . ticks [ xidx ] == y . ticks [ yidx ] ? GTSHelper . valueAtIndex ( x , xidx ) : null ; Object yelt = GTSHelper . valueAtIndex ( y , yidx ) ; params [ 0 ] = tick ; ( ( String [ ] ) params [ 1 ] ) [ 0 ] = x . getName ( ) ; ( ( Map [ ] ) params [ 2 ] ) [ 0 ] = xlabels ; ( ( long [ ] ) params [ 3 ] ) [ 0 ] = tick ; if ( null == xelt ) { ( ( long [ ] ) params [ 4 ] ) [ 0 ] = GeoTimeSerie . NO_LOCATION ; ( ( long [ ] ) params [ 5 ] ) [ 0 ] = GeoTimeSerie . NO_ELEVATION ; } else { ( ( long [ ] ) params [ 4 ] ) [ 0 ] = GTSHelper . locationAtIndex ( x , xidx ) ; ( ( long [ ] ) params [ 5 ] ) [ 0 ] = GTSHelper . elevationAtIndex ( x , xidx ) ; } ( ( Object [ ] ) params [ 6 ] ) [ 0 ] = xelt ; ( ( String [ ] ) params [ 1 ] ) [ 1 ] = y . getName ( ) ; ( ( Map [ ] ) params [ 2 ] ) [ 1 ] = ylabels ; ( ( long [ ] ) params [ 3 ] ) [ 1 ] = tick ; ( ( long [ ] ) params [ 4 ] ) [ 1 ] = GTSHelper . locationAtIndex ( y , yidx ) ; ( ( long [ ] ) params [ 5 ] ) [ 1 ] = GTSHelper . elevationAtIndex ( y , yidx ) ; ( ( Object [ ] ) params [ 6 ] ) [ 1 ] = yelt ; ( ( Map [ ] ) params [ 2 ] ) [ 2 ] = labels ; Object [ ] result = ( Object [ ] ) op . apply ( params ) ; Object value = result [ 3 ] ; if ( null != value ) { long location = ( long ) result [ 1 ] ; long elevation = ( long ) result [ 2 ] ; GTSHelper . setValue ( gts , tick , location , elevation , value , false ) ; } yidx ++ ; } xidx ++ ; while ( xidx < x . values && ( ( yidx < y . values && x . ticks [ xidx ] < y . ticks [ yidx ] ) || yidx >= y . values ) ) { long tick = x . ticks [ xidx ] ; Object xelt = x . ticks [ xidx ] ; Object yelt = null ; params [ 0 ] = tick ; ( ( String [ ] ) params [ 1 ] ) [ 0 ] = x . getName ( ) ; ( ( Map [ ] ) params [ 2 ] ) [ 0 ] = xlabels ; ( ( long [ ] ) params [ 3 ] ) [ 0 ] = tick ; if ( null == xelt ) { ( ( long [ ] ) params [ 4 ] ) [ 0 ] = GeoTimeSerie . NO_LOCATION ; ( ( long [ ] ) params [ 5 ] ) [ 0 ] = GeoTimeSerie . NO_ELEVATION ; } else { ( ( long [ ] ) params [ 4 ] ) [ 0 ] = GTSHelper . locationAtIndex ( x , xidx ) ; ( ( long [ ] ) params [ 5 ] ) [ 0 ] = GTSHelper . elevationAtIndex ( x , xidx ) ; } ( ( Object [ ] ) params [ 6 ] ) [ 0 ] = xelt ; ( ( String [ ] ) params [ 1 ] ) [ 1 ] = y . getName ( ) ; ( ( Map [ ] ) params [ 2 ] ) [ 1 ] = ylabels ; ( ( long [ ] ) params [ 3 ] ) [ 1 ] = tick ; ( ( long [ ] ) params [ 4 ] ) [ 1 ] = GeoTimeSerie . NO_LOCATION ; ( ( long [ ] ) params [ 5 ] ) [ 1 ] = GeoTimeSerie . NO_ELEVATION ; ( ( Object [ ] ) params [ 6 ] ) [ 1 ] = yelt ; ( ( Map [ ] ) params [ 2 ] ) [ 2 ] = labels ; Object [ ] result = ( Object [ ] ) op . apply ( params ) ; Object value = result [ 3 ] ; if ( null != value ) { long location = ( long ) result [ 1 ] ; long elevation = ( long ) result [ 2 ] ; GTSHelper . setValue ( gts , tick , location , elevation , value , false ) ; } xidx ++ ; } } return gts ; }
apply a binary op to two gts instances
