private Double pollAndUpdate(final long currentTime) { long timeDiff = currentTime - lastUpdate; if (timeDiff <= 0) { return null; } final Long currentValue = this.getNext(); final Long lastValue = this.lastValue; this.lastValue = currentValue; if (lastValue == null || currentValue == null) { return null; } final double valueDiff = (double) (currentValue - lastValue); // ignore negative values. if (valueDiff < 0) { return null; } return (valueDiff / timeDiff) * 1000; }
@Override public Double getValue() { if (initial) { synchronized (lock) { if (initial) { this.lastValue = getNext(); this.lastUpdate = timeProvider.currentTime(); this.initial = false; } } } final long currentTime = timeProvider.currentTime(); if (currentTime - lastUpdate < minimalTimeStep) { return this.derived; } synchronized (lock) { if (currentTime - lastUpdate < minimalTimeStep) { return this.derived; } final Double derived = pollAndUpdate(currentTime); this.derived = derived; this.lastUpdate = currentTime; return this.derived; } }
@Override public Double getValue() { if (initial) { synchronized (lock) { if (initial) { this.lastValue = getNext(); this.lastUpdate = timeProvider.currentTime(); this.initial = false; } } } final long currentTime = timeProvider.currentTime(); if (currentTime - lastUpdate < minimalTimeStep) { return this.derived; } synchronized (lock) { if (currentTime - lastUpdate < minimalTimeStep) { return this.derived; } final Double derived = pollAndUpdate(currentTime); this.derived = derived; this.lastUpdate = currentTime; return this.derived; } }
private Double pollAndUpdate(final long currentTime) { long timeDiff = currentTime - lastUpdate; if (timeDiff <= 0) { return null; } final Long currentValue = this.getNext(); final Long lastValue = this.lastValue; this.lastValue = currentValue; if (lastValue == null || currentValue == null) { return null; } final double valueDiff = (double) (currentValue - lastValue); // ignore negative values. if (valueDiff < 0) { return null; } return (valueDiff / timeDiff) * 1000; }