001package org.apache.maven.artifact;
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.util.HashMap;
023import java.util.Map;
024
025/**
026 * Type safe enumeration for the artifact status field.
027 *
028 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
029 */
030public final class ArtifactStatus
031    implements Comparable<ArtifactStatus>
032{
033    /**
034     * No trust - no information about status.
035     */
036    public static final ArtifactStatus NONE = new ArtifactStatus( "none", 0 );
037
038    /**
039     * No trust - information was generated with defaults.
040     */
041    public static final ArtifactStatus GENERATED = new ArtifactStatus( "generated", 1 );
042
043    /**
044     * Low trust - was converted from the Maven 1.x repository.
045     */
046    public static final ArtifactStatus CONVERTED = new ArtifactStatus( "converted", 2 );
047
048    /**
049     * Moderate trust - it was deployed directly from a partner.
050     */
051    public static final ArtifactStatus PARTNER = new ArtifactStatus( "partner", 3 );
052
053    /**
054     * Moderate trust - it was deployed directly by a user.
055     */
056    public static final ArtifactStatus DEPLOYED = new ArtifactStatus( "deployed", 4 );
057
058    /**
059     * Trusted, as it has had its data verified by hand.
060     */
061    public static final ArtifactStatus VERIFIED = new ArtifactStatus( "verified", 5 );
062
063    private final int rank;
064
065    private final String key;
066
067    private static Map<String, ArtifactStatus> map;
068
069    private ArtifactStatus( String key, int rank )
070    {
071        this.rank = rank;
072        this.key = key;
073
074        if ( map == null )
075        {
076            map = new HashMap<>();
077        }
078        map.put( key, this );
079    }
080
081    public static ArtifactStatus valueOf( String status )
082    {
083        ArtifactStatus retVal = null;
084
085        if ( status != null )
086        {
087            retVal = map.get( status );
088        }
089
090        return retVal != null ? retVal : NONE;
091    }
092
093    public boolean equals( Object o )
094    {
095        if ( this == o )
096        {
097            return true;
098        }
099        if ( o == null || getClass() != o.getClass() )
100        {
101            return false;
102        }
103
104        final ArtifactStatus that = (ArtifactStatus) o;
105
106        return rank == that.rank;
107
108    }
109
110    public int hashCode()
111    {
112        return rank;
113    }
114
115    public String toString()
116    {
117        return key;
118    }
119
120    public int compareTo( ArtifactStatus s )
121    {
122        return rank - s.rank;
123    }
124}