From: Sasa M. <sa...@us...> - 2004-07-19 15:00:13
|
Update of /cvsroot/jrobin/src/org/jrobin/cmd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13171/org/jrobin/cmd Modified Files: RrdXportCmd.java TimeParser.java TimeSpec.java Log Message: Added javadoc Index: TimeSpec.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/TimeSpec.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimeSpec.java 12 Jul 2004 13:35:17 -0000 1.1 --- TimeSpec.java 19 Jul 2004 15:00:03 -0000 1.2 *************** *** 33,40 **** import java.util.Calendar; ! class TimeSpec { ! public static final int TYPE_ABSOLUTE = 0; ! public static final int TYPE_START = 1; ! public static final int TYPE_END = 2; int type = TYPE_ABSOLUTE; --- 33,44 ---- import java.util.Calendar; ! /** ! * Simple class to represent time obtained by parsing at-style date specification (described ! * in detail on the rrdfetch man page. See javadoc {@link TimeParser} for more information. ! */ ! public class TimeSpec { ! static final int TYPE_ABSOLUTE = 0; ! static final int TYPE_START = 1; ! static final int TYPE_END = 2; int type = TYPE_ABSOLUTE; *************** *** 47,51 **** TimeSpec context; ! public TimeSpec(String dateString) { this.dateString = dateString; } --- 51,55 ---- TimeSpec context; ! TimeSpec(String dateString) { this.dateString = dateString; } *************** *** 87,91 **** } ! long getTimestamp() throws RrdException { return Util.getTimestamp(getTime()); } --- 91,105 ---- } ! /** ! * Returns the corresponding timestamp (seconds since Epoch). Example:<p> ! * <pre> ! * TimeParser p = new TimeParser("now-1day"); ! * TimeSpec ts = p.parse(); ! * System.out.println("Timestamp was: " + ts.getTimestamp(); ! * </pre> ! * @return Timestamp (in seconds, no milliseconds) ! * @throws RrdException Thrown if this TimeSpec object does not represent absolute time. ! */ ! public long getTimestamp() throws RrdException { return Util.getTimestamp(getTime()); } *************** *** 99,103 **** } ! static GregorianCalendar[] getTimes(TimeSpec spec1, TimeSpec spec2) throws RrdException { if(spec1.type == TYPE_START || spec2.type == TYPE_END) { throw new RrdException("Recursive time specifications not allowed"); --- 113,132 ---- } ! /** ! * Use this static method to resolve relative time references and obtain the corresponding ! * GregorianCalendar objects. Example:<p> ! * <pre> ! * TimeParser pStart = new TimeParser("now-1month"); // starting time ! * TimeParser pEnd = new TimeParser("start+1week"); // ending time ! * TimeSpec specStart = pStart.parse(); ! * TimeSpec specEnd = pEnd.parse(); ! * GregorianCalendar[] gc = TimeSpec.getTimes(specStart, specEnd); ! * </pre> ! * @param spec1 Starting time specification ! * @param spec2 Ending time specification ! * @return ! * @throws RrdException Thrown if relative time references cannot be resolved ! */ ! public static GregorianCalendar[] getTimes(TimeSpec spec1, TimeSpec spec2) throws RrdException { if(spec1.type == TYPE_START || spec2.type == TYPE_END) { throw new RrdException("Recursive time specifications not allowed"); *************** *** 111,115 **** } ! static long[] getTimestamps(TimeSpec spec1, TimeSpec spec2) throws RrdException { GregorianCalendar[] gcs = getTimes(spec1, spec2); return new long[] { --- 140,159 ---- } ! /** ! * Use this static method to resolve relative time references and obtain the corresponding ! * timestamps (seconds since epoch). Example:<p> ! * <pre> ! * TimeParser pStart = new TimeParser("now-1month"); // starting time ! * TimeParser pEnd = new TimeParser("start+1week"); // ending time ! * TimeSpec specStart = pStart.parse(); ! * TimeSpec specEnd = pEnd.parse(); ! * long[] ts = TimeSpec.getTimestamps(specStart, specEnd); ! * </pre> ! * @param spec1 Starting time specification ! * @param spec2 Ending time specification ! * @return ! * @throws RrdException Thrown if relative time references cannot be resolved ! */ ! public static long[] getTimestamps(TimeSpec spec1, TimeSpec spec2) throws RrdException { GregorianCalendar[] gcs = getTimes(spec1, spec2); return new long[] { Index: RrdXportCmd.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/RrdXportCmd.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RrdXportCmd.java 16 Jul 2004 07:40:48 -0000 1.2 --- RrdXportCmd.java 19 Jul 2004 15:00:03 -0000 1.3 *************** *** 80,84 **** ExportData data = export.fetch(maxRows); ! System.out.println(data.exportXml()); return data; --- 80,84 ---- ExportData data = export.fetch(maxRows); ! println(data.exportXml()); return data; *************** *** 133,136 **** --- 133,137 ---- def.export(tokens[1], tokens[2]); } + /* public static void main(String[] args) throws Exception { Index: TimeParser.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/cmd/TimeParser.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TimeParser.java 12 Jul 2004 13:35:17 -0000 1.1 --- TimeParser.java 19 Jul 2004 15:00:03 -0000 1.2 *************** *** 36,41 **** import java.io.IOException; ! class TimeParser { ! public static final int PREVIOUS_OP = -1; TimeToken token; --- 36,46 ---- import java.io.IOException; ! /** ! * Class which parses at-style time specification (describided in detail on the rrdfetch man page), ! * used in all RRDTool commands. This code is in most parts just a java port of Tobi's parsetime.c ! * code. ! */ ! public class TimeParser { ! private static final int PREVIOUS_OP = -1; TimeToken token; *************** *** 46,49 **** --- 51,59 ---- int prev_multiplier = -1; + /** + * Constructs TimeParser instance from the given input string. + * @param dateString at-style time specification (read rrdfetch man page + * for the complete explanation) + */ public TimeParser(String dateString) { scanner = new TimeScanner(dateString); *************** *** 295,299 **** } ! TimeSpec parse() throws RrdException { long now = Util.getTime(); int hr = 0; --- 305,314 ---- } ! /** ! * Parses the input string specified in the constructor. ! * @return Object representing parsed date/time. ! * @throws RrdException Thrown if the date string cannot be parsed. ! */ ! public TimeSpec parse() throws RrdException { long now = Util.getTime(); int hr = 0; *************** *** 403,406 **** --- 418,422 ---- } + /* public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); *************** *** 417,419 **** --- 433,436 ---- } } + */ } \ No newline at end of file |