public static GeoTimeSerie fillprevious(GeoTimeSerie gts){
  GeoTimeSerie filled=gts.clone();
  if (!isBucketized(filled)) {
    return filled;
  }
  sort(filled,false);
  int nticks=filled.values;
  if (0 != nticks) {
    long firsttick=filled.ticks[0];
    filled.setSizeHint(1 + (int)((filled.lastbucket - firsttick) / filled.bucketspan));
  }
  int idx=0;
  int bucketidx=filled.bucketcount - 1;
  long bucketts=filled.lastbucket - bucketidx * filled.bucketspan;
  Object prevValue=null;
  long prevLocation=GeoTimeSerie.NO_LOCATION;
  long prevElevation=GeoTimeSerie.NO_ELEVATION;
  long bucketoffset=filled.lastbucket % filled.bucketspan;
  while (bucketidx >= 0) {
    while (idx < nticks && bucketoffset != (filled.ticks[idx] % filled.bucketspan)) {
      idx++;
    }
    if (idx >= nticks) {
      break;
    }
    while (bucketidx >= 0 && filled.ticks[idx] > bucketts) {
      if (null != prevValue) {
        setValue(filled,bucketts,prevLocation,prevElevation,prevValue,false);
      }
      bucketidx--;
      bucketts=filled.lastbucket - bucketidx * filled.bucketspan;
    }
    bucketidx--;
    bucketts=filled.lastbucket - bucketidx * filled.bucketspan;
    prevValue=valueAtIndex(filled,idx);
    prevLocation=null != filled.locations ? filled.locations[idx] : GeoTimeSerie.NO_LOCATION;
    prevElevation=null != filled.elevations ? filled.elevations[idx] : GeoTimeSerie.NO_ELEVATION;
    idx++;
  }
  while (bucketidx >= 0) {
    if (null != prevValue) {
      setValue(filled,bucketts,prevLocation,prevElevation,prevValue,false);
    }
    bucketidx--;
    bucketts=filled.lastbucket - bucketidx * filled.bucketspan;
  }
  return filled;
}

public static GeoTimeSerie fillprevious ( GeoTimeSerie gts ) { GeoTimeSerie filled = gts . clone ( ) ; if ( ! isBucketized ( filled ) ) { return filled ; } sort ( filled , false ) ; int nticks = filled . values ; if ( 0 != nticks ) { long firsttick = filled . ticks [ 0 ] ; filled . setSizeHint ( 1 + ( int ) ( ( filled . lastbucket - firsttick ) / filled . bucketspan ) ) ; } int idx = 0 ; int bucketidx = filled . bucketcount - 1 ; long bucketts = filled . lastbucket - bucketidx * filled . bucketspan ; Object prevValue = null ; long prevLocation = GeoTimeSerie . NO_LOCATION ; long prevElevation = GeoTimeSerie . NO_ELEVATION ; long bucketoffset = filled . lastbucket % filled . bucketspan ; while ( bucketidx >= 0 ) { while ( idx < nticks && bucketoffset != ( filled . ticks [ idx ] % filled . bucketspan ) ) { idx ++ ; } if ( idx >= nticks ) { break ; } while ( bucketidx >= 0 && filled . ticks [ idx ] > bucketts ) { if ( null != prevValue ) { setValue ( filled , bucketts , prevLocation , prevElevation , prevValue , false ) ; } bucketidx -- ; bucketts = filled . lastbucket - bucketidx * filled . bucketspan ; } bucketidx -- ; bucketts = filled . lastbucket - bucketidx * filled . bucketspan ; prevValue = valueAtIndex ( filled , idx ) ; prevLocation = null != filled . locations ? filled . locations [ idx ] : GeoTimeSerie . NO_LOCATION ; prevElevation = null != filled . elevations ? filled . elevations [ idx ] : GeoTimeSerie . NO_ELEVATION ; idx ++ ; } while ( bucketidx >= 0 ) { if ( null != prevValue ) { setValue ( filled , bucketts , prevLocation , prevElevation , prevValue , false ) ; } bucketidx -- ; bucketts = filled . lastbucket - bucketidx * filled . bucketspan ; } return filled ; }
fill missing values / locations / elevations in a bucketized gts with the previously encountered one . returns a filled clone of ' gts ' . ' gts ' is not modified .
