/** * Returns the value of this {@code AtomicDouble} as a {@code float} after a narrowing primitive * conversion. */ public float floatValue() { return (float) get(); }
/** get returns the last value set */ public void testGetSet() { AtomicDouble at = new AtomicDouble(1.0); assertBitEquals(1.0, at.get()); for (double x : VALUES) { at.set(x); assertBitEquals(x, at.get()); } }
@Override public boolean process(Node node) { while (iterator.hasNext() && iterator.peek() <= node.getUpperBound()) { double bucketCount = sum.get() - lastSum.get(); Bucket bucket = new Bucket(bucketCount / normalizationFactor, bucketWeightedSum.get() / bucketCount); builder.add(bucket); lastSum.set(sum.get()); bucketWeightedSum.set(0); iterator.next(); } bucketWeightedSum.addAndGet(node.getMiddle() * node.weightedCount); sum.addAndGet(node.weightedCount); return iterator.hasNext(); } });
public double increment(String key, double val) { return doubleCounters.computeIfAbsent(key, k -> new AtomicDouble()).addAndGet(val); }
/** doubleValue returns current value. */ public void testDoubleValue() { AtomicDouble at = new AtomicDouble(); assertEquals(0.0d, at.doubleValue()); for (double x : VALUES) { at.set(x); assertBitEquals(x, at.doubleValue()); } }
/** constructor initializes to given value */ public void testConstructor() { for (double x : VALUES) { AtomicDouble a = new AtomicDouble(x); assertBitEquals(x, a.get()); } }
final AtomicDouble max = new AtomicDouble(Double.MIN_VALUE); String c = aggregator.substring(4, aggregator.length() - 1); choices.forEach(json -> max.set(Math.max(max.get(), ((JSONObject) json).getDouble(c)))); return a.put(new JSONObject().put(aggregator_as, max.get())); final AtomicDouble min = new AtomicDouble(Double.MAX_VALUE); String c = aggregator.substring(4, aggregator.length() - 1); choices.forEach(json -> min.set(Math.min(min.get(), ((JSONObject) json).getDouble(c)))); return a.put(new JSONObject().put(aggregator_as, min.get())); final AtomicDouble sum = new AtomicDouble(0.0d); String c = aggregator.substring(4, aggregator.length() - 1); choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c))); return a.put(new JSONObject().put(aggregator_as, sum.get())); final AtomicDouble sum = new AtomicDouble(0.0d); String c = aggregator.substring(4, aggregator.length() - 1); choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c))); return a.put(new JSONObject().put(aggregator_as, sum.get() / choices.length())); final String column_final = column; if (aggregator.startsWith("PERCENT(") && aggregator.endsWith(")")) { final AtomicDouble sum = new AtomicDouble(0.0d); String c = aggregator.substring(8, aggregator.length() - 1); choices.forEach(json -> sum.addAndGet(((JSONObject) json).getDouble(c))); choices.forEach(json -> a.put(new JSONObject() .put(aggregator_as, 100.0d * ((JSONObject) json).getDouble(c) / sum.get()) .put(column_as, ((JSONObject) json).get(column_final)))); return a;
/** * Sets the current activity. * @param currentActivity */ public synchronized void setCurrentActivity(String currentActivity) { this.currentActivity = currentActivity; currentProgress.set(0); }
/** addAndGet adds given value to current, and returns current value */ public void testAddAndGet() { for (double x : VALUES) { for (double y : VALUES) { AtomicDouble a = new AtomicDouble(x); double z = a.addAndGet(y); assertBitEquals(x + y, z); assertBitEquals(x + y, a.get()); } } }
/** getAndAdd returns previous value and adds given value */ public void testGetAndAdd() { for (double x : VALUES) { for (double y : VALUES) { AtomicDouble a = new AtomicDouble(x); double z = a.getAndAdd(y); assertBitEquals(x, z); assertBitEquals(x + y, a.get()); } } }
/** compareAndSet succeeds in changing value if equal to expected else fails */ public void testCompareAndSet() { double prev = Math.E; double unused = Math.E + Math.PI; AtomicDouble at = new AtomicDouble(prev); for (double x : VALUES) { assertBitEquals(prev, at.get()); assertFalse(at.compareAndSet(unused, x)); assertBitEquals(prev, at.get()); assertTrue(at.compareAndSet(prev, x)); assertBitEquals(x, at.get()); prev = x; } }
/** get returns the last value lazySet in same thread */ public void testGetLazySet() { AtomicDouble at = new AtomicDouble(1.0); assertBitEquals(1.0, at.get()); for (double x : VALUES) { at.lazySet(x); assertBitEquals(x, at.get()); } }
/** compareAndSet treats +0.0 and -0.0 as distinct values */ public void testDistinctZeros() { AtomicDouble at = new AtomicDouble(+0.0); assertFalse(at.compareAndSet(-0.0, 7.0)); assertFalse(at.weakCompareAndSet(-0.0, 7.0)); assertBitEquals(+0.0, at.get()); assertTrue(at.compareAndSet(+0.0, -0.0)); assertBitEquals(-0.0, at.get()); assertFalse(at.compareAndSet(+0.0, 7.0)); assertFalse(at.weakCompareAndSet(+0.0, 7.0)); assertBitEquals(-0.0, at.get()); } }
/** floatValue returns current value. */ public void testFloatValue() { AtomicDouble at = new AtomicDouble(); assertEquals(0.0f, at.floatValue()); for (double x : VALUES) { at.set(x); assertEquals((float) x, at.floatValue()); } }
/** repeated weakCompareAndSet succeeds in changing value when equal to expected */ public void testWeakCompareAndSet() { double prev = Math.E; double unused = Math.E + Math.PI; AtomicDouble at = new AtomicDouble(prev); for (double x : VALUES) { assertBitEquals(prev, at.get()); assertFalse(at.weakCompareAndSet(unused, x)); assertBitEquals(prev, at.get()); while (!at.weakCompareAndSet(prev, x)) {; } assertBitEquals(x, at.get()); prev = x; } }
/** longValue returns current value. */ public void testLongValue() { AtomicDouble at = new AtomicDouble(); assertEquals(0L, at.longValue()); for (double x : VALUES) { at.set(x); assertEquals((long) x, at.longValue()); } }
/** intValue returns current value. */ public void testIntValue() { AtomicDouble at = new AtomicDouble(); assertEquals(0, at.intValue()); for (double x : VALUES) { at.set(x); assertEquals((int) x, at.intValue()); } }
/** toString returns current value */ public void testToString() { AtomicDouble at = new AtomicDouble(); assertEquals("0.0", at.toString()); for (double x : VALUES) { at.set(x); assertEquals(Double.toString(x), at.toString()); } }
protected void updateMetrics(Map<String, Double> metrics, Optional<String> processorName, Map<String, String> tags) { for (Map.Entry<String, Double> entry : metrics.entrySet()) { final String metricName = buildMetricName(processorName, entry.getKey()); logger.debug(metricName + ": " + entry.getValue()); //if metric is not registered yet - register it if (!metricsMap.containsKey(metricName)) { metricsMap.put(metricName, new AtomicDouble(entry.getValue())); metricRegistry.register(metricName, new MetricGauge(metricName, tags)); } //set real time value to metrics map metricsMap.get(metricName).set(entry.getValue()); } }