Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.lib.osgi; |
| 2 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 3 | /** |
| 4 | * Holds the bundle bsn + version pair |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 5 | */ |
| 6 | public 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 McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 30 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 31 | 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 McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 37 | if (result != 0) |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 38 | return result; |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 39 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 40 | return version.compareTo(other.version); |
| 41 | } |
| 42 | } |