Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 32 33 package com.jeantessier.metrics; 34 35 import org.apache.oro.text.perl.*; 36 37 import com.jeantessier.text.*; 38 39 public abstract class MeasurementBase implements Measurement { 40 private static final Perl5Util perl = new Perl5Util(new MaximumCapacityPatternCache()); 41 42 protected static Perl5Util perl() { 43 return perl; 44 } 45 46 private MeasurementDescriptor descriptor = null; 47 private Metrics context = null; 48 49 private boolean cached = false; 50 private boolean empty = true; 51 52 public MeasurementBase(MeasurementDescriptor descriptor, Metrics context, String initText) { 53 this.descriptor = descriptor; 54 this.context = context; 55 } 56 57 public MeasurementDescriptor getDescriptor() { 58 return descriptor; 59 } 60 61 public Metrics getContext() { 62 return context; 63 } 64 65 69 protected boolean isCached() { 70 return cached; 71 } 72 73 79 protected void setCached(boolean cached) { 80 this.cached = cached && getDescriptor().isCached(); 81 } 82 83 public boolean isEmpty() { 84 return empty; 85 } 86 87 protected void setEmpty(boolean empty) { 88 this.empty = empty; 89 } 90 91 public String getShortName() { 92 return getDescriptor().getShortName(); 93 } 94 95 public String getLongName() { 96 return getDescriptor().getLongName(); 97 } 98 99 public Number getValue() { 100 return new Double (compute()); 101 } 102 103 public int intValue() { 104 return (int) compute(); 105 } 106 107 public long longValue() { 108 return (long) compute(); 109 } 110 111 public float floatValue() { 112 return (float) compute(); 113 } 114 115 public double doubleValue() { 116 return compute(); 117 } 118 119 public boolean isInRange() { 120 boolean result = true; 121 122 if (getDescriptor() != null) { 123 Comparable lowerThreshold = getDescriptor().getLowerThreshold(); 124 Comparable upperThreshold = getDescriptor().getUpperThreshold(); 125 126 if (result && lowerThreshold != null) { 127 if (lowerThreshold instanceof String ) { 128 try { 129 result = Double.parseDouble((String ) lowerThreshold) <= compute(); 130 } catch (NumberFormatException ex) { 131 } 133 } else if (lowerThreshold instanceof Number ) { 134 result = ((Number ) lowerThreshold).doubleValue() <= compute(); 135 } else { 136 result = lowerThreshold.compareTo(getValue()) <= 0; 137 } 138 } 139 140 if (result && upperThreshold != null) { 141 if (upperThreshold instanceof String ) { 142 try { 143 result = Double.parseDouble((String ) upperThreshold) >= compute(); 144 } catch (NumberFormatException ex) { 145 } 147 } else if (upperThreshold instanceof Number ) { 148 result = ((Number ) upperThreshold).doubleValue() >= compute(); 149 } else { 150 result = upperThreshold.compareTo(getValue()) >= 0; 151 } 152 } 153 } 154 155 return result; 156 } 157 158 public void add(Object object) { 159 } 161 162 public void add(int i) { 163 } 165 166 public void add(long l) { 167 } 169 170 public void add(float f) { 171 } 173 174 public void add(double d) { 175 } 177 178 protected abstract double compute(); 179 180 public String toString() { 181 return getValue().toString(); 182 } 183 } 184
| Popular Tags
|