~ubuntu-branches/ubuntu/trusty/subversion/trusty-proposed

« back to all changes in this revision

Viewing changes to subversion/bindings/javahl/src/org/apache/subversion/javahl/types/LogDate.java

  • Committer: Package Import Robot
  • Author(s): Andy Whitcroft
  • Date: 2012-06-21 15:36:36 UTC
  • mfrom: (0.4.13 sid)
  • Revision ID: package-import@ubuntu.com-20120621153636-amqqmuidgwgxz1ly
Tags: 1.7.5-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Create pot file on build.
  - Build a python-subversion-dbg package.
  - Build-depend on python-dbg.
  - Build-depend on default-jre-headless/-jdk.
  - Do not apply java-build patch.
  - debian/rules: Manually create the doxygen output directory, otherwise
    we get weird build failures when running parallel builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @copyright
 
3
 * ====================================================================
 
4
 *    Licensed to the Apache Software Foundation (ASF) under one
 
5
 *    or more contributor license agreements.  See the NOTICE file
 
6
 *    distributed with this work for additional information
 
7
 *    regarding copyright ownership.  The ASF licenses this file
 
8
 *    to you under the Apache License, Version 2.0 (the
 
9
 *    "License"); you may not use this file except in compliance
 
10
 *    with the License.  You may obtain a copy of the License at
 
11
 *
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
14
 *    Unless required by applicable law or agreed to in writing,
 
15
 *    software distributed under the License is distributed on an
 
16
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
17
 *    KIND, either express or implied.  See the License for the
 
18
 *    specific language governing permissions and limitations
 
19
 *    under the License.
 
20
 * ====================================================================
 
21
 * @endcopyright
 
22
 */
 
23
 
 
24
package org.apache.subversion.javahl.types;
 
25
 
 
26
import java.text.DateFormat;
 
27
import java.text.ParseException;
 
28
import java.text.SimpleDateFormat;
 
29
import java.util.Calendar;
 
30
import java.util.Date;
 
31
import java.util.TimeZone;
 
32
 
 
33
/**
 
34
 * Holds date for a log message.  This class maintains
 
35
 * the time to the microsecond and is not lossy.
 
36
 */
 
37
public class LogDate implements java.io.Serializable
 
38
{
 
39
    private static final long serialVersionUID = 1L;
 
40
    private static final DateFormat formatter = new SimpleDateFormat(
 
41
            "yyyy-MM-dd'T'HH:mm:ss.SSS z");
 
42
    private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
 
43
 
 
44
    private final long timeMicros;
 
45
    private final String cachedString;
 
46
    private final Calendar cachedDate;
 
47
 
 
48
    public LogDate(String datestr) throws ParseException
 
49
    {
 
50
        if (datestr == null || datestr.length() != 27 || datestr.charAt(26) != 'Z')
 
51
        {
 
52
            throw new ParseException("String is not a valid Subversion date", 0);
 
53
        }
 
54
        Date date = formatter.parse(datestr.substring(0, 23) + " UTC");
 
55
        this.cachedString = datestr;
 
56
        cachedDate = Calendar.getInstance(UTC);
 
57
        cachedDate.setTime(date);
 
58
        timeMicros = cachedDate.getTimeInMillis() * 1000
 
59
                        + Integer.parseInt(datestr.substring(23, 26));
 
60
    }
 
61
 
 
62
    /**
 
63
     * Returns the time of the commit in microseconds
 
64
     * @return the time of the commit measured in the number of
 
65
     *         microseconds since 00:00:00 January 1, 1970 UTC
 
66
     */
 
67
    public long getTimeMicros()
 
68
    {
 
69
        return timeMicros;
 
70
    }
 
71
 
 
72
    /**
 
73
     * Returns the time of the commit in milliseconds
 
74
     * @return the time of the commit measured in the number of
 
75
     *         milliseconds since 00:00:00 January 1, 1970 UTC
 
76
     */
 
77
    public long getTimeMillis()
 
78
    {
 
79
        return cachedDate.getTimeInMillis();
 
80
    }
 
81
 
 
82
    /**
 
83
     * Returns the time of the commit as Calendar
 
84
     * @return the time of the commit as java.util.Calendar
 
85
     */
 
86
    public Calendar getCalender()
 
87
    {
 
88
        return cachedDate;
 
89
    }
 
90
 
 
91
    /**
 
92
     * Returns the date of the commit
 
93
     * @return the time of the commit as java.util.Date
 
94
     */
 
95
    public Date getDate()
 
96
    {
 
97
        return cachedDate.getTime();
 
98
    }
 
99
 
 
100
    public String toString()
 
101
    {
 
102
         return cachedString;
 
103
    }
 
104
 
 
105
    public int hashCode()
 
106
    {
 
107
        final int prime = 31;
 
108
        int result = 1;
 
109
        result = prime * result + (int) (timeMicros ^ (timeMicros >>> 32));
 
110
        return result;
 
111
    }
 
112
 
 
113
    public boolean equals(Object obj)
 
114
    {
 
115
        if (this == obj)
 
116
            return true;
 
117
        if (obj == null)
 
118
            return false;
 
119
        if (getClass() != obj.getClass())
 
120
            return false;
 
121
        final LogDate other = (LogDate) obj;
 
122
        if (timeMicros != other.getTimeMicros())
 
123
            return false;
 
124
        return true;
 
125
    }
 
126
 
 
127
}