Coverage Summary for Class: Count (com.google.common.collect)

Class Class, % Method, % Line, %
Count 100% (1/1) 22.2% (2/9) 26.7% (4/15)


1 /* 2  * Copyright (C) 2011 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 10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 11  * express or implied. See the License for the specific language governing permissions and 12  * limitations under the License. 13  */ 14  15 package com.google.common.collect; 16  17 import com.google.common.annotations.GwtCompatible; 18 import java.io.Serializable; 19 import org.checkerframework.checker.nullness.qual.Nullable; 20  21 /** 22  * A mutable value of type {@code int}, for multisets to use in tracking counts of values. 23  * 24  * @author Louis Wasserman 25  */ 26 @GwtCompatible 27 final class Count implements Serializable { 28  private int value; 29  30  Count(int value) { 31  this.value = value; 32  } 33  34  public int get() { 35  return value; 36  } 37  38  public void add(int delta) { 39  value += delta; 40  } 41  42  public int addAndGet(int delta) { 43  return value += delta; 44  } 45  46  public void set(int newValue) { 47  value = newValue; 48  } 49  50  public int getAndSet(int newValue) { 51  int result = value; 52  value = newValue; 53  return result; 54  } 55  56  @Override 57  public int hashCode() { 58  return value; 59  } 60  61  @Override 62  public boolean equals(@Nullable Object obj) { 63  return obj instanceof Count && ((Count) obj).value == value; 64  } 65  66  @Override 67  public String toString() { 68  return Integer.toString(value); 69  } 70 }