1 16 package net.sf.dozer.util.mapping.stats; 17 18 import java.io.Serializable ; 19 import java.util.HashMap ; 20 import java.util.HashSet ; 21 import java.util.Map ; 22 import java.util.Set ; 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 32 public class Statistic implements Serializable { 33 private final String type; 34 private final Map entriesMap = new HashMap (); 35 36 public Statistic(String type) { 37 this.type = type; 38 } 39 40 public String getType() { 41 return type; 42 } 43 44 public void clear() { 45 entriesMap.clear(); 46 } 47 48 public Set getEntries() { 49 return new HashSet (entriesMap.values()); 50 } 51 52 public void addEntry(StatisticEntry statEntry) { 53 if (statEntry == null) { 54 throw new IllegalArgumentException ("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 entryKey) { 64 return (StatisticEntry) entriesMap.get(entryKey); 65 } 66 67 public boolean equals(Object 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 toString() { 79 return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE); 80 } 81 } 82 | Popular Tags |