Coverage Summary for Class: LongAddables (com.google.common.hash)
| 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.hash; 16 17 import com.google.common.base.Supplier; 18 import java.util.concurrent.atomic.AtomicLong; 19 20 /** 21 * Source of {@link LongAddable} objects that deals with GWT, Unsafe, and all that. 22 * 23 * @author Louis Wasserman 24 */ 25 @ElementTypesAreNonnullByDefault 26 final class LongAddables { 27 private static final Supplier<LongAddable> SUPPLIER; 28 29 static { 30 Supplier<LongAddable> supplier; 31 try { 32 new LongAdder(); // trigger static initialization of the LongAdder class, which may fail 33 supplier = 34 new Supplier<LongAddable>() { 35 @Override 36 public LongAddable get() { 37 return new LongAdder(); 38 } 39 }; 40 } catch (Throwable t) { // we really want to catch *everything* 41 supplier = 42 new Supplier<LongAddable>() { 43 @Override 44 public LongAddable get() { 45 return new PureJavaLongAddable(); 46 } 47 }; 48 } 49 SUPPLIER = supplier; 50 } 51 52 public static LongAddable create() { 53 return SUPPLIER.get(); 54 } 55 56 private static final class PureJavaLongAddable extends AtomicLong implements LongAddable { 57 @Override 58 public void increment() { 59 getAndIncrement(); 60 } 61 62 @Override 63 public void add(long x) { 64 getAndAdd(x); 65 } 66 67 @Override 68 public long sum() { 69 return get(); 70 } 71 } 72 }