src/Pure/General/time.scala
changeset 56351 1c735e46acf0
parent 53292 f567c1c7b180
child 56691 ad5d7461b370
equal deleted inserted replaced
56350:949d4c7a86c6 56351:1c735e46acf0
    19 
    19 
    20   def print_seconds(s: Double): String =
    20   def print_seconds(s: Double): String =
    21     String.format(Locale.ROOT, "%.3f", s.asInstanceOf[AnyRef])
    21     String.format(Locale.ROOT, "%.3f", s.asInstanceOf[AnyRef])
    22 }
    22 }
    23 
    23 
    24 final class Time private(val ms: Long)
    24 final class Time private(val ms: Long) extends AnyVal
    25 {
    25 {
    26   def + (t: Time): Time = new Time(ms + t.ms)
    26   def + (t: Time): Time = new Time(ms + t.ms)
    27 
    27 
    28   def seconds: Double = ms / 1000.0
    28   def seconds: Double = ms / 1000.0
    29 
    29 
    31   def max(t: Time): Time = if (ms > t.ms) this else t
    31   def max(t: Time): Time = if (ms > t.ms) this else t
    32 
    32 
    33   def is_zero: Boolean = ms == 0
    33   def is_zero: Boolean = ms == 0
    34   def is_relevant: Boolean = ms >= 1
    34   def is_relevant: Boolean = ms >= 1
    35 
    35 
    36   override def hashCode: Int = ms.hashCode
       
    37   override def equals(that: Any): Boolean =
       
    38     that match {
       
    39       case other: Time => ms == other.ms
       
    40       case _ => false
       
    41     }
       
    42 
       
    43   override def toString = Time.print_seconds(seconds)
    36   override def toString = Time.print_seconds(seconds)
    44 
    37 
    45   def message: String = toString + "s"
    38   def message: String = toString + "s"
    46 }
    39 }
    47 
    40