001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.scm;
020
021import java.io.Serializable;
022
023/**
024 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
025 *
026 */
027public class ScmFile implements Comparable<ScmFile>, Serializable {
028    private static final long serialVersionUID = -9133015730693522690L;
029
030    private String path;
031
032    private ScmFileStatus status;
033
034    /**
035     * @param path   The relative path of the file, should <b>never</b> start with any {@link java.io.File#separator}.
036     * @param status The file status
037     */
038    public ScmFile(String path, ScmFileStatus status) {
039        this.path = path;
040
041        this.status = status;
042    }
043
044    /**
045     * Returns the relative path of the file.
046     *
047     * @return the file path
048     */
049    public String getPath() {
050        return path;
051    }
052
053    /**
054     * @return The file status
055     */
056    public ScmFileStatus getStatus() {
057        return status;
058    }
059
060    // ----------------------------------------------------------------------
061    // Comparable Implementation
062    // ----------------------------------------------------------------------
063
064    /** {@inheritDoc} */
065    public int compareTo(ScmFile other) {
066        return other.getPath().compareTo(path);
067    }
068
069    // ----------------------------------------------------------------------
070    // Object overrides
071    // ----------------------------------------------------------------------
072
073    /** {@inheritDoc} */
074    public boolean equals(Object other) {
075        if (!(other instanceof ScmFile)) {
076            return false;
077        }
078
079        return ((ScmFile) other).getPath().equals(path);
080    }
081
082    /** {@inheritDoc} */
083    public int hashCode() {
084        return path.hashCode();
085    }
086
087    /** {@inheritDoc} */
088    public String toString() {
089        return "[" + path + ":" + status + "]";
090    }
091}