KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > stats > StatisticEntry


1 /*
2  * Copyright 2005-2007 the original author or authors.
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 net.sf.dozer.util.mapping.stats;
17
18 import java.io.Serializable JavaDoc;
19
20 import org.apache.commons.lang.builder.EqualsBuilder;
21 import org.apache.commons.lang.builder.HashCodeBuilder;
22 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
23 import org.apache.commons.lang.builder.ToStringStyle;
24
25 /**
26  * @author tierney.matt
27  */

28 public class StatisticEntry implements Serializable JavaDoc {
29   private final Object JavaDoc key;
30   private long value = 0;
31
32   public StatisticEntry(Object JavaDoc key) {
33     this.key = key;
34   }
35
36   public Object JavaDoc getKey() {
37     return key;
38   }
39
40   public long getValue() {
41     return value;
42   }
43
44   public void increment() {
45       increment(1);
46   }
47
48   public synchronized void increment(long value) {
49     this.value += value;
50   }
51   
52   public boolean equals(Object JavaDoc object) {
53     if ( (this == object ) ) { return true; }
54     if ( !(object instanceof StatisticEntry) ) { return false; }
55     StatisticEntry entry = (StatisticEntry) object;
56     return new EqualsBuilder().append(this.getKey(), entry.getKey()).isEquals();
57   }
58
59   public int hashCode() {
60     return new HashCodeBuilder().append(getKey()).toHashCode();
61   }
62   
63   public String JavaDoc toString() {
64     return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
65   }
66 }
67
Popular Tags