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
;
9 class A2Component
implements Comparable
<A2Component
> {
10 private final A2Contribution contribution
;
11 private final String id
;
13 final SortedMap
<String
, A2Branch
> branches
= Collections
.synchronizedSortedMap(new TreeMap
<>());
15 public A2Component(A2Contribution contribution
, String id
) {
16 this.contribution
= contribution
;
18 contribution
.components
.put(id
, this);
21 A2Branch
getOrAddBranch(String branchId
) {
22 if (branches
.containsKey(branchId
))
23 return branches
.get(branchId
);
25 return new A2Branch(this, branchId
);
28 A2Module
getOrAddModule(Version version
, Object locator
) {
29 A2Branch branch
= getOrAddBranch(A2Branch
.versionToBranchId(version
));
30 A2Module module
= branch
.getOrAddModule(version
, locator
);
35 return branches
.get(branches
.lastKey());
38 A2Contribution
getContribution() {
47 public int compareTo(A2Component o
) {
48 return id
.compareTo(o
.id
);
52 public int hashCode() {
57 public boolean equals(Object obj
) {
58 if (obj
instanceof A2Component
) {
59 A2Component o
= (A2Component
) obj
;
60 return contribution
.equals(o
.contribution
) && id
.equals(o
.id
);
66 public String
toString() {
67 return contribution
.getId() + ":" + id
;
70 void asTree(String prefix
, StringBuffer buf
) {
73 A2Branch lastBranch
= last();
74 SortedMap
<String
, A2Branch
> displayMap
= new TreeMap
<>(Collections
.reverseOrder());
75 displayMap
.putAll(branches
);
76 for (String branchId
: displayMap
.keySet()) {
77 A2Branch branch
= displayMap
.get(branchId
);
78 if (!lastBranch
.equals(branch
)) {
86 A2Module first
= branch
.first();
87 A2Module last
= branch
.last();
88 buf
.append(" (").append(last
.getVersion());
89 if (!first
.equals(last
))
90 buf
.append(" ... ").append(first
.getVersion());