| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package org.apache.camel.util; |
| 18 |
|
|
| 19 |
|
import java.util.concurrent.TimeUnit; |
| 20 |
|
import java.util.Date; |
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
public class Time { |
| 28 |
|
private long number; |
| 29 |
0 |
private TimeUnit timeUnit = TimeUnit.MILLISECONDS; |
| 30 |
|
|
| 31 |
|
public static Time millis(long value) { |
| 32 |
0 |
return new Time(value, TimeUnit.MILLISECONDS); |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
public static Time micros(long value) { |
| 36 |
0 |
return new Time(value, TimeUnit.MICROSECONDS); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
public static Time nanos(long value) { |
| 40 |
0 |
return new Time(value, TimeUnit.NANOSECONDS); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
public static Time seconds(long value) { |
| 44 |
0 |
return new Time(value, TimeUnit.SECONDS); |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
public static Time minutes(long value) { |
| 48 |
0 |
return new Time(minutesAsSeconds(value), TimeUnit.MILLISECONDS); |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
public static Time hours(long value) { |
| 52 |
0 |
return new Time(hoursAsSeconds(value), TimeUnit.MILLISECONDS); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
public static Time days(long value) { |
| 56 |
0 |
return new Time(daysAsSeconds(value), TimeUnit.MILLISECONDS); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
0 |
public Time(long number, TimeUnit timeUnit) { |
| 60 |
0 |
this.number = number; |
| 61 |
0 |
this.timeUnit = timeUnit; |
| 62 |
0 |
} |
| 63 |
|
|
| 64 |
|
public long toMillis() { |
| 65 |
0 |
return timeUnit.toMillis(number); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
public Date toDate() { |
| 69 |
0 |
return new Date(toMillis()); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
public long getNumber() { |
| 73 |
0 |
return number; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
public TimeUnit getTimeUnit() { |
| 77 |
0 |
return timeUnit; |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
protected static long minutesAsSeconds(long value) { |
| 81 |
0 |
return value * 60; |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
protected static long hoursAsSeconds(long value) { |
| 85 |
0 |
return minutesAsSeconds(value) * 60; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
protected static long daysAsSeconds(long value) { |
| 89 |
0 |
return hoursAsSeconds(value) * 24; |
| 90 |
|
} |
| 91 |
|
} |