]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.init/src/org/argeo/init/a2/A2Branch.java
1 package org
.argeo
.init
.a2
;
3 import java
.util
.Collections
;
4 import java
.util
.SortedMap
;
5 import java
.util
.TreeMap
;
7 import org
.argeo
.init
.osgi
.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 public Iterable
<A2Module
> listModules(Object filter
) {
28 return modules
.values();
31 A2Module
getOrAddModule(Version version
, Object locator
) {
32 if (modules
.containsKey(version
)) {
33 A2Module res
= modules
.get(version
);
34 if (OsgiBootUtils
.isDebug() && !res
.getLocator().equals(locator
)) {
35 OsgiBootUtils
.debug("Inconsistent locator " + locator
+ " (registered: " + res
.getLocator() + ")");
39 return new A2Module(this, version
, locator
);
42 public A2Module
last() {
43 return modules
.get(modules
.lastKey());
46 public A2Module
first() {
47 return modules
.get(modules
.firstKey());
50 public A2Component
getComponent() {
54 public String
getId() {
59 public int compareTo(A2Branch o
) {
60 return id
.compareTo(id
);
64 public int hashCode() {
69 public boolean equals(Object obj
) {
70 if (obj
instanceof A2Branch
) {
71 A2Branch o
= (A2Branch
) obj
;
72 return component
.equals(o
.component
) && id
.equals(o
.id
);
78 public String
toString() {
79 return getCoordinates();
82 public String
getCoordinates() {
83 return component
+ ":" + id
;
86 static String
versionToBranchId(Version version
) {
87 return version
.getMajor() + "." + version
.getMinor();