org.omnaest.utils.time
Class DurationCapture

java.lang.Object
  extended by org.omnaest.utils.time.DurationCapture
All Implemented Interfaces:
Serializable

public class DurationCapture
extends Object
implements Serializable

A DurationCapture will measure time intervals.

Author:
Omnaest
See Also:
newInstance(), DurationCaptureTypeFactory, Serialized Form

Nested Class Summary
static class DurationCapture.Interval
          Saves the interval points and their data like name and time.
protected static class DurationCapture.IntervalStatistic
          Internal class for statistical data calculated for the DurationCapture.Interval instances.
 
Field Summary
static Class<? extends DurationCapture> implementationForDurationClass
          Used by the factory method.
static Object INTERVAL_DEFAULTKEY
           
protected  Map<Object,DurationCapture.Interval> intervalKeyToIntervalMap
           
 
Constructor Summary
DurationCapture()
           
 
Method Summary
 String calculateIntervalStatisticLogMessage()
          Returns the collected statistical informations for the intervals durations.
protected  Map<Object,DurationCapture.IntervalStatistic> calculateIntervalStatisticMap()
          Calculates the statistical data for the interval and returns a map with the intervalKeys and a DurationCapture.IntervalStatistic instance.
protected  DurationCapture.Interval determineInterval(Object key)
          Returns an DurationCapture.Interval for the given key.
 long getDuration(Object intervalKey, TimeUnit timeUnit)
          Returns the needed time between measurement start and stop for the given interval key in the given TimeUnit.
 long getDuration(TimeUnit timeUnit)
          Returns the needed time between measurement start and stop in the given TimeUnit.
 long getDuration(TimeUnit timeUnit, Object... intervalKeys)
          Returns the time duration sum between measurement start and stop in the given TimeUnit for all given interval keys.
 long getDurationInMilliseconds()
          Returns the needed time between measurement start and stop in milliseconds.
 long getDurationInMilliseconds(Object... intervalKeys)
          Returns the time duration sum between measurement start and stop in milliseconds for all given interval keys.
 long getDurationInMilliseconds(Object intervalKey)
          Returns the needed time between measurement start and stop in milliseconds.
 long getInterimTime(Object intervalKey, TimeUnit timeUnit)
          Returns the time since starting the measurement and now in milliseconds for the given interval key in the given TimeUnit
 long getInterimTime(TimeUnit timeUnit)
          Returns the time since starting the measurement and now in the given TimeUnit.
 long getInterimTime(TimeUnit timeUnit, Object... intervalKeys)
          Returns the time sum since starting the measurement and now in the given TimeUnit for all given interval keys.
 long getInterimTimeInMilliseconds()
          Returns the time since starting the measurement and now in milliseconds.
 long getInterimTimeInMilliseconds(Object... intervalKeys)
          Returns the time sum since starting the measurement and now in milliseconds for all given interval keys.
 long getInterimTimeInMilliseconds(Object intervalKey)
          Returns the time since starting the measurement and now in milliseconds for the given interval key
 List<Object> getIntervalKeyList()
          Returns all available DurationCapture.Interval keys.
 Map<Object,Long> getIntervalKeyToDurationInMillisecondsMap()
          Returns a new Map instance with all DurationCapture.Interval keys and the related getDurationInMilliseconds(Object) as value
 Map<Object,Long> getIntervalKeyToDurationMap(TimeUnit timeUnit)
          Returns a new Map instance with all DurationCapture.Interval keys and the related getDuration(TimeUnit) as value
protected  boolean hasDefaultInterval()
          Returns true, if there is an DurationCapture.Interval instance for the INTERVAL_DEFAULTKEY.
static DurationCapture newInstance()
          Creates a new instance of this class.
 void resetTimer()
          Sets the timer of the default DurationCapture.Interval back to zero.
 void resetTimers()
          Resets the timer of all contained DurationCapture.Interval instances.
 DurationCapture startTimeMeasurement()
          Starts the measurement of time.
 DurationCapture startTimeMeasurement(Object intervalKey)
          Starts the time measurement which will relate to the given key.
 DurationCapture stopTimeMeasurement()
          Stops the measurement of the time for the default DurationCapture.Interval.
 DurationCapture stopTimeMeasurement(Object intervalKey)
          Stops the time measurement for the respective DurationCapture.Interval.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTERVAL_DEFAULTKEY

public static final Object INTERVAL_DEFAULTKEY

intervalKeyToIntervalMap

protected final Map<Object,DurationCapture.Interval> intervalKeyToIntervalMap

implementationForDurationClass

public static Class<? extends DurationCapture> implementationForDurationClass
Used by the factory method.

See Also:
newInstance()
Constructor Detail

DurationCapture

public DurationCapture()
See Also:
DurationCapture
Method Detail

startTimeMeasurement

public DurationCapture startTimeMeasurement(Object intervalKey)
Starts the time measurement which will relate to the given key.

Parameters:
intervalKey -
Returns:
this

determineInterval

protected DurationCapture.Interval determineInterval(Object key)
Returns an DurationCapture.Interval for the given key.

