Пример #1
0
  public static void main(String[] args) {
    try {
      // define time domain "once every fourth year"
      TimeDomainDefinition year4def =
          new TimeDomainDefinition(
              "year4", Resolution.YEAR, 0L, new Cycle(true, false, false, false));
      TimeDomain year4 = TimeDomainManager.getFactory().get(year4def, true);

      // define "missing value" for String (else, the default is null)
      String missingValue = "(missing)";
      TimeSeriesFactory.getInstance().define(String.class, missingValue);

      TimeAddressable<String> olympics = TimeSeriesFactory.make(year4, String.class);
      olympics.put(
          year4.time("1896"),
          new String[] {"Athens", "Paris", "Saint-Louis", "London", "Stockholm"});
      olympics.put(
          year4.time("1920"),
          new String[] {"Antwerp", "Paris", "Amsterdam", "Los Angeles", "Berlin"});

      for (Observation<String> oly : olympics) {
        System.out.println(oly.toString());
      }

    } catch (Exception e) {
      System.err.println("Oops...\n" + e.getMessage());
    }
  }
Пример #2
0
 private TimeSeries convertToJFCTimeSeries(
     boolean interpolate, String name, TimeAddressable<Double> ts) throws KeyedException {
   Constructor<? extends RegularTimePeriod> constructor = getPeriodConstructor(ts.getTimeDomain());
   TimeSeries timeSeries = new TimeSeries(name);
   for (Observation<Double> obs : ts) {
     Double value = obs.getValue();
     if (ts.isMissing(value)) {
       if (interpolate) continue;
     }
     Date date = JavaDateUtil.toJavaDate(obs.getTime());
     RegularTimePeriod period = null;
     try {
       period = constructor.newInstance(date);
     } catch (Exception e) {
       throw K.JFC_PERIOD_ERR.exception(e, date.toString());
     }
     timeSeries.add(period, value);
   }
   return timeSeries;
 }