]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.osgi.boot/src/org/argeo/osgi/boot/a2/A2Branch.java
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
.argeo
.osgi
.boot
.OsgiBootUtils
;
8 import org
.osgi
.framework
.Version
;
10 class A2Branch
implements Comparable
<A2Branch
> {
11 private final A2Component component
;
12 private final String id
;
14 final SortedMap
<Version
, A2Module
> modules
= Collections
.synchronizedSortedMap(new TreeMap
<>());
16 A2Branch(A2Component component
, String id
) {
17 this.component
= component
;
19 component
.branches
.put(id
, this);
22 A2Module
getOrAddModule(Version version
, Object locator
) {
23 if (modules
.containsKey(version
)) {
24 A2Module res
= modules
.get(version
);
25 if (OsgiBootUtils
.isDebug() && !res
.getLocator().equals(locator
)) {
26 OsgiBootUtils
.debug("Inconsistent locator " + locator
+ " (registered: " + res
.getLocator() + ")");
30 return new A2Module(this, version
, locator
);
34 return modules
.get(modules
.lastKey());
38 return modules
.get(modules
.firstKey());
41 A2Component
getComponent() {
50 public int compareTo(A2Branch o
) {
51 return id
.compareTo(id
);
55 public int hashCode() {
60 public boolean equals(Object obj
) {
61 if (obj
instanceof A2Branch
) {
62 A2Branch o
= (A2Branch
) obj
;
63 return component
.equals(o
.component
) && id
.equals(o
.id
);
69 public String
toString() {
70 return getCoordinates();
73 public String
getCoordinates() {
74 return component
+ ":" + id
;
77 static String
versionToBranchId(Version version
) {
78 return version
.getMajor() + "." + version
.getMinor();