MetricValue.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015 package edu.rice.cs.hpc.data.experiment.metric;
00016
00017
00018 import edu.rice.cs.hpc.data.util.*;
00019
00020
00021
00022
00024
00026
00034 public final class MetricValue
00035 {
00036
00038 protected float value;
00039
00041 protected float annotation;
00042
00043 protected byte flags;
00044
00045 protected static final byte VALUE_IS_AVAILABLE = 1;
00046 protected static final byte ANNOTATION_IS_AVAILABLE = 2;
00047
00049 public static final MetricValue NONE = new MetricValue(-1);
00050
00051
00052
00053
00055
00057
00058
00059
00060
00061
00062
00063
00064
00065 public MetricValue()
00066 {
00067 setAvailable(this, false);
00068 setAnnotationAvailable(this, false);
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078 public MetricValue(double value, double annotation)
00079 {
00080 setValue(this, value);
00081 setAnnotationValue(this, ((float)annotation));
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091 public MetricValue(double value)
00092 {
00093 setValue(this, value);
00094 setAvailable(this, true);
00095 setAnnotationAvailable(this, false);
00096 }
00097
00098
00099
00101
00103
00104
00105
00106
00107
00108 private static boolean getAvailable(MetricValue m)
00109 {
00110 boolean available = (m.flags & VALUE_IS_AVAILABLE) == VALUE_IS_AVAILABLE;
00111 return available;
00112 }
00113
00114 private static void setAvailable(MetricValue m, boolean status)
00115 {
00116 if (status) {
00117 m.flags |= VALUE_IS_AVAILABLE;
00118 } else {
00119 m.flags &= ~VALUE_IS_AVAILABLE;
00120 }
00121 }
00122
00123
00124 private static boolean getAnnotationAvailable(MetricValue m)
00125 {
00126 boolean available = (m.flags & ANNOTATION_IS_AVAILABLE) == ANNOTATION_IS_AVAILABLE;
00127 return available;
00128 }
00129
00130 public static void setAnnotationAvailable(MetricValue m, boolean status)
00131 {
00132 if (status) {
00133 m.flags |= ANNOTATION_IS_AVAILABLE;
00134 } else {
00135 m.flags &= ~ANNOTATION_IS_AVAILABLE;
00136 }
00137 }
00138
00139
00140 public float getValue()
00141 {
00142 boolean available = (flags & VALUE_IS_AVAILABLE) == VALUE_IS_AVAILABLE;
00143 Dialogs.Assert(available, "MetricValue::getValue");
00144 return this.value;
00145 }
00146
00147
00148
00149
00150
00151 public static boolean isAvailable(MetricValue m)
00152 {
00153 return ( (m != MetricValue.NONE) && getAvailable(m) && (m.value != 0.0) );
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 public static float getValue(MetricValue m)
00164 {
00165 return m.getValue();
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175 public static void setValue(MetricValue m, double value)
00176 {
00177 setAvailable(m, true);
00178 m.value = (float) value;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188 public static boolean isAnnotationAvailable(MetricValue m)
00189 {
00190 return (m != MetricValue.NONE) && getAnnotationAvailable(m);
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200 public static float getAnnotationValue(MetricValue m)
00201 {
00202 return m.annotation;
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212 public static void setAnnotationValue(MetricValue m, double annotation)
00213 {
00214 setAnnotationAvailable(m, true);
00215 m.annotation = (float) annotation;
00216 }
00217
00218
00219 public static void setAnnotationValue(MetricValue m, float annotation)
00220 {
00221 setAnnotationAvailable(m, true);
00222 m.annotation = annotation;
00223 }
00224
00225
00226 public static boolean isZero(MetricValue m)
00227 {
00228 if (m != MetricValue.NONE) {
00229 return ( Double.compare(0.0, m.value) == 0 );
00230 }
00231 return true;
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 public static int compareTo(MetricValue left, MetricValue right)
00243 {
00244 int result;
00245
00246 if( MetricValue.isAvailable(left) && MetricValue.isAvailable(right) )
00247 {
00248 if( left.value > right.value )
00249 result = +1;
00250 else if( left.value < right.value )
00251 result = -1;
00252 else
00253 result = 0;
00254 }
00255 else if( MetricValue.isAvailable(left) )
00256 result = +1;
00257 else if( MetricValue.isAvailable(right) )
00258 result = -1;
00259 else
00260 result = 0;
00261
00262 return result;
00263 }
00264
00265
00266 public String toString()
00267 {
00268 return value + " ( " + annotation + " ) ";
00269 }
00270
00271
00272
00273
00274
00275
00276 public MetricValue duplicate()
00277 {
00278 MetricValue mv = new MetricValue(value, annotation);
00279 mv.flags = flags;
00280 return mv;
00281 }
00282 }