Example #1
0
  public void update(final VType value) {
    display_info = Optional.ofNullable(ValueUtil.displayOf(value));
    if (display_info.isPresent()) value_dbl = ValueUtil.numericValueOf(value).doubleValue();

    if (value instanceof VNumber)
      value_str = Double.toString(((VNumber) value).getValue().doubleValue());
    else if (value instanceof VEnum) {
      final VEnum ev = (VEnum) value;
      if (ev.getIndex() >= 0 && ev.getIndex() < ev.getLabels().size())
        value_str = ev.getLabels().get(ev.getIndex());
      else value_str = Integer.toString(ev.getIndex());
    } else if (value instanceof VString) value_str = ((VString) value).getValue();
    else value_str = Objects.toString(value);

    final Time vtime = ValueUtil.timeOf(value);
    if (vtime == null) return;

    final Timestamp stamp = vtime.getTimestamp();
    final Instant new_time = Instant.ofEpochSecond(stamp.getSec(), stamp.getNanoSec());
    if (time != null) {
      final Duration duration = Duration.between(time, new_time);
      final double period = duration.getSeconds() + duration.getNano() * 1e-9;
      value_period.add(period);
    } else value_period.reset();
    time = new_time;
  }
Example #2
0
 private static void appendTime(StringBuilder builder, Time time) {
   builder.append(", ").append(timeFormat.format(time.getTimestamp()));
 }