1 32 33 package com.jeantessier.metrics; 34 35 import java.util.*; 36 37 import org.apache.log4j.*; 38 39 55 public class NameListMeasurement extends MeasurementBase implements CollectionMeasurement { 56 private Collection values; 57 58 public NameListMeasurement(MeasurementDescriptor descriptor, Metrics context, String initText) { 59 super(descriptor, context, initText); 60 61 if (initText != null) { 62 if (initText.trim().equalsIgnoreCase("list")) { 63 values = new LinkedList(); 64 } else if (initText.trim().equalsIgnoreCase("set")) { 65 values = new HashSet(); 66 } else { 67 Logger.getLogger(getClass()).debug("Cannot initialize with \"" + initText + "\", using default value of SET instead"); 68 values = new HashSet(); 69 } 70 } else { 71 Logger.getLogger(getClass()).debug("Cannot initialize with null text, using default value of SET instead"); 72 values = new HashSet(); 73 } 74 } 75 76 public void add(Object object) { 77 values.add(object); 78 } 79 80 public void accept(MeasurementVisitor visitor) { 81 visitor.visitNameListMeasurement(this); 82 } 83 84 public Number getValue() { 85 return new Integer (values.size()); 86 } 87 88 public boolean isEmpty() { 89 return values.isEmpty(); 90 } 91 92 protected double compute() { 93 return values.size(); 94 } 95 96 public Collection getValues() { 97 return Collections.unmodifiableCollection(values); 98 } 99 } 100 | Popular Tags |