]> git.argeo.org Git - lgpl/argeo-commons.git/blob - a2/A2Contribution.java
Prepare next development cycle
[lgpl/argeo-commons.git] / a2 / A2Contribution.java
1 package org.argeo.osgi.boot.a2;
2
3 import java.util.Collections;
4 import java.util.Map;
5 import java.util.TreeMap;
6
7 class A2Contribution implements Comparable<A2Contribution> {
8 final static String BOOT = "boot";
9 final static String RUNTIME = "runtime";
10
11 private final ProvisioningSource source;
12 private final String id;
13
14 final Map<String, A2Component> components = Collections.synchronizedSortedMap(new TreeMap<>());
15
16 public A2Contribution(ProvisioningSource context, String id) {
17 this.source = context;
18 this.id = id;
19 if (context != null)
20 context.contributions.put(id, this);
21 }
22
23 A2Component getOrAddComponent(String componentId) {
24 if (components.containsKey(componentId))
25 return components.get(componentId);
26 else
27 return new A2Component(this, componentId);
28 }
29
30 public ProvisioningSource getSource() {
31 return source;
32 }
33
34 public String getId() {
35 return id;
36 }
37
38 @Override
39 public int compareTo(A2Contribution o) {
40 return id.compareTo(o.id);
41 }
42
43 @Override
44 public int hashCode() {
45 return id.hashCode();
46 }
47
48 @Override
49 public boolean equals(Object obj) {
50 if (obj instanceof A2Contribution) {
51 A2Contribution o = (A2Contribution) obj;
52 return id.equals(o.id);
53 } else
54 return false;
55 }
56
57 @Override
58 public String toString() {
59 return id;
60 }
61
62 void asTree(String prefix, StringBuffer buf) {
63 if (prefix == null)
64 prefix = "";
65 for (String componentId : components.keySet()) {
66 buf.append(prefix);
67 buf.append(componentId);
68 A2Component component = components.get(componentId);
69 component.asTree(prefix, buf);
70 buf.append('\n');
71 }
72 }
73
74 }