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.Date; |
20 |
|
import java.util.concurrent.TimeUnit; |
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
public class Time { |
28 |
|
private long number; |
29 |
0 |
private TimeUnit timeUnit = TimeUnit.MILLISECONDS; |
30 |
|
|
31 |
0 |
public Time(long number, TimeUnit timeUnit) { |
32 |
0 |
this.number = number; |
33 |
0 |
this.timeUnit = timeUnit; |
34 |
0 |
} |
35 |
|
|
36 |
|
public static Time millis(long value) { |
37 |
0 |
return new Time(value, TimeUnit.MILLISECONDS); |
38 |
|
} |
39 |
|
|
40 |
|
public static Time micros(long value) { |
41 |
0 |
return new Time(value, TimeUnit.MICROSECONDS); |
42 |
|
} |
43 |
|
|
44 |
|
public static Time nanos(long value) { |
45 |
0 |
return new Time(value, TimeUnit.NANOSECONDS); |
46 |
|
} |
47 |
|
|
48 |
|
public static Time seconds(long value) { |
49 |
0 |
return new Time(value, TimeUnit.SECONDS); |
50 |
|
} |
51 |
|
|
52 |
|
public static Time minutes(long value) { |
53 |
0 |
return new Time(minutesAsSeconds(value), TimeUnit.MILLISECONDS); |
54 |
|
} |
55 |
|
|
56 |
|
public static Time hours(long value) { |
57 |
0 |
return new Time(hoursAsSeconds(value), TimeUnit.MILLISECONDS); |
58 |
|
} |
59 |
|
|
60 |
|
public static Time days(long value) { |
61 |
0 |
return new Time(daysAsSeconds(value), TimeUnit.MILLISECONDS); |
62 |
|
} |
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 |
|
} |