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 */
026public class ScmFile implements Comparable<ScmFile>, Serializable {
027    private static final long serialVersionUID = -9133015730693522690L;
028
029    private String path;
030
031    private ScmFileStatus status;
032
033    /**
034     * @param path   the relative path of the file, should <b>never</b> start with any {@link java.io.File#separator}
035     * @param status the file status
036     */
037    public ScmFile(String path, ScmFileStatus status) {
038        this.path = path;
039
040        this.status = status;
041    }
042
043    /**
044     * Returns the relative path of the file.
045     *
046     * @return the file path
047     */
048    public String getPath() {
049        return path;
050    }
051
052    /**
053     * @return the file status
054     */
055    public ScmFileStatus getStatus() {
056        return status;
057    }
058
059    // ----------------------------------------------------------------------
060    // Comparable Implementation
061    // ----------------------------------------------------------------------
062
063    /**
064     * {@inheritDoc}
065     */
066    public int compareTo(ScmFile other) {
067        return other.getPath().compareTo(path);
068    }
069
070    // ----------------------------------------------------------------------
071    // Object overrides
072    // ----------------------------------------------------------------------
073
074    /**
075     * {@inheritDoc}
076     */
077    public boolean equals(Object other) {
078        if (!(other instanceof ScmFile)) {
079            return false;
080        }
081
082        return ((ScmFile) other).getPath().equals(path);
083    }
084
085    /**
086     * {@inheritDoc}
087     */
088    public int hashCode() {
089        return path.hashCode();
090    }
091
092    /**
093     * {@inheritDoc}
094     */
095    public String toString() {
096        return "[" + path + ":" + status + "]";
097    }
098}