1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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 }