1 package org
.argeo
.osgi
.boot
.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 A2Branch
getOrAddBranch(String branchId
) {
27 if (branches
.containsKey(branchId
))
28 return branches
.get(branchId
);
30 return new A2Branch(this, branchId
);
33 A2Module
getOrAddModule(Version version
, Object locator
) {
34 A2Branch branch
= getOrAddBranch(A2Branch
.versionToBranchId(version
));
35 A2Module module
= branch
.getOrAddModule(version
, locator
);
40 return branches
.get(branches
.lastKey());
43 A2Contribution
getContribution() {
52 public int compareTo(A2Component o
) {
53 return id
.compareTo(o
.id
);
57 public int hashCode() {
62 public boolean equals(Object obj
) {
63 if (obj
instanceof A2Component
) {
64 A2Component o
= (A2Component
) obj
;
65 return contribution
.equals(o
.contribution
) && id
.equals(o
.id
);
71 public String
toString() {
72 return contribution
.getId() + ":" + id
;
75 void asTree(String prefix
, StringBuffer buf
) {
78 A2Branch lastBranch
= last();
79 SortedMap
<String
, A2Branch
> displayMap
= new TreeMap
<>(Collections
.reverseOrder());
80 displayMap
.putAll(branches
);
81 for (String branchId
: displayMap
.keySet()) {
82 A2Branch branch
= displayMap
.get(branchId
);
83 if (!lastBranch
.equals(branch
)) {
91 A2Module first
= branch
.first();
92 A2Module last
= branch
.last();
93 buf
.append(" (").append(last
.getVersion());
94 if (!first
.equals(last
))
95 buf
.append(" ... ").append(first
.getVersion());