Coverage Report - org.apache.camel.util.Time
 
Classes in this File Line Coverage Branch Coverage Complexity
Time
0% 
N/A 
1
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.util;
 18  
 
 19  
 import java.util.concurrent.TimeUnit;
 20  
 import java.util.Date;
 21  
 
 22  
 /**
 23  
  * A helper class for working with times in various units
 24  
  *
 25  
  * @version $Revision: $
 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  
 }