/**
 * Copyright 2017 Pivotal Software, Inc.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micrometer.core.instrument.cumulative;

import com.google.common.util.concurrent.AtomicDouble;
import io.micrometer.core.instrument.AbstractDistributionSummary;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Statistic;
import io.micrometer.core.instrument.histogram.HistogramConfig;

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicLong;

public class CumulativeDistributionSummary extends AbstractDistributionSummary {
    private final AtomicLong count;
    private final AtomicDouble total;
    private final AtomicDouble max;

    public CumulativeDistributionSummary(Id id, Clock clock, HistogramConfig histogramConfig) {
        super(id, clock, histogramConfig);
        this.count = new AtomicLong();
        this.total = new AtomicDouble();
        this.max = new AtomicDouble();
    }

    @Override
    protected void recordNonNegative(double amount) {
        count.getAndAdd(1);
        total.getAndAdd(amount);
        updateMax(amount);
    }

    @Override
    public long count() {
        return count.get();
    }

    @Override
    public double totalAmount() {
        return total.get();
    }

    @Override
    public double max() {
        return max.get();
    }

    @Override
    public Iterable<Measurement> measure() {
        return Arrays.asList(
            new Measurement(() -> (double) count(), Statistic.Count),
            new Measurement(this::totalAmount, Statistic.Total),
            new Measurement(this::max, Statistic.Max)
        );
    }

    private void updateMax(double amount) {
        while (true) {
            double currentMax = max.get();
            if (currentMax >= amount) {
                return;
            }
            if (max.compareAndSet(currentMax, amount)) {
                return;
            }
        }
    }

}

@@ -663,63 +663,8 @@
 e;%0A%0A
-import com.google.common.util.concurrent.AtomicDouble;%0A
 impo
@@ -1004,16 +1004,195 @@
 icLong;%0A
+import java.util.concurrent.atomic.DoubleAdder;%0A%0A/**%0A * Cumulative distribution summary.%0A *%0A * @author Clint Checketts%0A * @author Vladimir Bukhtoyarov%0A * @author Jon Schneider%0A */
 %0Apublic 
@@ -1265,16 +1265,17 @@
 mmary %7B%0A
+%0A
     priv
@@ -1320,28 +1320,27 @@
 e final 
-Atomic
 Double
+Adder
  total;%0A
@@ -1367,18 +1367,24 @@
 omic
-Double max
+Long maxLongBits
 ;%0A%0A 
@@ -1581,36 +1581,35 @@
 total = new 
-Atomic
 Double
+Adder
 ();%0A        
@@ -1616,16 +1616,24 @@
 this.max
+LongBits
  = new A
@@ -1637,22 +1637,20 @@
 w Atomic
-Double
+Long
 ();%0A    
@@ -1738,19 +1738,24 @@
 unt.
-getAndAdd(1
+incrementAndGet(
 );%0A 
@@ -1771,15 +1771,9 @@
 tal.
-getAndA
+a
 dd(a
@@ -1958,19 +1958,19 @@
 n total.
-get
+sum
 ();%0A    
@@ -2027,25 +2027,58 @@
  return 
-max
+Double.longBitsToDouble(maxLongBits
 .get()
+)
 ;%0A    %7D%0A
@@ -2430,63 +2430,217 @@
     
-while (true) %7B%0A            double currentMax = max.get(
+long amountLongBits = Double.doubleToLongBits(amount);%0A        while (true) %7B%0A            long currentMaxLongBits = maxLongBits.get();%0A            double currentMax = Double.longBitsToDouble(currentMaxLongBits
 );%0A 
@@ -2735,16 +2735,24 @@
  if (max
+LongBits
 .compare
@@ -2772,16 +2772,32 @@
 tMax
-, amount
+LongBits, amountLongBits
 )) %7B

Remove AtomicDouble usage from Guava