List of usage examples for org.joda.time.format PeriodFormatter printTo
public void printTo(Writer out, ReadablePeriod period) throws IOException
From source file:net.sf.jacclog.service.analyzer.commands.internal.AnalyzeLogEntriesShellCommand.java
License:Apache License
private void analyzeEntries() { if (service != null) { final DateTimeFormatter format = DateTimeFormat.forPattern("yyyyMMdd"); final DateTime from = format.parseDateTime(this.from); final DateTime to = (this.to != null) ? format.parseDateTime(this.to) : from.plusDays(1); final Interval interval = new Interval(from, to); final Period period = interval.toPeriod(); final StringBuffer buffer = new StringBuffer(); buffer.append("Analyse the log entries from '"); buffer.append(from.toString()).append('\''); buffer.append(" to '").append(to); // print the period final String space = " "; buffer.append("'. The period includes "); final PeriodFormatter dateFormat = new PeriodFormatterBuilder().appendYears() .appendSuffix(" year", " years").appendSeparator(space).appendMonths() .appendSuffix(" month", " months").appendSeparator(space).appendWeeks() .appendSuffix(" week", " weeks").appendSeparator(space).appendDays() .appendSuffix(" day", " days").appendSeparator(space).appendHours() .appendSuffix(" hour", " hours").appendSeparator(space).appendMinutes() .appendSuffix(" minute", " minutes").appendSeparator(space).toFormatter(); dateFormat.printTo(buffer, period); buffer.append('.'); System.out.println(buffer.toString()); final long maxResults = service.count(interval); if (maxResults > 0) { int maxCount = 0; if (proceed(maxResults)) { final long startTime = System.currentTimeMillis(); final LogEntryAnalysisResult result = analyzerService.analyze(interval).toResult(); final Map<UserAgentInfo, AtomicInteger> stats = result.getUserAgentInfos(); System.out.println("User agent information count: " + stats.size()); String name;//from w w w.j av a 2s . com String osName; int count; for (final Entry<UserAgentInfo, AtomicInteger> entry : stats.entrySet()) { name = entry.getKey().getName(); osName = entry.getKey().getOsName(); count = entry.getValue().get(); maxCount += count; System.out.println(name + " (" + osName + ") \t" + count); } System.out.println("Sum: " + maxCount); final long elapsedTime = System.currentTimeMillis() - startTime; final Period p = new Period(elapsedTime); System.out.println("Total processing time: " + p.toString(FORMATTER)); } } else { System.out.println("There is nothing to analyze."); } } }