KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.HashMap JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import org.apache.commons.lang.builder.EqualsBuilder;
25 import org.apache.commons.lang.builder.HashCodeBuilder;
26 import org.apache.commons.lang.builder.ReflectionToStringBuilder;
27 import org.apache.commons.lang.builder.ToStringStyle;
28
29 /**
30  * @author tierney.matt
31  */

32 public class Statistic implements Serializable JavaDoc {
33   private final String JavaDoc type;
34   private final Map JavaDoc entriesMap = new HashMap JavaDoc();
35
36   public Statistic(String JavaDoc type) {
37     this.type = type;
38   }
39   
40   public String JavaDoc getType() {
41     return type;
42   }
43   
44   public void clear() {
45     entriesMap.clear();
46   }
47   
48   public Set JavaDoc getEntries() {
49     return new HashSet JavaDoc(entriesMap.values());
50   }
51   
52   public void addEntry(StatisticEntry statEntry) {
53     if (statEntry == null) {
54       throw new IllegalArgumentException JavaDoc("Statistic Entry cannot be null");
55     }
56     entriesMap.put(statEntry.getKey(), statEntry);
57   }
58   
59   public StatisticEntry getEntry() {
60     return getEntry(type);
61   }
62   
63   public StatisticEntry getEntry(Object JavaDoc entryKey) {
64     return (StatisticEntry) entriesMap.get(entryKey);
65   }
66   
67   public boolean equals(Object JavaDoc object) {
68     if ( (this == object ) ) { return true; }
69     if ( !(object instanceof Statistic) ) { return false; }
70     Statistic entry = (Statistic) object;
71     return new EqualsBuilder().append(this.getType(), entry.getType()).isEquals();
72   }
73
74   public int hashCode() {
75     return new HashCodeBuilder().append(getType()).toHashCode();
76   }
77   
78   public String JavaDoc toString() {
79     return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
80   }
81 }
82
Popular Tags