src/Pure/General/time.scala
author wenzelm
Sat, 22 Feb 2014 20:52:43 +0100
changeset 55672 5e25cc741ab9
parent 53292 f567c1c7b180
child 56351 1c735e46acf0
permissions -rw-r--r--
support for completion within the formal context; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45674
eb65c9d17e2f clarified Time vs. Timing;
wenzelm
parents: 45673
diff changeset
     1
/*  Title:      Pure/General/time.scala
45673
cd41e3903fbf separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
wenzelm
parents: 45667
diff changeset
     2
    Module:     PIDE
40393
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
     4
45674
eb65c9d17e2f clarified Time vs. Timing;
wenzelm
parents: 45673
diff changeset
     5
Time based on milliseconds.
40393
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
     6
*/
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
     7
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
     8
package isabelle
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
     9
45664
ac6e704dcd12 tuned signature (according to ML version);
wenzelm
parents: 45249
diff changeset
    10
50298
1426d478ccda tuned import;
wenzelm
parents: 47993
diff changeset
    11
import java.util.Locale
1426d478ccda tuned import;
wenzelm
parents: 47993
diff changeset
    12
1426d478ccda tuned import;
wenzelm
parents: 47993
diff changeset
    13
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40393
diff changeset
    14
object Time
40393
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
    15
{
47993
135fd6f2dadd less warning in scala-2.10.0-M3;
wenzelm
parents: 46768
diff changeset
    16
  def seconds(s: Double): Time = new Time((s * 1000.0).round)
44699
5199ee17c7d7 property "tooltip-dismiss-delay" is edited in ms, not seconds;
wenzelm
parents: 40852
diff changeset
    17
  def ms(m: Long): Time = new Time(m)
51587
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    18
  val zero: Time = ms(0)
51533
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50298
diff changeset
    19
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50298
diff changeset
    20
  def print_seconds(s: Double): String =
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50298
diff changeset
    21
    String.format(Locale.ROOT, "%.3f", s.asInstanceOf[AnyRef])
40393
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
    22
}
2bb7ec08574a somewhat more uniform timing in ML vs. Scala;
wenzelm
parents:
diff changeset
    23
46712
8650d9a95736 prefer final ADTs -- prevent ooddities;
wenzelm
parents: 45674
diff changeset
    24
final class Time private(val ms: Long)
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40393
diff changeset
    25
{
51587
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    26
  def + (t: Time): Time = new Time(ms + t.ms)
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    27
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40393
diff changeset
    28
  def seconds: Double = ms / 1000.0
40852
aee98c88c587 builtin time bounds (again);
wenzelm
parents: 40848
diff changeset
    29
aee98c88c587 builtin time bounds (again);
wenzelm
parents: 40848
diff changeset
    30
  def min(t: Time): Time = if (ms < t.ms) this else t
aee98c88c587 builtin time bounds (again);
wenzelm
parents: 40848
diff changeset
    31
  def max(t: Time): Time = if (ms > t.ms) this else t
aee98c88c587 builtin time bounds (again);
wenzelm
parents: 40848
diff changeset
    32
53292
f567c1c7b180 option to insert unique completion immediately into buffer;
wenzelm
parents: 51587
diff changeset
    33
  def is_zero: Boolean = ms == 0
46768
46acd255810d relevant timing as in ML;
wenzelm
parents: 46712
diff changeset
    34
  def is_relevant: Boolean = ms >= 1
46acd255810d relevant timing as in ML;
wenzelm
parents: 46712
diff changeset
    35
51587
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    36
  override def hashCode: Int = ms.hashCode
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    37
  override def equals(that: Any): Boolean =
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    38
    that match {
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    39
      case other: Time => ms == other.ms
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    40
      case _ => false
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    41
    }
7050c4656fd8 more operations on Time, Timing;
wenzelm
parents: 51533
diff changeset
    42
51533
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50298
diff changeset
    43
  override def toString = Time.print_seconds(seconds)
46768
46acd255810d relevant timing as in ML;
wenzelm
parents: 46712
diff changeset
    44
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40393
diff changeset
    45
  def message: String = toString + "s"
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40393
diff changeset
    46
}
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40393
diff changeset
    47