Parameters:
key -
Returns:

startTimeMeasurement

public DurationCapture startTimeMeasurement()
Starts the measurement of time.

Returns:

resetTimer

public void resetTimer()
Sets the timer of the default DurationCapture.Interval back to zero.


resetTimers

public void resetTimers()
Resets the timer of all contained DurationCapture.Interval instances.


stopTimeMeasurement

public DurationCapture stopTimeMeasurement()
Stops the measurement of the time for the default DurationCapture.Interval.

Returns:

stopTimeMeasurement

public DurationCapture stopTimeMeasurement(Object intervalKey)
Stops the time measurement for the respective DurationCapture.Interval.

Parameters:
intervalKey -
Returns:
this

calculateIntervalStatisticMap

protected Map<Object,DurationCapture.IntervalStatistic> calculateIntervalStatisticMap()
Calculates the statistical data for the interval and returns a map with the intervalKeys and a DurationCapture.IntervalStatistic instance.


getDurationInMilliseconds

public long getDurationInMilliseconds()
Returns the needed time between measurement start and stop in milliseconds.

Returns:
See Also:
getDurationInMilliseconds(Object)

getDuration

public long getDuration(TimeUnit timeUnit)
Returns the needed time between measurement start and stop in the given TimeUnit.

Parameters:
timeUnit -
Returns:
See Also:
getDurationInMilliseconds(Object)

getDurationInMilliseconds

public long getDurationInMilliseconds(Object intervalKey)
Returns the needed time between measurement start and stop in milliseconds.

Parameters:
intervalKey -
Returns:
See Also:
getDurationInMilliseconds()

getDuration

public long getDuration(Object intervalKey,
                        TimeUnit timeUnit)
Returns the needed time between measurement start and stop for the given interval key in the given TimeUnit.

Parameters:
timeUnit -
Returns:
See Also:
getDurationInMilliseconds(Object)

getDurationInMilliseconds

public long getDurationInMilliseconds(Object... intervalKeys)
Returns the time duration sum between measurement start and stop in milliseconds for all given interval keys. If no interval key is specified getDurationInMilliseconds() is returned.

Parameters:
intervalKeys -
Returns:

getDuration

public long getDuration(TimeUnit timeUnit,
                        Object... intervalKeys)
Returns the time duration sum between measurement start and stop in the given TimeUnit for all given interval keys. If no interval key is specified getDurationInMilliseconds() is returned.

Parameters:
timeUnit -
intervalKeys -
Returns:

getInterimTimeInMilliseconds

public long getInterimTimeInMilliseconds()
Returns the time since starting the measurement and now in milliseconds.

Returns:

getInterimTime

public long getInterimTime(TimeUnit timeUnit)
Returns the time since starting the measurement and now in the given TimeUnit.

Parameters:
timeUnit -
Returns:

getInterimTimeInMilliseconds

public long getInterimTimeInMilliseconds(Object intervalKey)
Returns the time since starting the measurement and now in milliseconds for the given interval key

Returns:

getInterimTime

public long getInterimTime(Object intervalKey,
                           TimeUnit timeUnit)
Returns the time since starting the measurement and now in milliseconds for the given interval key in the given TimeUnit

Parameters:
timeUnit - TimeUnit
Returns:

getInterimTimeInMilliseconds

public long getInterimTimeInMilliseconds(Object... intervalKeys)
Returns the time sum since starting the measurement and now in milliseconds for all given interval keys. If no interval key is given getInterimTimeInMilliseconds() is returned instead.

Parameters:
intervalKeys -
Returns:

getInterimTime

public long getInterimTime(TimeUnit timeUnit,
                           Object... intervalKeys)
Returns the time sum since starting the measurement and now in the given TimeUnit for all given interval keys. If no interval key is given getInterimTime(TimeUnit) is returned instead.

Parameters:
timeUnit - TimeUnit
intervalKeys -
Returns:

hasDefaultInterval

protected boolean hasDefaultInterval()
Returns true, if there is an DurationCapture.Interval instance for the INTERVAL_DEFAULTKEY.

Returns:

calculateIntervalStatisticLogMessage

public String calculateIntervalStatisticLogMessage()
Returns the collected statistical informations for the intervals durations.

Returns:

getIntervalKeyList

public List<Object> getIntervalKeyList()
Returns all available DurationCapture.Interval keys.

Returns:

getIntervalKeyToDurationInMillisecondsMap

public Map<Object,Long> getIntervalKeyToDurationInMillisecondsMap()
Returns a new Map instance with all DurationCapture.Interval keys and the related getDurationInMilliseconds(Object) as value

Returns:

getIntervalKeyToDurationMap

public Map<Object,Long> getIntervalKeyToDurationMap(TimeUnit timeUnit)
Returns a new Map instance with all DurationCapture.Interval keys and the related getDuration(TimeUnit) as value

Parameters:
timeUnit - TimeUnit
Returns:

newInstance

public static DurationCapture newInstance()
Creates a new instance of this class.

See Also:
implementationForDurationClass

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013. All Rights Reserved.