~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/RevisionRange.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
 
 
27
/**
 
28
 * Object that describes a revision range
 
29
 */
 
30
public class RevisionRange implements Comparable<RevisionRange>, java.io.Serializable
 
31
{
 
32
    // Update the serialVersionUID when there is a incompatible change
 
33
    // made to this class.  See any of the following, depending upon
 
34
    // the Java release.
 
35
    // http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/version.doc7.html
 
36
    // http://java.sun.com/j2se/1.4/pdf/serial-spec.pdf
 
37
    // http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/version.html#6678
 
38
    // http://java.sun.com/javase/6/docs/platform/serialization/spec/version.html#6678
 
39
    private static final long serialVersionUID = 1L;
 
40
 
 
41
    private Revision from;
 
42
    private Revision to;
 
43
 
 
44
    /**
 
45
     * Creates a new instance.  Called by native library.
 
46
     */
 
47
    @SuppressWarnings("unused")
 
48
    private RevisionRange(long from, long to)
 
49
    {
 
50
        this.from = Revision.getInstance(from);
 
51
        this.to = Revision.getInstance(to);
 
52
    }
 
53
 
 
54
    public RevisionRange(Revision from, Revision to)
 
55
    {
 
56
        this.from = from;
 
57
        this.to = to;
 
58
    }
 
59
 
 
60
    /**
 
61
     * Accepts a string in one of these forms: n m-n Parses the results into a
 
62
     * from and to revision
 
63
     * @param revisionElement revision range or single revision
 
64
     */
 
65
    public RevisionRange(String revisionElement)
 
66
    {
 
67
        super();
 
68
        if (revisionElement == null)
 
69
        {
 
70
            return;
 
71
        }
 
72
 
 
73
        int hyphen = revisionElement.indexOf('-');
 
74
        if (hyphen > 0)
 
75
        {
 
76
            try
 
77
            {
 
78
                long fromRev = Long
 
79
                        .parseLong(revisionElement.substring(0, hyphen));
 
80
                long toRev = Long.parseLong(revisionElement
 
81
                        .substring(hyphen + 1));
 
82
                this.from = new Revision.Number(fromRev);
 
83
                this.to = new Revision.Number(toRev);
 
84
            }
 
85
            catch (NumberFormatException e)
 
86
            {
 
87
                return;
 
88
            }
 
89
 
 
90
        }
 
91
        else
 
92
        {
 
93
            try
 
94
            {
 
95
                long revNum = Long.parseLong(revisionElement.trim());
 
96
                this.from = new Revision.Number(revNum);
 
97
                this.to = this.from;
 
98
            }
 
99
            catch (NumberFormatException e)
 
100
            {
 
101
                return;
 
102
            }
 
103
        }
 
104
    }
 
105
 
 
106
    public Revision getFromRevision()
 
107
    {
 
108
        return from;
 
109
    }
 
110
 
 
111
    public Revision getToRevision()
 
112
    {
 
113
        return to;
 
114
    }
 
115
 
 
116
    public String toString()
 
117
    {
 
118
        if (from != null && to != null)
 
119
        {
 
120
            if (from.equals(to))
 
121
                return from.toString();
 
122
            else
 
123
                return from.toString() + '-' + to.toString();
 
124
        }
 
125
        return super.toString();
 
126
    }
 
127
 
 
128
    public static Long getRevisionAsLong(Revision rev)
 
129
    {
 
130
        long val = 0;
 
131
        if (rev != null && rev instanceof Revision.Number)
 
132
        {
 
133
            val = ((Revision.Number) rev).getNumber();
 
134
        }
 
135
        return new Long(val);
 
136
    }
 
137
 
 
138
    public int hashCode()
 
139
    {
 
140
        final int prime = 31;
 
141
        int result = 1;
 
142
        result = prime * result + ((from == null) ? 0 : from.hashCode());
 
143
        result = prime * result + ((to == null) ? 0 : to.hashCode());
 
144
        return result;
 
145
    }
 
146
 
 
147
    /**
 
148
     * @param range The RevisionRange to compare this object to.
 
149
     */
 
150
    public boolean equals(Object range)
 
151
    {
 
152
        if (this == range)
 
153
            return true;
 
154
        if (!super.equals(range))
 
155
            return false;
 
156
        if (getClass() != range.getClass())
 
157
            return false;
 
158
 
 
159
        final RevisionRange other = (RevisionRange) range;
 
160
 
 
161
        if (from == null)
 
162
        {
 
163
            if (other.from != null)
 
164
                return false;
 
165
        }
 
166
        else if (!from.equals(other.from))
 
167
        {
 
168
            return false;
 
169
        }
 
170
 
 
171
        if (to == null)
 
172
        {
 
173
            if (other.to != null)
 
174
                return false;
 
175
        }
 
176
        else if (!to.equals(other.to))
 
177
        {
 
178
            return false;
 
179
        }
 
180
 
 
181
        return true;
 
182
    }
 
183
 
 
184
    /**
 
185
     * @param range The RevisionRange to compare this object to.
 
186
     */
 
187
    public int compareTo(RevisionRange range)
 
188
    {
 
189
        if (this == range)
 
190
            return 0;
 
191
 
 
192
        Revision other = (range).getFromRevision();
 
193
        return RevisionRange.getRevisionAsLong(this.getFromRevision())
 
194
            .compareTo(RevisionRange.getRevisionAsLong(other));
 
195
    }
 
196
}