Coverage Report - javafx.lang.Duration
 
Classes in this File Line Coverage Branch Coverage Complexity
Duration
70%
23/33
43%
12/28
0
Duration$Intf
N/A
N/A
0
 
 1  
 /*
 2  
  * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  
  *
 5  
  * This code is free software; you can redistribute it and/or modify it
 6  
  * under the terms of the GNU General Public License version 2 only, as
 7  
  * published by the Free Software Foundation.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun in the LICENSE file that accompanied this code.
 10  
  *
 11  
  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  
  * version 2 for more details (a copy is included in the LICENSE file that
 15  
  * accompanied this code).
 16  
  *
 17  
  * You should have received a copy of the GNU General Public License version
 18  
  * 2 along with this work; if not, write to the Free Software Foundation,
 19  
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  
  *
 21  
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 
 26  
 package javafx.lang;
 27  
 
 28  
 import java.lang.Object;
 29  
 import java.lang.Comparable;
 30  
 import java.lang.Long;
 31  
 import java.lang.Math;
 32  
 
 33  
 /**
 34  
  * A class that defines a duration of time.  Duration instances are defined in
 35  
  * milliseconds, but can be easily created using time literals; for
 36  
  * example, a two-and-a-half minute Duration instance can be defined in several
 37  
  * ways:
 38  
  * <code><pre>    Duration t = 2m + 30s;
 39  
     Duration t = 2.5m;
 40  
     Duration t = 2500ms;</pre></code>
 41  
  */
 42  798
 public class Duration extends Comparable {
 43  
 
 44  
     /** The duration of time, as expressed in milliseconds. */
 45  984
     public attribute millis: Number;
 46  
 
 47  
     public function equals(obj:Object):Boolean {
 48  7
         if (obj instanceof Duration) {
 49  7
             var t = obj as Duration;
 50  7
             return t.millis == millis;
 51  
         }
 52  0
         return false;
 53  
     }
 54  
 
 55  
     public function compareTo(obj:Object):Integer {
 56  526
         var t = obj as Duration;
 57  526
         var m1 = millis;
 58  526
         var m2 = t.millis;
 59  526
         var cmp = m1 - m2;
 60  263
         return if (cmp < 0) -1 else if (cmp > 0) 1 else 0;
 61  
     }
 62  
 
 63  
     public function hashCode():Integer {
 64  0
         return Long.valueOf(millis.longValue()).hashCode();
 65  
     }
 66  
 
 67  
     /** Returns the number of milliseconds in this period. */
 68  
     public function toMillis():Number {
 69  0
         return millis;
 70  
     }
 71  
     
 72  
     /** Returns the number of whole seconds in this period. */
 73  
     public function toSeconds():Number {
 74  1
         return Math.floor(millis / 1000);
 75  
     }
 76  
     
 77  
     /** Returns the number of whole minutes in this period. */
 78  
     public function toMinutes(): Number {
 79  1
         return Math.floor(millis / 60 / 1000);
 80  
     }
 81  
     
 82  
     /** Returns the number of whole hours in this period. */
 83  
     public function toHours(): Number {
 84  0
         return Math.floor(millis / 60 / 60 / 1000);
 85  
     }
 86  
 
 87  
     /** Add this instance and another Duration instance to return a new Duration instance.
 88  
      *  This function does not change the value of called Duration instance. */
 89  
     public function add(other:Duration):Duration {
 90  8
         return Duration {
 91  4
             millis: millis + other.millis;
 92  
         }
 93  
     }
 94  
 
 95  
     /** Subtract this instance from another Duration instance to return a new Duration instance.
 96  
      *  This function does not change the value of called Duration instance. */
 97  
     public function sub(other:Duration):Duration {
 98  2
         return Duration {
 99  1
             millis: millis - other.millis;
 100  
         }
 101  
     }
 102  
 
 103  
     /** Multiply this instance with a number to return a new Duration instance.
 104  
      *  This function does not change the value of called Duration instance. */
 105  
     public function mul(n:Number):Duration {
 106  2
         return Duration {
 107  1
             millis: millis * n;
 108  
         }
 109  
     }
 110  
 
 111  
 
 112  
     /** Divide this instance by a number to return a new Duration instance.
 113  
      *  This function does not change the value of called Duration instance. */
 114  
     public function div(n:Number):Duration {
 115  2
         return Duration {
 116  1
             millis: millis / n;
 117  
         }
 118  
     }
 119  
 
 120  
     public function negate():Duration {
 121  0
         return Duration {
 122  0
             millis: -millis;
 123  
         }
 124  
     }
 125  
 
 126  
     public function toString(): String {
 127  1
         return "{millis}ms";
 128  
     }
 129  
 
 130  
     public function lt(other: Duration):Boolean {
 131  238
         return compareTo(other) < 0;
 132  
     }
 133  
 
 134  
     public function le(other: Duration):Boolean {
 135  0
         return compareTo(other) <= 0;
 136  
     }
 137  
 
 138  
     public function gt(other: Duration):Boolean {
 139  0
         return compareTo(other) > 0;
 140  
     }
 141  
 
 142  
     public function ge(other: Duration):Boolean {
 143  0
         return compareTo(other) >= 0;
 144  
     }
 145  
 
 146  0
     public function toDate():java.util.Date {
 147  16
         return new java.util.Date(millis.longValue());
 148  
     }
 149  
 }