Coverage Report - org.dozer.stats.StatisticEntry
 
Classes in this File Line Coverage Branch Coverage Complexity
StatisticEntry
87%
14/16
75%
3/4
1.571
 
 1  
 /**
 2  
  * Copyright 2005-2013 Dozer Project
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.dozer.stats;
 17  
 
 18  
 import org.apache.commons.lang3.builder.EqualsBuilder;
 19  
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
 20  
 import org.apache.commons.lang3.builder.ToStringStyle;
 21  
 
 22  
 import java.util.concurrent.atomic.AtomicLong;
 23  
 
 24  
 /**
 25  
  * Internal class that represents one entry in the statistic. Holds the statistic value and unique key for lookup.
 26  
  * Entry counter is based on AtomicLong and is Thread Safe.
 27  
  *
 28  
  * Only intended for internal use.
 29  
  * 
 30  
  * @author tierney.matt
 31  
  * @author dmitry.buzdin
 32  
  */
 33  
 public class StatisticEntry {
 34  
 
 35  
   private final Object key;
 36  499
   private final AtomicLong value = new AtomicLong();
 37  
 
 38  499
   public StatisticEntry(Object key) {
 39  499
     this.key = key;
 40  499
   }
 41  
 
 42  
   public Object getKey() {
 43  5
     return key;
 44  
   }
 45  
 
 46  
   public long getValue() {
 47  206
     return value.get();
 48  
   }
 49  
 
 50  
   public void increment(long value) {
 51  40020
     this.value.addAndGet(value);
 52  40020
   }
 53  
 
 54  
   @Override
 55  
   public boolean equals(Object object) {
 56  7
     if ((this == object)) {
 57  5
       return true;
 58  
     }
 59  2
     if (!(object instanceof StatisticEntry)) {
 60  0
       return false;
 61  
     }
 62  2
     StatisticEntry entry = (StatisticEntry) object;
 63  2
     return new EqualsBuilder().append(this.getKey(), entry.getKey()).isEquals();
 64  
   }
 65  
 
 66  
   @Override
 67  
   public int hashCode() {
 68  25
     return key.hashCode();
 69  
   }
 70  
 
 71  
   @Override
 72  
   public String toString() {
 73  0
     return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
 74  
   }
 75  
   
 76  
 }