Fix javadoc warnings in DurationStatisticsTracker
[yangtools.git] / common / util / src / main / java / org / opendaylight / yangtools / util / DurationStatisticsTracker.java
index 10cb39ce7571f6b629c80944d593795a9540a27c..b8bbe346a381343c48fd90af5f2d3fcd40eee865 100644 (file)
@@ -11,6 +11,7 @@ import static java.util.concurrent.TimeUnit.MICROSECONDS;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static java.util.concurrent.TimeUnit.NANOSECONDS;
 import static java.util.concurrent.TimeUnit.SECONDS;
+
 import com.google.common.annotations.Beta;
 import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
@@ -37,8 +38,7 @@ public abstract class DurationStatisticsTracker {
     }
 
     /**
-     * Create a concurrent {@link DurationStatisticsTracker}, which performs well
-     * in very contended environments.
+     * Create a concurrent {@link DurationStatisticsTracker}, which performs well in very contended environments.
      *
      * @return A new instance.
      */
@@ -47,8 +47,7 @@ public abstract class DurationStatisticsTracker {
     }
 
     /**
-     * Create a synchronized {@link DurationStatisticsTracker}, which performs well
-     * in non-contended environments.
+     * Create a synchronized {@link DurationStatisticsTracker}, which performs well in non-contended environments.
      *
      * @return A new instance.
      */
