private static Value transform(Value in, float factor, float offset) { if (in instanceof FloatValue) return new FloatValue(in.getFloatValue() * factor + offset); else if (in instanceof IntegerValue) return new IntegerValue(in.getIntegerValue() * ((int) factor) + (int) offset); // problematic... else if (in instanceof LongValue) return new LongValue(in.getLongValue() * ((long) factor) + (long) offset);// problematic... else if (in instanceof BooleanValue) return new BooleanValue(in.getBooleanValue() && (factor >= 0)); else return in; }
@Override public final SampledValue apply(SampledValue value) { return new SampledValue(new FloatValue(value.getValue().getFloatValue() * m_factor), value.getTimestamp(), value.getQuality()); }
public float getGradient(SampledValue sv1, SampledValue sv2) { long tDiff = sv2.getTimestamp() - sv1.getTimestamp(); float valDiff = sv2.getValue().getFloatValue() - sv1.getValue().getFloatValue(); return valDiff / ((float) tDiff); }
@SuppressWarnings("unchecked") N getValue(final SampledValue sv) { if (type == Float.class) return (N) (Float) sv.getValue().getFloatValue(); if (type == Integer.class) return (N) (Integer) sv.getValue().getIntegerValue(); if (type == Long.class) return (N) (Long) sv.getValue().getLongValue(); if (type == String.class) { return (N) sv.getValue().getStringValue(); } return (N) (Float) sv.getValue().getFloatValue(); }
Value getValue(N value) { if (value == null) value = getNullReplacement(); if (type == Float.class) return new FloatValue((Float) value); if (type == Integer.class) return new IntegerValue((Integer) value); if (type == Long.class) return new LongValue((Long) value); if (type == String.class) { return new StringValue((String) value); } return new FloatValue((Float) value); }
@Override public void writeValue(SampledValue v, JsonGenerator jGen) throws IOException { jGen.writeBooleanField("value", v.getValue().getBooleanValue()); jGen.writeStringField("@type", "SampledBoolean"); } },
@Override public void writeValue(SampledValue v, JsonGenerator jGen) throws IOException { jGen.writeStringField(SINGLEVALUE, v.getValue().getStringValue()); jGen.writeStringField("@type", "SampledString"); } };
private static final boolean nextIsNewer(SampledValue current, SampledValue next) { if (current == null || next == null) return next != null; if (next == current) return false; return current.getTimestamp() < next.getTimestamp(); }
@Override Value createScheduleValue(Float value) { return new FloatValue(value); } };
@Override Value createScheduleValue(Integer value) { return new IntegerValue(value); } };
@Override Value createScheduleValue(Long value) { return new LongValue(value); } };
@Override Value createScheduleValue(byte[] value) { return new ByteArrayValue(value); } };
@Override Value createScheduleValue(String value) { return new StringValue(value); } };
@Override public DoubleValue load(Double key) throws Exception { return new DoubleValue(key); } });
@Override public final SampledValue apply(SampledValue value) { return new SampledValue(new FloatValue(value.getValue().getFloatValue() + m_addend), value.getTimestamp(), value.getQuality()); }
private static final boolean nextIsNewer(SampledValue current, SampledValue next) { if (current == null || next == null) return next != null; if (next == current) return false; return current.getTimestamp() < next.getTimestamp(); }
@Override public final SampledValue apply(final SampledValue value1, final SampledValue value2) { final long t1 = value1.getTimestamp(); final long t2 = value2.getTimestamp(); if (t1 != t2) return new SampledValue(new FloatValue(0.f), t1, Quality.BAD); final float x1 = value1.getValue().getFloatValue(); final float x2 = value2.getValue().getFloatValue(); final Quality q1 = value1.getQuality(); final Quality q2 = value2.getQuality(); final Quality quality = (q1 == Quality.GOOD && q2 == Quality.GOOD) ? Quality.GOOD : Quality.BAD; return new SampledValue(new FloatValue(x1 + x2), t2, quality); } }
private static final boolean nextIsNewer(SampledValue current, SampledValue next) { if (current == null || next == null) return next != null; if (next == current) return false; return current.getTimestamp() < next.getTimestamp(); }
@Override public final SampledValue apply(final SampledValue value1, final SampledValue value2) { final long t1 = value1.getTimestamp(); final long t2 = value2.getTimestamp(); if (t1 != t2) return new SampledValue(new FloatValue(0.f), t1, Quality.BAD); final float x1 = value1.getValue().getFloatValue(); final float x2 = value2.getValue().getFloatValue(); final Quality q1 = value1.getQuality(); final Quality q2 = value2.getQuality(); final Quality quality = (q1 == Quality.GOOD && q2 == Quality.GOOD) ? Quality.GOOD : Quality.BAD; return new SampledValue(new FloatValue(x1 * x2), t2, quality); } }
@Override public synchronized SampledValue getMin(long t0, long t1) { final FloatTreeTimeSeries f = new FloatTreeTimeSeries(this); f.multiplyBy(-1.f); final SampledValue negMax = f.getMax(t0, t1); return new SampledValue(new FloatValue(negMax.getValue().getFloatValue()), negMax.getTimestamp(), negMax .getQuality()); }