MetricValuePredefinedFormat.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.experiment.metric;
00002 
00003 import java.util.Formatter;
00004 
00005 
00006 /**********************************************************
00007  * 
00008  * @author laksonoadhianto
00009  *
00010  **********************************************************/
00011 public class MetricValuePredefinedFormat implements IMetricValueFormat {
00012     private String format;
00013     
00014     public MetricValuePredefinedFormat(String sFormat) {
00015         this.format = sFormat;
00016     }
00017     
00018     
00019     public String format(MetricValue value) {
00020         Formatter format_str = new Formatter();
00021         try {
00022             // --------------------------------------------------------------------------------
00023             // temporary bug fix: if the format is hexadecimal (%x), the input value
00024             //  has to be either an integer or a long number. Since we store by default
00025             //  the value to be "double", we should convert it to long (integer is too small)
00026             // 
00027             // for next release, we need to have a universal metric value type that can 
00028             //  represent any possible value such as double, int, long, hex, ...
00029             // --------------------------------------------------------------------------------
00030 /*          if (format.indexOf("%x")>=0) {
00031                 long valong = (long) value.getValue();
00032                 format_str = format_str.format(format, valong);
00033                 
00034             } else*/ 
00035             {
00036                 format_str = format_str.format(format, MetricValue.getValue(value));
00037             }
00038 
00039             if (format_str != null) {
00040                 return format_str.toString();
00041             } else {
00042                 return "";
00043             }
00044         } catch (java.util.IllegalFormatConversionException e) {
00045             System.err.println("Illegal format conversion: " + format.toString() + "\tFrom value: " + MetricValue.getValue(value));
00046             e.printStackTrace();
00047         }
00048         return "";
00049     }
00050 
00051     /****
00052      * get the custom format
00053      * 
00054      * @return the format
00055      */
00056     public String getFormat() {
00057         return format;
00058     }
00059 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1