This is a pure value holder, use a record for it.
Change-Id: I3f6743cfbbe74bd7b83acb0b9d8bfb0265f03540
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
* the number of volatile operations.
*/
final var currentShortest = (DurationWithTime) SHORTEST.getAcquire(this);
- if (currentShortest == null || duration < currentShortest.getDuration()) {
+ if (currentShortest == null || duration < currentShortest.duration()) {
updateShortest(currentShortest, duration);
}
final var currentLongest = (DurationWithTime) LONGEST.getAcquire(this);
- if (currentLongest == null || duration > currentLongest.getDuration()) {
+ if (currentLongest == null || duration > currentLongest.duration()) {
updateLongest(currentLongest, duration);
}
}
var expected = prev;
while (true) {
final var witness = (DurationWithTime) SHORTEST.compareAndExchangeRelease(this, expected, newObj);
- if (witness == expected || duration >= witness.getDuration()) {
+ if (witness == expected || duration >= witness.duration()) {
break;
}
expected = witness;
var expected = prev;
while (true) {
final var witness = (DurationWithTime) LONGEST.compareAndExchangeRelease(this, expected, newObj);
- if (witness == expected || duration <= witness.getDuration()) {
+ if (witness == expected || duration <= witness.duration()) {
break;
}
expected = witness;
}
private static long getDuration(final DurationWithTime current) {
- return current == null ? 0L : current.getDuration();
+ return current == null ? 0L : current.duration();
}
private static long getTimeMillis(final DurationWithTime current) {
- return current == null ? 0L : current.getTimeMillis();
+ return current == null ? 0L : current.timeMillis();
}
private static String formatDuration(final double duration, final Long timeStamp) {
}
private static String formatDuration(final DurationWithTime current) {
- if (current == null) {
- return formatDuration(0, null);
- }
- return formatDuration(current.getDuration(), current.getTimeMillis());
+ return current == null ? formatDuration(0, null) : formatDuration(current.duration(), current.timeMillis());
}
private static TimeUnit chooseUnit(final long nanos) {
package org.opendaylight.yangtools.util;
/**
- * Utility holder for a duration/time of occurance.
+ * Utility holder for a duration/time of occurrence.
*/
-final class DurationWithTime {
- private final long duration;
- private final long timeMillis;
-
- DurationWithTime(final long duration, final long timeMillis) {
- this.duration = duration;
- this.timeMillis = timeMillis;
- }
-
- long getDuration() {
- return duration;
- }
-
- long getTimeMillis() {
- return timeMillis;
- }
-}
\ No newline at end of file
+record DurationWithTime(long duration, long timeMillis) {
+ // Nothing else
+}
import org.junit.Test;
public class SynchronizedDurationStatsTrackerTest {
-
@Test
public void testAllMethodsOfSynchronizedDurationStatsTracker() {
final SynchronizedDurationStatsTracker statsTracker = new SynchronizedDurationStatsTracker();
statsTracker.addDuration(2000);
statsTracker.addDuration(3000);
- assertEquals("Shortest recorded duration should be '1000'.", 1000, statsTracker.getShortest().getDuration());
+ assertEquals("Shortest recorded duration should be '1000'.", 1000, statsTracker.getShortest().duration());
assertEquals("Average recorded duration should be '2000'.", 2000, statsTracker.getAverageDuration(), 0.0001);
- assertEquals("Longest recorded duration should be '3000'.", 3000, statsTracker.getLongest().getDuration());
+ assertEquals("Longest recorded duration should be '3000'.", 3000, statsTracker.getLongest().duration());
assertEquals("Total recorded duration count should be '3'.", 3, statsTracker.getTotalDurations());
statsTracker.reset();