1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.scm;
20
21 import java.io.Serializable;
22
23 /**
24 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
25 */
26 public class ScmFile implements Comparable<ScmFile>, Serializable {
27 private static final long serialVersionUID = -9133015730693522690L;
28
29 private String path;
30
31 private ScmFileStatus status;
32
33 /**
34 * @param path the relative path of the file, should <b>never</b> start with any {@link java.io.File#separator}
35 * @param status the file status
36 */
37 public ScmFile(String path, ScmFileStatus status) {
38 this.path = path;
39
40 this.status = status;
41 }
42
43 /**
44 * Returns the relative path of the file.
45 *
46 * @return the file path
47 */
48 public String getPath() {
49 return path;
50 }
51
52 /**
53 * @return the file status
54 */
55 public ScmFileStatus getStatus() {
56 return status;
57 }
58
59 // ----------------------------------------------------------------------
60 // Comparable Implementation
61 // ----------------------------------------------------------------------
62
63 /**
64 * {@inheritDoc}
65 */
66 public int compareTo(ScmFile other) {
67 return other.getPath().compareTo(path);
68 }
69
70 // ----------------------------------------------------------------------
71 // Object overrides
72 // ----------------------------------------------------------------------
73
74 /**
75 * {@inheritDoc}
76 */
77 public boolean equals(Object other) {
78 if (!(other instanceof ScmFile)) {
79 return false;
80 }
81
82 return ((ScmFile) other).getPath().equals(path);
83 }
84
85 /**
86 * {@inheritDoc}
87 */
88 public int hashCode() {
89 return path.hashCode();
90 }
91
92 /**
93 * {@inheritDoc}
94 */
95 public String toString() {
96 return "[" + path + ":" + status + "]";
97 }
98 }