1 package org
.argeo
.init
.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 return branches
.get(branchId
);
34 return new A2Branch(this, branchId
);
37 A2Module
getOrAddModule(Version version
, Object locator
) {
38 A2Branch branch
= getOrAddBranch(A2Branch
.versionToBranchId(version
));
39 A2Module module
= branch
.getOrAddModule(version
, locator
);
43 public A2Branch
last() {
44 return branches
.get(branches
.lastKey());
47 public A2Contribution
getContribution() {
51 public String
getId() {
56 public int compareTo(A2Component o
) {
57 return id
.compareTo(o
.id
);
61 public int hashCode() {
66 public boolean equals(Object obj
) {
67 if (obj
instanceof A2Component
) {
68 A2Component o
= (A2Component
) obj
;
69 return contribution
.equals(o
.contribution
) && id
.equals(o
.id
);
75 public String
toString() {
76 return contribution
.getId() + ":" + id
;
79 void asTree(String prefix
, StringBuffer buf
) {
82 A2Branch lastBranch
= last();
83 SortedMap
<String
, A2Branch
> displayMap
= new TreeMap
<>(Collections
.reverseOrder());
84 displayMap
.putAll(branches
);
85 for (String branchId
: displayMap
.keySet()) {
86 A2Branch branch
= displayMap
.get(branchId
);
87 if (!lastBranch
.equals(branch
)) {
95 A2Module first
= branch
.first();
96 A2Module last
= branch
.last();
97 buf
.append(" (").append(last
.getVersion());
98 if (!first
.equals(last
))
99 buf
.append(" ... ").append(first
.getVersion());