SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
TimeUnit.java
1/*
2 * Class: TimeUnit
3 * Description: Represents a time unit for conversion of time durations.
4 * Environment: Java
5 * Software: SSJ
6 * Copyright (C) 2001 Pierre L'Ecuyer and Universite de Montreal
7 * Organization: DIRO, Universite de Montreal
8 * @author
9 * @since
10 *
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 */
25package umontreal.ssj.util;
26
36public enum TimeUnit {
37
41
46
47 ("ns", "nanosecond", 1.0 / 3600000000000.0),
48
53
54 ("us", "microsecond", 1.0 / 3600000000.0),
55
60
61 ("ms", "millisecond", 1.0 / 3600000.0),
62
67
68 ("s", "second", 1.0 / 3600.0),
69
74
75 ("min", "minute", 1.0 / 60.0),
76
81
82 ("h", "hour", 1.0),
83
88
89 ("d", "day", 24.0),
90
94 WEEK
95
96 ("w", "week", 24.0 * 7);
97
98 private String shortName;
99 private String longName;
100 private transient double numHours;
101
102 private TimeUnit(String shortName, String longName, double numHours) {
103 this.shortName = shortName;
104 this.longName = longName;
105 this.numHours = numHours;
106 }
107
111
118 public String getShortName() {
119 return shortName;
120 }
121
127 public String getLongName() {
128 return longName;
129 }
130
136 public String toString() {
137 return longName;
138 }
139
146 public double getHours() {
147 return numHours;
148 }
149
161 public static double convert(double value, TimeUnit srcUnit, TimeUnit dstUnit) {
162 double hours = value * srcUnit.getHours();
163 return hours / dstUnit.getHours();
164 }
165}
NANOSECOND
Represents a nanosecond which has short name ns.
Definition TimeUnit.java:45
double getHours()
Returns this time unit represented in hours.
String toString()
Calls getLongName.
WEEK
Represents a week which has short name w.
Definition TimeUnit.java:94
static double convert(double value, TimeUnit srcUnit, TimeUnit dstUnit)
Converts value expressed in time unit srcUnit to a time duration expressed in dstUnit and returns the...
SECOND
Represents a second which has short name s.
Definition TimeUnit.java:66
String getShortName()
Returns the short name representing this unit in a string specifying a time duration.
HOUR
Represents an hour which has short name h.
Definition TimeUnit.java:80
MICROSECOND
Represents a microsecond which has short name us.
Definition TimeUnit.java:52
DAY
Represents a day which has short name d.
Definition TimeUnit.java:87
MINUTE
Represents a minute which has short name min.
Definition TimeUnit.java:73
String getLongName()
Returns the long name of this time unit.
MILLISECOND
Represents a millisecond which has short name ms.
Definition TimeUnit.java:59