@@ -59,21 +58,21 @@ public abstract class DurationStatisticsTracker {
     /**
      * Add a duration to track.
      *
-     * @param duration
-     *            non-negative duration in nanoseconds.
+     * @param duration non-negative duration in nanoseconds.
      */
     public abstract void addDuration(long duration);
 
     /**
      * Returns the average duration in nanoseconds.
+     *
+     * @return average duration in nanoseconds.
      */
     public abstract double getAverageDuration();
 
     /**
      * Returns the total number of tracked durations.
      *
-     * @return Total number of measurements accumulated since last
-     *         {@link #reset()}.
+     * @return Total number of measurements accumulated since last {@link #reset()}.
      */
     public abstract long getTotalDurations();
 
@@ -82,22 +81,10 @@ public abstract class DurationStatisticsTracker {
      */
     public abstract void reset();
 
-    /**
-     * Get the shortest recorded duration and the time when it was recorded.
-     *
-     * @return Duration and timestamp.
-     */
-    protected abstract DurationWithTime getShortest();
-
-    /**
-     * Get the longest recorded duration and the time when it was recorded.
-     *
-     * @return Duration and timestamp.
-     */
-    protected abstract DurationWithTime getLongest();
-
     /**
      * Returns the longest duration in nanoseconds.
+     *
+     * @return the longest duration in nanoseconds.
      */
     public final long getLongestDuration() {
         return getDuration(getLongest());
@@ -105,30 +92,37 @@ public abstract class DurationStatisticsTracker {
 
     /**
      * Returns the shortest duration in nanoseconds.
+     *
+     * @return the shortest duration in nanoseconds.
      */
     public final long getShortestDuration() {
         return getDuration(getShortest());
     }
 
     /**
-     * Returns the average duration as a displayable String with units, e.g.
-     * "12.34 ms".
+     * Returns the average duration as a displayable String with units, e.g. {@code 12.34 ms}.
+     *
+     * @return the average duration in human-readable form.
      */
     public final String getDisplayableAverageDuration() {
         return formatDuration(getAverageDuration(), null);
     }
 
     /**
-     * Returns the longest duration as a displayable String with units and the
-     * date/time at which it occurred, e.g. "12.34 ms at 08/02/2014 12:30:24".
+     * Returns the longest duration as a displayable String with units and the date/time at which it occurred, e.g.
+     * {@code 12.34 ms at 08/02/2014 12:30:24}.
+     *
+     * @return The longest duration and when it has occurred in human-readable form.
      */
     public final String getDisplayableLongestDuration() {
         return formatDuration(getLongest());
     }
 
     /**
-     * Returns the shortest duration as a displayable String with units and the
-     * date/time at which it occurred, e.g. "12.34 ms at 08/02/2014 12:30:24".
+     * Returns the shortest duration as a displayable String with units and the date/time at which it occurred, e.g.
+     * {@code 12.34 ms at 08/02/2014 12:30:24}.
+     *
+     * @return The shortest duration and when it has occurred in human-readable form.
      */
     public final String getDisplayableShortestDuration() {
         return formatDuration(getShortest());
@@ -136,6 +130,8 @@ public abstract class DurationStatisticsTracker {
 
     /**
      * Returns the time stamp of the longest duration.
+     *
+     * @return the time stamp of the longest duration.
      */
     public final long getTimeOfLongestDuration() {
         return getTimeMillis(getLongest());
@@ -143,14 +139,29 @@ public abstract class DurationStatisticsTracker {
 
     /**
      * Returns the time stamp of the shortest duration.
+     *
+     * @return the time stamp of the shortest duration.
      */
     public final long getTimeOfShortestDuration() {
         return getTimeMillis(getShortest());
     }
 
     /**
-     * Returns formatted value of number, e.g. "12.34". Always is used dot as
-     * decimal separator.
+     * Get the shortest recorded duration and the time when it was recorded.
+     *
+     * @return Duration and timestamp.
+     */
+    abstract DurationWithTime getShortest();
+
+    /**
+     * Get the longest recorded duration and the time when it was recorded.
+     *
+     * @return Duration and timestamp.
+     */
+    abstract DurationWithTime getLongest();
+
+    /**
+     * Returns formatted value of number, e.g. "12.34". Always is used dot as decimal separator.
      */
     private static synchronized String formatDecimalValue(final double value) {
         return DECIMAL_FORMAT.format(value);
@@ -169,9 +180,7 @@ public abstract class DurationStatisticsTracker {
         final double value = duration / NANOSECONDS.convert(1, unit);
 
         final StringBuilder sb = new StringBuilder();
-        sb.append(formatDecimalValue(value));
-        sb.append(' ');
-        sb.append(abbreviate(unit));
+        sb.append(formatDecimalValue(value)).append(' ').append(abbreviate(unit));
 
         if (timeStamp != null) {
             sb.append(String.format(" at %1$tD %1$tT", new Date(timeStamp)));
@@ -181,11 +190,10 @@ public abstract class DurationStatisticsTracker {
     }
 
     private static String formatDuration(final DurationWithTime current) {
-        if (current != null) {
-            return formatDuration(current.getDuration(), current.getTimeMillis());
-        } else {
+        if (current == null) {
             return formatDuration(0, null);
         }
+        return formatDuration(current.getDuration(), current.getTimeMillis());
     }
 
     private static TimeUnit chooseUnit(final long nanos) {
@@ -204,23 +212,23 @@ public abstract class DurationStatisticsTracker {
 
     private static String abbreviate(final TimeUnit unit) {
         switch (unit) {
-        case NANOSECONDS:
-            return "ns";
-        case MICROSECONDS:
-            return "\u03bcs"; // μs
-        case MILLISECONDS:
-            return "ms";
-        case SECONDS:
-            return "s";
-        case MINUTES:
-            return "m";
-        case HOURS:
-            return "h";
-        case DAYS:
-            return "d";
+            case NANOSECONDS:
+                return "ns";
+            case MICROSECONDS:
+                return "μs";
+            case MILLISECONDS:
+                return "ms";
+            case SECONDS:
+                return "s";
+            case MINUTES:
+                return "m";
+            case HOURS:
+                return "h";
+            case DAYS:
+                return "d";
+            default:
+                LOG.warn("Unhandled time unit {}", unit);
+                return "";
         }
-
-        LOG.warn("Unhandled time unit {}", unit);
-        return "";
     }
 }