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