Package org.sonar.api.utils
Class Duration
- java.lang.Object
-
- org.sonar.api.utils.Duration
-
- All Implemented Interfaces:
java.io.Serializable
public class Duration extends java.lang.Object implements java.io.Serializable
- Since:
- 4.3
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Duration
add(Duration with)
Add the given duration to the current one.static Duration
create(long durationInMinutes)
Create a Duration from a number of minutes.static Duration
decode(java.lang.String text, int hoursInDay)
Create a Duration from a text duration and the number of hours in a day.java.lang.String
encode(int hoursInDay)
Return the duration in text, by using the given hours in day parameter to process hours.boolean
equals(java.lang.Object o)
int
hashCode()
boolean
isGreaterThan(Duration other)
Return true if the given duration is greater than the current one.Duration
multiply(int factor)
Multiply the duration with the given factor.Duration
subtract(Duration with)
Subtract the given duration to the current one.long
toMinutes()
Return the duration in minutes.java.lang.String
toString()
-
-
-
Field Detail
-
DAY
public static final java.lang.String DAY
- See Also:
- Constant Field Values
-
HOUR
public static final java.lang.String HOUR
- See Also:
- Constant Field Values
-
MINUTE
public static final java.lang.String MINUTE
- See Also:
- Constant Field Values
-
-
Method Detail
-
create
public static Duration create(long durationInMinutes)
Create a Duration from a number of minutes.
-
decode
public static Duration decode(java.lang.String text, int hoursInDay)
Create a Duration from a text duration and the number of hours in a day.
For instance, Duration.decode("1d 1h", 8) will have a number of minutes of 540 (1*8*60 + 60).
-
encode
public java.lang.String encode(int hoursInDay)
Return the duration in text, by using the given hours in day parameter to process hours.
Duration.decode("1d 1h", 8).encode(8) will return "1d 1h" Duration.decode("2d", 8).encode(16) will return "1d"
-
toMinutes
public long toMinutes()
Return the duration in minutes.
For instance, Duration.decode(1h, 24).toMinutes() will return 60.
-
isGreaterThan
public boolean isGreaterThan(Duration other)
Return true if the given duration is greater than the current one.
-
multiply
public Duration multiply(int factor)
Multiply the duration with the given factor.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-