Brooklyn

brooklyn.util.time
[Java] Class Duration

java.lang.Object
  brooklyn.util.time.Duration
All Implemented Interfaces:
java.lang.Comparable

public class Duration

simple class determines a length of time


Field Summary
static Duration FIVE_MINUTES

static Duration FIVE_SECONDS

static Duration ONE_DAY

static Duration ONE_HOUR

static Duration ONE_MINUTE

static Duration ONE_SECOND

static Duration TEN_SECONDS

static Duration THIRTY_SECONDS

static Duration TWO_MINUTES

static Duration ZERO

 
Constructor Summary
Duration(long value, java.util.concurrent.TimeUnit unit)

 
Method Summary
Duration add(Duration other)

int compareTo(Duration o)

CountdownTimer countdownTimer()

returns a new started CountdownTimer with this duration

boolean equals(java.lang.Object o)

Duration half()

int hashCode()

static Duration millis(java.lang.Number n)

creates new Duration instance of the given length of time

Duration multiply(long x)

Duration multiply(double d)

as #multiply(long), but approximate due to the division (nano precision)

long nanos()

number of nanoseconds of this duration

static Duration nanos(java.lang.Number n)

creates new Duration instance of the given length of time

static Duration of(java.lang.Object o)

tries to convert given object to a Duration, parsing strings, treating numbers as millis, etc; throws IAE if not convertable

static Duration of(long value, java.util.concurrent.TimeUnit unit)

static Duration parse(java.lang.String textualDescription)

see of(Object) and Time#parseTimeString(String)#parseTimeString(String)

static Duration seconds(java.lang.Number n)

creates new Duration instance of the given length of time

static void sleep(Duration duration)

see Time#sleep(long)#sleep(long)

Duration times(long x)

long toMilliseconds()

long toMillisecondsRoundingUp()

as toMilliseconds() but rounding away from zero (so 1 nanosecond gets rounded to 1 millisecond); see toUnitRoundingUp(TimeUnit); provided as a convenience on top of toUnit(TimeUnit, RoundingMode) as this is a common case (when you want to make sure you wait at least a certain amount of time)

long toNanoseconds()

long toSeconds()

java.lang.String toString()

java.lang.String toStringRounded()

long toUnit(java.util.concurrent.TimeUnit unit)

converts to the given java.util.concurrent.TimeUnit, using java.util.concurrent.TimeUnit#convert(long, java.util.concurrent.TimeUnit) which rounds _down_ (so 1 nanosecond converted to milliseconds gives 0 milliseconds, and -1 ns gives -1 ms)

long toUnit(java.util.concurrent.TimeUnit unit, java.math.RoundingMode rounding)

as toUnit(TimeUnit) but rounding as indicated (rather than always taking the floor which is TimeUnit's default behaviour)

long toUnitRoundingUp(java.util.concurrent.TimeUnit unit)

as toUnit(TimeUnit) but rounding away from zero, so 1 ns converted to ms gives 1 ms, and -1 ns gives 1ms

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

FIVE_MINUTES

public static final Duration FIVE_MINUTES


FIVE_SECONDS

public static final Duration FIVE_SECONDS


ONE_DAY

public static final Duration ONE_DAY


ONE_HOUR

public static final Duration ONE_HOUR


ONE_MINUTE

public static final Duration ONE_MINUTE


ONE_SECOND

public static final Duration ONE_SECOND


TEN_SECONDS

public static final Duration TEN_SECONDS


THIRTY_SECONDS

public static final Duration THIRTY_SECONDS


TWO_MINUTES

public static final Duration TWO_MINUTES


ZERO

public static final Duration ZERO


 
Constructor Detail

Duration

public Duration(long value, java.util.concurrent.TimeUnit unit)


 
Method Detail

add

public Duration add(Duration other)


compareTo

@Override
public int compareTo(Duration o)


countdownTimer

public CountdownTimer countdownTimer()
returns a new started CountdownTimer with this duration


equals

@Override
public boolean equals(java.lang.Object o)


half

public Duration half()


hashCode

@Override
public int hashCode()


millis

public static Duration millis(java.lang.Number n)
creates new Duration instance of the given length of time


multiply

public Duration multiply(long x)


multiply

public Duration multiply(double d)
as #multiply(long), but approximate due to the division (nano precision)


nanos

public long nanos()
number of nanoseconds of this duration


nanos

public static Duration nanos(java.lang.Number n)
creates new Duration instance of the given length of time


of

public static Duration of(java.lang.Object o)
tries to convert given object to a Duration, parsing strings, treating numbers as millis, etc; throws IAE if not convertable


of

public static Duration of(long value, java.util.concurrent.TimeUnit unit)


parse

public static Duration parse(java.lang.String textualDescription)
see of(Object) and Time#parseTimeString(String)#parseTimeString(String)


seconds

public static Duration seconds(java.lang.Number n)
creates new Duration instance of the given length of time


sleep

public static void sleep(Duration duration)
see Time#sleep(long)#sleep(long)


times

public Duration times(long x)


toMilliseconds

public long toMilliseconds()


toMillisecondsRoundingUp

public long toMillisecondsRoundingUp()
as toMilliseconds() but rounding away from zero (so 1 nanosecond gets rounded to 1 millisecond); see toUnitRoundingUp(TimeUnit); provided as a convenience on top of toUnit(TimeUnit, RoundingMode) as this is a common case (when you want to make sure you wait at least a certain amount of time)


toNanoseconds

public long toNanoseconds()


toSeconds

public long toSeconds()


toString

@Override
public java.lang.String toString()


toStringRounded

public java.lang.String toStringRounded()


toUnit

public long toUnit(java.util.concurrent.TimeUnit unit)
converts to the given java.util.concurrent.TimeUnit, using java.util.concurrent.TimeUnit#convert(long, java.util.concurrent.TimeUnit) which rounds _down_ (so 1 nanosecond converted to milliseconds gives 0 milliseconds, and -1 ns gives -1 ms)


toUnit

public long toUnit(java.util.concurrent.TimeUnit unit, java.math.RoundingMode rounding)
as toUnit(TimeUnit) but rounding as indicated (rather than always taking the floor which is TimeUnit's default behaviour)


toUnitRoundingUp

public long toUnitRoundingUp(java.util.concurrent.TimeUnit unit)
as toUnit(TimeUnit) but rounding away from zero, so 1 ns converted to ms gives 1 ms, and -1 ns gives 1ms


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.