Coverage Summary for Class: LongAddables (com.google.common.cache)
| Class | Method, % | Line, % |
|---|---|---|
| LongAddables | 0% (0/3) | 0% (0/8) |
| LongAddables$1 | 0% (0/2) | 0% (0/2) |
| LongAddables$2 | 0% (0/2) | 0% (0/2) |
| LongAddables$PureJavaLongAddable | 0% (0/4) | 0% (0/4) |
| Total | 0% (0/11) | 0% (0/16) |
1 /* 2 * Copyright (C) 2012 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.cache; 16 17 import com.google.common.annotations.GwtCompatible; 18 import com.google.common.base.Supplier; 19 import java.util.concurrent.atomic.AtomicLong; 20 21 /** 22 * Source of {@link LongAddable} objects that deals with GWT, Unsafe, and all that. 23 * 24 * @author Louis Wasserman 25 */ 26 @GwtCompatible(emulated = true) 27 final class LongAddables { 28 private static final Supplier<LongAddable> SUPPLIER; 29 30 static { 31 Supplier<LongAddable> supplier; 32 try { 33 new LongAdder(); // trigger static initialization of the LongAdder class, which may fail 34 supplier = 35 new Supplier<LongAddable>() { 36 @Override 37 public LongAddable get() { 38 return new LongAdder(); 39 } 40 }; 41 } catch (Throwable t) { // we really want to catch *everything* 42 supplier = 43 new Supplier<LongAddable>() { 44 @Override 45 public LongAddable get() { 46 return new PureJavaLongAddable(); 47 } 48 }; 49 } 50 SUPPLIER = supplier; 51 } 52 53 public static LongAddable create() { 54 return SUPPLIER.get(); 55 } 56 57 private static final class PureJavaLongAddable extends AtomicLong implements LongAddable { 58 @Override 59 public void increment() { 60 getAndIncrement(); 61 } 62 63 @Override 64 public void add(long x) { 65 getAndAdd(x); 66 } 67 68 @Override 69 public long sum() { 70 return get(); 71 } 72 } 73 }