View Javadoc

1   package org.apache.maven.multiproject.harmonizer;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import java.util.ArrayList;
22  import java.util.HashMap;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.maven.project.Project;
28  
29  /**
30   * @author mmaczka
31   *
32   * To change the template for this generated type comment go to
33   * Window>Preferences>Java>Code Generation>Code and Comments
34   */
35  public class MultiDependency implements Comparable
36  {
37      private Map versions = new HashMap();
38      private String id = null;
39     
40      /**
41       * 
42       */
43      public int compareTo(Object obj)
44      {
45          MultiDependency other = (MultiDependency) obj;
46          if (this.isClean() && !other.isClean())
47          {
48              return 1;
49          }
50          if (!this.isClean() && other.isClean())
51          {
52              return -1;
53          }
54          return this.id.compareTo(other.id);
55      }
56      /**
57       * @return
58       */
59      public String getId()
60      {
61          return id;
62      }
63      /**
64       * @param id
65       */
66      public void setId(String id)
67      {
68          this.id = id;
69      }
70      public boolean isClean()
71      {
72          return versions.size() == 1;
73      }
74      /**
75       * 
76       * @param project the name of the project which has this dependecy
77       * @param version the version of the dependecy used in the project
78       */
79      public void add(Project project, String version)
80      {
81          List projectList = null;
82          if (versions.containsKey(version))
83          {
84              projectList = (List) versions.get(version);
85          }
86          else
87          {
88              projectList = new ArrayList();
89              versions.put(version, projectList);
90          }
91          projectList.add(project);
92      }
93      public Iterator getProjects(String version)
94      {
95          List projects = (List) versions.get(version);
96          return projects.iterator();
97      }
98      public Iterator getVersions()
99      {
100         return versions.keySet().iterator();
101     }
102     public String toString()
103     {
104         return id;
105     }
106     /**
107      * @return
108      */
109     public int getNumberOfVersions()
110     {
111         
112         return versions.size();
113     }
114 }