blob: 87fc25f2937a270a86bd39e2637915ff1c53b383 [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.lib.osgi;
2
Stuart McCullochbb014372012-06-07 21:57:32 +00003/**
4 * Holds the bundle bsn + version pair
Stuart McCullochbb014372012-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 McCulloch2286f232012-06-15 13:27:53 +000030
Stuart McCullochbb014372012-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 McCulloch2286f232012-06-15 13:27:53 +000037 if (result != 0)
Stuart McCullochbb014372012-06-07 21:57:32 +000038 return result;
Stuart McCulloch2286f232012-06-15 13:27:53 +000039
Stuart McCullochbb014372012-06-07 21:57:32 +000040 return version.compareTo(other.version);
41 }
42}