Esempio n. 1
0
    @Nonnull
    @Override
    public OptionalTsData build() {
      if (dc.getCount() == 0) {
        return onFailure("No data available");
      }
      if (freq == TsFrequency.Undefined && aggregation != TsAggregationType.None) {
        return onFailure("Invalid aggregation mode");
      }
      TsData result;
      if (aggregation == TsAggregationType.None) {
        result = dc.make(freq, aggregation);
      } else {
        result = dc.make(TsFrequency.Undefined, TsAggregationType.None);
        if (result != null && (result.getFrequency().intValue() % freq.intValue() == 0)) {
          // should succeed
          result = result.changeFrequency(freq, aggregation, true);
        } else {
          result = dc.make(freq, aggregation);
        }
      }

      if (result == null) {
        switch (freq) {
          case Undefined:
            return dc.getCount() == 1
                ? onFailure("Cannot guess frequency with a single observation")
                : onFailure("Cannot guess frequency with duplicated periods");
          default:
            // TODO: if TsAggregationType.None
        }
        return onFailure("Unexpected error");
      }
      return onSuccess(result);
    }
Esempio n. 2
0
 @Nonnull
 public Builder add(@Nullable Date period, @Nullable Number value) {
   if (period != null) {
     if (value != null) {
       dc.addObservation(period, value.doubleValue());
     } else if (!skipMissingValues) {
       dc.addMissingValue(period);
     }
   } else {
     nbrUselessRows++;
   }
   return this;
 }
Esempio n. 3
0
 private OptionalTsData onFailure(String cause) {
   return new Absent(dc.getCount(), nbrUselessRows, cause);
 }
Esempio n. 4
0
 private OptionalTsData onSuccess(TsData tsData) {
   return new Present(dc.getCount(), nbrUselessRows, tsData);
 }
Esempio n. 5
0
 @Nonnull
 public Builder clear() {
   dc.clear();
   nbrUselessRows = 0;
   return this;
 }