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
12
* http://www.apache.org/licenses/LICENSE-2.0
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
20
* ====================================================================
24
package org.apache.subversion.javahl.types;
28
* Object that describes a revision range
30
public class RevisionRange implements Comparable<RevisionRange>, java.io.Serializable
32
// Update the serialVersionUID when there is a incompatible change
33
// made to this class. See any of the following, depending upon
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;
41
private Revision from;
45
* Creates a new instance. Called by native library.
47
@SuppressWarnings("unused")
48
private RevisionRange(long from, long to)
50
this.from = Revision.getInstance(from);
51
this.to = Revision.getInstance(to);
54
public RevisionRange(Revision from, Revision to)
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
65
public RevisionRange(String revisionElement)
68
if (revisionElement == null)
73
int hyphen = revisionElement.indexOf('-');
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);
85
catch (NumberFormatException e)
95
long revNum = Long.parseLong(revisionElement.trim());
96
this.from = new Revision.Number(revNum);
99
catch (NumberFormatException e)
106
public Revision getFromRevision()
111
public Revision getToRevision()
116
public String toString()
118
if (from != null && to != null)
121
return from.toString();
123
return from.toString() + '-' + to.toString();
125
return super.toString();
128
public static Long getRevisionAsLong(Revision rev)
131
if (rev != null && rev instanceof Revision.Number)
133
val = ((Revision.Number) rev).getNumber();
135
return new Long(val);
138
public int hashCode()
140
final int prime = 31;
142
result = prime * result + ((from == null) ? 0 : from.hashCode());
143
result = prime * result + ((to == null) ? 0 : to.hashCode());
148
* @param range The RevisionRange to compare this object to.
150
public boolean equals(Object range)
154
if (!super.equals(range))
156
if (getClass() != range.getClass())
159
final RevisionRange other = (RevisionRange) range;
163
if (other.from != null)
166
else if (!from.equals(other.from))
173
if (other.to != null)
176
else if (!to.equals(other.to))
185
* @param range The RevisionRange to compare this object to.
187
public int compareTo(RevisionRange range)
192
Revision other = (range).getFromRevision();
193
return RevisionRange.getRevisionAsLong(this.getFromRevision())
194
.compareTo(RevisionRange.getRevisionAsLong(other));