@Override public MemoryTimeSeries clone() { return new TreeTimeSeries(this, m_type); }
@Override public boolean replaceValuesFixedStep(long startTime, List<Value> values, long stepSize) { final long endTime = startTime + stepSize * values.size(); deleteValues(startTime, endTime); long t = startTime; for (Value value : values) { addValue(t, value); t += stepSize; } return true; }
/** * Copy-constructor from another time series. Note that the TimeSeries interface provides no means of telling the * user what the actual data type is, so it must be provided explicitly. */ public TreeTimeSeries(ReadOnlyTimeSeries other, Class<? extends Value> type) { this.m_type = type; addValues(other.getValues(Long.MIN_VALUE)); setInterpolationMode(other.getInterpolationMode()); }
@Override public boolean replaceValues(long startTime, long endTime, Collection<SampledValue> values) { deleteValues(startTime, endTime); if (values == null) values = Collections.emptyList(); addValues(values); return true; }
/** * Multiplies each value of <code>schedule</code> with <code>factor</code> and adds <code>addend</code> * * @param readOnlyTimeSeries * @param factor * @param addend * @return */ public static MemoryTimeSeries affineTransformation(ReadOnlyTimeSeries readOnlyTimeSeries, float factor, float addend) { TreeTimeSeries tts = new TreeTimeSeries(FloatValue.class); tts.setInterpolationMode(readOnlyTimeSeries.getInterpolationMode()); final Iterator<SampledValue> it = readOnlyTimeSeries.iterator(); SampledValue value; while (it.hasNext()) { value = it.next(); tts.addValue(new SampledValue(new FloatValue(value.getValue().getFloatValue()*factor + addend), value.getTimestamp(), value.getQuality())); } return tts; }
result = MemoryTimeSeries.EMPTY_TIME_SERIES; else { result = new TreeTimeSeries(values.iterator().next().getValue().getClass()); ((TreeTimeSeries) result).addValues(values);
@Override public TreeTimeSeries read(ReadOnlyTimeSeries schedule) { m_values.clear(); final List<SampledValue> newValues = schedule.getValues(Long.MIN_VALUE); for (SampledValue value : newValues) { m_values.add(value.copyDefensively()); } setInterpolationMode(schedule.getInterpolationMode()); return this; }
@Override public boolean addValues(Collection<SampledValue> values, long timeOfCalculation) { addValues(values); m_lastCalculationTime = timeOfCalculation; return true; }
@Override public boolean addValue(long timestamp, Value value, long timeOfCalculation) { addValue(timestamp, value); m_lastCalculationTime = timeOfCalculation; return true; }
@Override public final boolean addValues(Collection<SampledValue> values) { if (values.isEmpty()) return true; if (m_values.isEmpty()) { // no need to delete old values in this case m_values.addAll(values); return true; } final SortedSet<SampledValue> copy; if (values instanceof SortedSet) { copy = (SortedSet<SampledValue>) values; } else { copy = new TreeSet<>(values); } SampledValue first = copy.first(); SampledValue last = copy.last(); if (!m_values.subSet(first, true, last, true).isEmpty()) { deleteByTimestamps(copy); } m_values.addAll(values); return true; }
@Override public TreeTimeSeries read(ReadOnlyTimeSeries schedule, long start, long end) { m_values.clear(); final List<SampledValue> newValues = schedule.getValues(start, end); for (SampledValue value : newValues) { m_values.add(value.copyDefensively()); } setInterpolationMode(schedule.getInterpolationMode()); return this; }
private static ReadOnlyTimeSeries deserialize(final TimeseriesDTO dto) { final TreeTimeSeries ts = new FloatTreeTimeSeries(); if (dto.values == null || dto.timestamps == null) throw new NullPointerException("Timestamps or values are null"); if (dto.values.size() != dto.timestamps.size()) throw new IllegalStateException("Nr of timestamps does not equal nr of values"); final Iterator<Long> tIt = dto.timestamps.iterator(); final Iterator<Float> vIt = dto.values.iterator(); final List<SampledValue> values = new ArrayList<>(dto.timestamps.size()); while (tIt.hasNext()) { values.add(new SampledValue(new FloatValue(vIt.next()), tIt.next(), Quality.GOOD)); } ts.addValues(values); return ts; }
@Override public boolean addValue(long timestamp, Value value) { addValue(new SampledValue(value, timestamp, Quality.GOOD)); return true; }
+ parentClass.getCanonicalName() + ": Schedules of this type are not supported."); m_schedule = new TreeTimeSeries(m_valueType);
@Override public TreeTimeSeries readWithBoundaries(ReadOnlyTimeSeries schedule, long start, long end) { m_values.clear(); setInterpolationMode(schedule.getInterpolationMode()); if (end < start) return this; if (end == start) { SampledValue sv = schedule.getValue(start); if (sv != null) m_values.add(new SampledValue(sv)); return this; } final List<SampledValue> newValues = schedule.getValues(start, end); if (newValues.isEmpty() || start < newValues.get(0).getTimestamp()) { SampledValue sv = schedule.getValue(start); if (sv != null) m_values.add(sv.copyDefensively()); } for (SampledValue value : newValues) { m_values.add(value.copyDefensively()); } SampledValue sv = schedule.getValue(end); if (sv != null) m_values.add(sv.copyDefensively()); return this; }
@Override public synchronized ReadOnlyTimeSeries getValue() { if (gapGraph == null) { gapGraph = new TreeTimeSeries(BooleanValue.class); gapGraph.setInterpolationMode(InterpolationMode.STEPS); for (SampledValue sv: gaps) { gapGraph.addValue(new SampledValue(new BooleanValue(true), sv.getTimestamp(), Quality.GOOD)); gapGraph.addValue(new SampledValue(new BooleanValue(false), sv.getTimestamp()+sv.getValue().getLongValue(), Quality.GOOD)); } } return gapGraph; }