View Javadoc

1   /*
2    *  Licensed under the Apache License, Version 2.0 (the "License");
3    *  you may not use this file except in compliance with the License.
4    *  You may obtain a copy of the License at
5    *
6    *      http://www.apache.org/licenses/LICENSE-2.0
7    *
8    *  Unless required by applicable law or agreed to in writing, software
9    *  distributed under the License is distributed on an "AS IS" BASIS,
10   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   *  See the License for the specific language governing permissions and
12   *  limitations under the License.
13   */
14  /*
15   * This file has been modified by Chris Pheby in accordance with Section 4.2
16   * of the Apache Software License
17   */
18  package org.jadira.dependencynavigator.model;
19  
20  import org.jadira.dependencynavigator.controller.model.ArtifactVersionsListManager;
21  
22  import java.util.ArrayList;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  /**
27   * Class describing duplicate artifacts in a dependency tree
28   */
29  public class Duplicate {
30      private String identifier;
31      private List<ArtifactInstanceMap> versions;
32      private List<Duplicate> duplicatesList;
33  
34      private boolean selected;
35  
36      public Duplicate(ArtifactInstanceMap map, List<Duplicate> duplicates) {
37          this.identifier = map.getGroupId() + ":" + map.getArtifactId();
38          this.duplicatesList = duplicates;
39          versions = new ArrayList<ArtifactInstanceMap>();
40          versions.add(map);
41      }
42  
43      public void addVersion(ArtifactInstanceMap map) {
44          if (versions.contains(map)) {
45              return;
46          }
47          versions.add(map);
48          if (versions.size() == 2) {
49              duplicatesList.add(this);
50          }
51      }
52  
53      public String getIdentifier() {
54          return identifier;
55      }
56  
57      public void select(boolean state, ArtifactVersionsListManager artifactVersionsListManager) {
58          selected = state;
59          artifactVersionsListManager.select(versions);
60      }
61  
62      public boolean isSelected() {
63          return selected;
64      }
65  
66      public String getVersions() {
67          StringBuffer versionList = new StringBuffer();
68          for (Iterator<ArtifactInstanceMap> iter = versions.iterator(); iter.hasNext();) {
69              ArtifactInstanceMap version = iter.next();
70              versionList.append(version.getVersion());
71              if (iter.hasNext()) {
72                  versionList.append(", ");
73              }
74          }
75          return versionList.toString();
76      }
77  
78  }