Author: chatellier Date: 2009-09-02 10:39:54 +0000 (Wed, 02 Sep 2009) New Revision: 2570 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java Log: Rename "getInfomation" > "getInformation" Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java 2009-09-02 09:13:35 UTC (rev 2569) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java 2009-09-02 10:39:54 UTC (rev 2570) @@ -51,24 +51,32 @@ */ public class SimulationInformation { - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimulationInformation.class); + /** Class logger. */ + private static Log log = LogFactory.getLog(SimulationInformation.class); - static private final String START_SIMULATION = "simulationStart"; - static private final String END_SIMULATION = "simulationEnd"; - static private final String EXPORT_TIME = "exportTime"; - static private final String OTHER_INFO = "otherInfo"; - static private final String STATISTIC = "statistic"; - static private final String OPTIMIZATION_USAGE = "optimizationUsage"; - static private final String SIMULATION_EXCEPTION = "exception"; + private static final String START_SIMULATION = "simulationStart"; + private static final String END_SIMULATION = "simulationEnd"; + private static final String EXPORT_TIME = "exportTime"; + private static final String RULE_TIME = "ruleTime"; + private static final String OTHER_INFO = "otherInfo"; + private static final String STATISTIC = "statistic"; + private static final String OPTIMIZATION_USAGE = "optimizationUsage"; + private static final String SIMULATION_EXCEPTION = "exception"; - static private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss"); + private static final String RULE_TIME_INIT = "init"; + private static final String RULE_TIME_PRE = "pre"; + private static final String RULE_TIME_POST = "post"; + private static final SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy.MM.dd HH:mm:ss"); + protected Properties info = new Properties(); protected File file = null; - + /** + * Constructor. * + * @param file simulation information output file */ public SimulationInformation(File file) { this.file = file; @@ -79,32 +87,38 @@ reader.close(); } catch (IOException eee) { if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.read.simulation", file.getPath()), eee); + log.warn(_("isisfish.error.read.simulation", file + .getPath()), eee); } } } } - + /* * @see java.lang.Object#toString() */ @Override public String toString() { String result = "Simulation Information:\n"; - result += "Start: " + dateFormat.format(getSimulationStart()) + " End: " + dateFormat.format(getSimulationEnd()) + "\n"; + result += "Start: " + dateFormat.format(getSimulationStart()) + + " End: " + dateFormat.format(getSimulationEnd()) + "\n"; Map<String, Long> exportTime = getExportTime(); if (exportTime.size() > 0) { result += "Export time:\n"; for (Map.Entry<String, Long> entry : exportTime.entrySet()) { - result += "\t" + entry.getKey() + " : " + DurationFormatUtils.formatDuration(entry.getValue(), "s'.'S") + "\n"; + result += "\t" + + entry.getKey() + + " : " + + DurationFormatUtils.formatDuration(entry.getValue(), + "s'.'S") + "\n"; } } - - String info = getInfomation(); + + String info = getInformation(); if (info != null && !"".equals(info)) { result += "Information:\n" + info + "\n"; } - + String v = getStatistic(); if (v != null) { result += "Statistic:\n" + v + "\n"; @@ -120,7 +134,7 @@ return result; } - + protected void store() { try { FileWriter writer = new FileWriter(file); @@ -128,19 +142,21 @@ writer.close(); } catch (IOException eee) { if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.write.simulation", file.getPath()), eee); + log.warn(_("isisfish.error.write.simulation", file.getPath()), + eee); } } } - + protected void setInfo(String key, String value) { info.setProperty(key, value); store(); } - + /** - * Get the date of simulation start - * @return + * Get the date of simulation start. + * + * @return simulation start date */ public Date getSimulationStart() { String d = info.getProperty(START_SIMULATION); @@ -159,11 +175,11 @@ } return result; } - + public void setSimulationStart(Date date) { setInfo(START_SIMULATION, dateFormat.format(date)); } - + /** * Get the date of simulation start * @return @@ -185,11 +201,11 @@ } return result; } - + public void setSimulationEnd(Date date) { setInfo(END_SIMULATION, dateFormat.format(date)); } - + /** * get all export time in map * @return @@ -218,7 +234,7 @@ } return result; } - + public long getExportTime(String exportName) { String t = info.getProperty(EXPORT_TIME + "." + exportName); long result = 0; @@ -233,56 +249,73 @@ } return result; } - + public void addExportTime(String exportName, long time) { setInfo(EXPORT_TIME + "." + exportName, String.valueOf(time)); } - + public String getStatistic() { String result = info.getProperty(STATISTIC); return result; - } - + } + public void setStatistic(String v) { setInfo(STATISTIC, v); } - + public String getOptimizationUsage() { String result = info.getProperty(OPTIMIZATION_USAGE); return result; } - + public void setOptimizationUsage(String v) { - setInfo(OPTIMIZATION_USAGE, v); + setInfo(OPTIMIZATION_USAGE, v); } - + public String getException() { String result = info.getProperty(SIMULATION_EXCEPTION); return result; } - + public void setException(Throwable eee) { StringWriter w = new StringWriter(); PrintWriter pw = new PrintWriter(w); eee.printStackTrace(pw); String v = w.getBuffer().toString(); - setInfo(SIMULATION_EXCEPTION, v); + setInfo(SIMULATION_EXCEPTION, v); } - + + /** + * Return {@code true} if an exception has been set. + * + * @return {@code true} if there is an exception + */ public boolean hasError() { boolean result = getException() != null && getException().length() > 0; return result; } - + + /** + * @deprecated since 3.2.0.5, use {@link #getInformation()} instead + */ public String getInfomation() { + return getInformation(); + } + + /** + * Get other information. + * + * @return other information + */ + public String getInformation() { String result = info.getProperty(OTHER_INFO); if (result == null) { result = ""; } return result; } - + public void addInformation(String value) { - setInfo(OTHER_INFO, getInfomation() + value + "\n"); + setInfo(OTHER_INFO, getInformation() + value + "\n"); } }
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org