##### Coverage Report - org.webmacro.util.Clock

Classes in this File | Line Coverage | Branch Coverage | Complexity
Clock |
0% | 0/9
0% | 0/2
| 1.5;1.5

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2000 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
21 |  |
      */
22 |  |
23 |  |
24 |  |
     package org.webmacro.util;
25 |  |
26 |  |
     import java.util.Date;
27 |  |
28 |  |
     /**
29 |  |
      * This is an optimization. "System.currentTimeMillis()" is a relatively
30 |  |
      * slow method, and "new Date()" is an incredibly expensive operation.
31 |  |
      *
32 |  |
      * Update: System.ctm is no longer all that slow; replaced with a version
33 |  |
      * that caches the Date but not the time.
34 |  |
      */
35 |  |
     final public class Clock
36 |  |
     {
37 |  |
38 |  |
         /** Disallow instantiation.  */
39 |  |
         private Clock()
40 | 0 |
         {
41 | 0 |
         }
42 |  |
43 |  |
         /**
44 |  |
          * Every tick interval the following variable is updated with the current system time.
45 |  |
          */
46 | 0 |
         static public long TIME = System.currentTimeMillis();
47 |  |
48 |  |
         /**
49 |  |
          * Date information.
50 |  |
          */
51 | 0 |
         private static Date date = new Date();
52 |  |
53 |  |
         /**
54 |  |
          * The current date. This object is updated not faster than once per second.
55 |  |
          */
56 |  |
         public synchronized static Date getDate ()
57 |  |
         {
58 | 0 |
             long time = System.currentTimeMillis();
59 | 0 |
             if ((TIME - time) > 1000) {
60 | 0 |
                 TIME = time;
61 | 0 |
                 date = new Date(TIME);
62 |  |
             }
63 | 0 |
             return date;
64 |  |
         }
65 |  |
66 |  |
     }
67 |  |
68 |  |