blob: 67f9b4a648d242daa75a08a1c5298501d4661666 [file] [log] [blame]
Stuart McCulloch39cc9ac2012-07-16 13:43:38 +00001package aQute.bnd.osgi;
Stuart McCullochbb014372012-06-07 21:57:32 +00002
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
Stuart McCulloch55d4dfe2012-08-07 10:57:21 +000027 @Override
Stuart McCullochbb014372012-06-07 21:57:32 +000028 public boolean equals(Object o) {
29 return this == o || ((o instanceof BundleId) && compareTo((BundleId) o) == 0);
30 }
Stuart McCulloch2286f232012-06-15 13:27:53 +000031
Stuart McCulloch55d4dfe2012-08-07 10:57:21 +000032 @Override
Stuart McCullochbb014372012-06-07 21:57:32 +000033 public int hashCode() {
34 return bsn.hashCode() ^ version.hashCode();
35 }
36
37 public int compareTo(BundleId other) {
38 int result = bsn.compareTo(other.bsn);
Stuart McCulloch2286f232012-06-15 13:27:53 +000039 if (result != 0)
Stuart McCullochbb014372012-06-07 21:57:32 +000040 return result;
Stuart McCulloch2286f232012-06-15 13:27:53 +000041
Stuart McCullochbb014372012-06-07 21:57:32 +000042 return version.compareTo(other.version);
43 }
44}