KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > admin > DateComparator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.lib.cvsclient.admin;
20
21 /**
22  * A class for comparing the file's date and the CVS/Entries date.
23  *
24  * @author Thomas Singer
25  * @version Sep 29, 2001
26  */

27 public class DateComparator {
28
29     private static final long SECONDS_PER_HOUR = 3600;
30
31     private static final DateComparator singleton = new DateComparator();
32
33     /**
34      * Returns an instance of a DateComparator.
35      */

36     public static DateComparator getInstance() {
37         return singleton;
38     }
39
40     /**
41      * This class is a singleton. There is no need to subclass or
42      * instantiate it outside.
43      */

44     private DateComparator() {
45     }
46
47     /**
48      * Compares the specified dates, whether they should be treated as equal.
49      * Returns true to indicate equality.
50      */

51     public boolean equals(final long fileTime, final long entryTime) {
52         final long fileTimeSeconds = fileTime / 1000;
53         final long entryTimeSeconds = entryTime / 1000;
54         final long difference = Math.abs(fileTimeSeconds - entryTimeSeconds);
55         // differences smaller than 1 second are treated as equal to catch rounding errors
56
if (difference < 1) {
57             return true;
58         }
59
60         // 1-hour-differences (caused by daylight-saving) are treated as equal
61
if (difference >= SECONDS_PER_HOUR - 1
62                 && difference <= SECONDS_PER_HOUR + 1) {
63             return true;
64         }
65         return false;
66     }
67 }
68
Popular Tags