View Javadoc

1   package org.apache.maven.artifact;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  /**
26   * Type safe enumeration for the artifact status field.
27   *
28   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
29   */
30  public final class ArtifactStatus
31      implements Comparable<ArtifactStatus>
32  {
33      /**
34       * No trust - no information about status.
35       */
36      public static final ArtifactStatus NONE = new ArtifactStatus( "none", 0 );
37  
38      /**
39       * No trust - information was generated with defaults.
40       */
41      public static final ArtifactStatus GENERATED = new ArtifactStatus( "generated", 1 );
42  
43      /**
44       * Low trust - was converted from the Maven 1.x repository.
45       */
46      public static final ArtifactStatus CONVERTED = new ArtifactStatus( "converted", 2 );
47  
48      /**
49       * Moderate trust - it was deployed directly from a partner.
50       */
51      public static final ArtifactStatus PARTNER = new ArtifactStatus( "partner", 3 );
52  
53      /**
54       * Moderate trust - it was deployed directly by a user.
55       */
56      public static final ArtifactStatus DEPLOYED = new ArtifactStatus( "deployed", 4 );
57  
58      /**
59       * Trusted, as it has had its data verified by hand.
60       */
61      public static final ArtifactStatus VERIFIED = new ArtifactStatus( "verified", 5 );
62  
63      private final int rank;
64  
65      private final String key;
66  
67      private static Map<String, ArtifactStatus> map;
68  
69      private ArtifactStatus( String key, int rank )
70      {
71          this.rank = rank;
72          this.key = key;
73  
74          if ( map == null )
75          {
76              map = new HashMap<String, ArtifactStatus>();
77          }
78          map.put( key, this );
79      }
80  
81      public static ArtifactStatus valueOf( String status )
82      {
83          ArtifactStatus retVal = null;
84  
85          if ( status != null )
86          {
87              retVal = map.get( status );
88          }
89  
90          return retVal != null ? retVal : NONE;
91      }
92  
93      public boolean equals( Object o )
94      {
95          if ( this == o )
96          {
97              return true;
98          }
99          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 }