blob: 2d711ad5c57cad59779aac0f7a7527069ca50ff3 [file] [log] [blame]
Stuart McCulloch42151ee2012-07-16 13:43:38 +00001package aQute.bnd.osgi;
Stuart McCullochf3173222012-06-07 21:57:32 +00002
Stuart McCullochf3173222012-06-07 21:57:32 +00003/**
4 * Holds the bundle bsn + version pair
Stuart McCullochf3173222012-06-07 21:57:32 +00005 */
6public class BundleId implements Comparable<BundleId> {
7 final String bsn;
8 final String version;
9
10 public BundleId(String bsn, String version) {
11 this.bsn = bsn.trim();
12 this.version = version.trim();
13 }
14
15 public String getVersion() {
16 return version;
17 }
18
19 public String getBsn() {
20 return bsn;
21 }
22
23 public boolean isValid() {
24 return Verifier.isVersion(version) && Verifier.isBsn(bsn);
25 }
26
27 public boolean equals(Object o) {
28 return this == o || ((o instanceof BundleId) && compareTo((BundleId) o) == 0);
29 }
Stuart McCulloch4482c702012-06-15 13:27:53 +000030
Stuart McCullochf3173222012-06-07 21:57:32 +000031 public int hashCode() {
32 return bsn.hashCode() ^ version.hashCode();
33 }
34
35 public int compareTo(BundleId other) {
36 int result = bsn.compareTo(other.bsn);
Stuart McCulloch4482c702012-06-15 13:27:53 +000037 if (result != 0)
Stuart McCullochf3173222012-06-07 21:57:32 +000038 return result;
Stuart McCulloch4482c702012-06-15 13:27:53 +000039
Stuart McCullochf3173222012-06-07 21:57:32 +000040 return version.compareTo(other.version);
41 }
42}