]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.osgi.boot/src/org/argeo/osgi/a2/A2Branch.java
1 package org
.argeo
.osgi
.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
;
11 * A logical linear sequence of versions of a given {@link A2Component}. This is
12 * typically a combination of major and minor version, indicating backward
15 public class A2Branch
implements Comparable
<A2Branch
> {
16 private final A2Component component
;
17 private final String id
;
19 final SortedMap
<Version
, A2Module
> modules
= Collections
.synchronizedSortedMap(new TreeMap
<>());
21 public A2Branch(A2Component component
, String id
) {
22 this.component
= component
;
24 component
.branches
.put(id
, this);
27 A2Module
getOrAddModule(Version version
, Object locator
) {
28 if (modules
.containsKey(version
)) {
29 A2Module res
= modules
.get(version
);
30 if (OsgiBootUtils
.isDebug() && !res
.getLocator().equals(locator
)) {
31 OsgiBootUtils
.debug("Inconsistent locator " + locator
+ " (registered: " + res
.getLocator() + ")");
35 return new A2Module(this, version
, locator
);
39 return modules
.get(modules
.lastKey());
43 return modules
.get(modules
.firstKey());
46 A2Component
getComponent() {
55 public int compareTo(A2Branch o
) {
56 return id
.compareTo(id
);
60 public int hashCode() {
65 public boolean equals(Object obj
) {
66 if (obj
instanceof A2Branch
) {
67 A2Branch o
= (A2Branch
) obj
;
68 return component
.equals(o
.component
) && id
.equals(o
.id
);
74 public String
toString() {
75 return getCoordinates();
78 public String
getCoordinates() {
79 return component
+ ":" + id
;
82 static String
versionToBranchId(Version version
) {
83 return version
.getMajor() + "." + version
.getMinor();