📄 summarymessagewriterdecorator.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: SummaryMessageWriterDecorator.java,v 1.2 2003/11/07 21:34:22 per_nyfelt Exp $package org.ozoneDB.tools.OPP.message;import org.ozoneDB.tools.OPP.message.MessageWriter;import java.text.Format;import java.text.NumberFormat;import java.util.Stack;public class SummaryMessageWriterDecorator implements MessageWriter { private class Summary { private int warnings; private int errors; private long startTime; private String object = ""; public int getWarnings() { return warnings; } public int getErrors() { return errors; } public long getStartTime() { return startTime; } public String getObject() { return object; } public void incWarnings() { warnings++; } public void incErrors() { errors++; } public Summary(String object) { startTime = System.currentTimeMillis(); this.object = object; } public long getTotalTime() { return System.currentTimeMillis() - startTime; } public void addSummary(Summary summary) { if (summary != null) { warnings += summary.warnings; errors += summary.errors; } } } private MessageWriter listener; private Stack summaries = new Stack(); private Summary currentSummary; private StringBuffer indent = new StringBuffer(); private void updateIndent(int count) { indent.delete(0, indent.length()); for (int i = 0; i < count; i++) { indent.append(" "); } } public SummaryMessageWriterDecorator(MessageWriter listener) { this.listener = listener; } public void startGeneration(String object) { info("Begin " + object + "..."); currentSummary = new Summary(object); summaries.push(currentSummary); updateIndent(summaries.size()); } public void error(String message) { currentSummary.incErrors(); listener.error(indent + message); } public void warning(String message) { currentSummary.incWarnings(); listener.warning(indent + message); } public void warning(String filename, int row, String message) { currentSummary.incWarnings(); listener.warning(indent + filename, row, message); } public void info(String message) { listener.info(indent + message); } public void debug(String message) { listener.debug(indent + message); } public void endGeneration() { Summary tmpSummary = (Summary) summaries.pop(); tmpSummary.addSummary(currentSummary); currentSummary = tmpSummary; updateIndent(summaries.size()); if (summaries.size() == 0) { double generationTime = currentSummary.getTotalTime(); generationTime /= 1000; Format fmt = NumberFormat.getInstance(); info("End " + currentSummary.getObject() + " generated in " + fmt.format(new Double(generationTime)) + " seconds."); info("Generation completed with " + currentSummary.getWarnings() + " warnings and " + currentSummary.getErrors() + " errors"); } else { info("End " + currentSummary.object); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -