1 package org
.argeo
.api
.a2
;
3 import java
.util
.Collections
;
4 import java
.util
.SortedMap
;
5 import java
.util
.TreeMap
;
7 import org
.osgi
.framework
.Version
;
10 * The logical name of a software package. In OSGi's case this is
11 * <code>Bundle-SymbolicName</code>. This is the equivalent of Maven's artifact
14 public class A2Component
implements Comparable
<A2Component
> {
15 private final A2Contribution contribution
;
16 private final String id
;
18 final SortedMap
<String
, A2Branch
> branches
= Collections
.synchronizedSortedMap(new TreeMap
<>());
20 public A2Component(A2Contribution contribution
, String id
) {
21 this.contribution
= contribution
;
23 contribution
.components
.put(id
, this);
26 public Iterable
<A2Branch
> listBranches(Object filter
) {
27 return branches
.values();
30 A2Branch
getOrAddBranch(String branchId
) {
31 if (!branches
.containsKey(branchId
)) {
32 A2Branch a2Branch
= new A2Branch(this, branchId
);
33 branches
.put(branchId
, a2Branch
);
35 return branches
.get(branchId
);
38 A2Module
getOrAddModule(Version version
, Object locator
) {
39 A2Branch branch
= getOrAddBranch(A2Branch
.versionToBranchId(version
));
40 A2Module module
= branch
.getOrAddModule(version
, locator
);
44 public A2Branch
last() {
45 return branches
.get(branches
.lastKey());
48 public A2Contribution
getContribution() {
52 public String
getId() {
57 public int compareTo(A2Component o
) {
58 return id
.compareTo(o
.id
);
62 public int hashCode() {
67 public boolean equals(Object obj
) {
68 if (obj
instanceof A2Component
) {
69 A2Component o
= (A2Component
) obj
;
70 return contribution
.equals(o
.contribution
) && id
.equals(o
.id
);
76 public String
toString() {
77 return contribution
.getId() + ":" + id
;
80 void asTree(String prefix
, StringBuffer buf
) {
83 A2Branch lastBranch
= last();
84 SortedMap
<String
, A2Branch
> displayMap
= new TreeMap
<>(Collections
.reverseOrder());
85 displayMap
.putAll(branches
);
86 for (String branchId
: displayMap
.keySet()) {
87 A2Branch branch
= displayMap
.get(branchId
);
88 if (!lastBranch
.equals(branch
)) {
96 A2Module first
= branch
.first();
97 A2Module last
= branch
.last();
98 buf
.append(" (").append(last
.getVersion());
99 if (!first
.equals(last
))
100 buf
.append(" ... ").append(first
.getVersion());