1 | /******************************************************************************* |
2 | * Copyright (c) 2007, 2008 IBM Corporation and others. |
3 | * All rights reserved. This program and the accompanying materials |
4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | * which accompanies this distribution, and is available at |
6 | * http://www.eclipse.org/legal/epl-v10.html |
7 | * |
8 | * Contributors: |
9 | * IBM Corporation - initial API and implementation |
10 | *******************************************************************************/ |
11 | package org.eclipse.pde.api.tools.internal; |
12 | |
13 | import org.eclipse.osgi.service.resolver.VersionRange; |
14 | import org.eclipse.pde.api.tools.internal.provisional.IVersionRange; |
15 | import org.osgi.framework.Version; |
16 | |
17 | /** |
18 | * Implementation of a required component description based on |
19 | * OSGi bundles. |
20 | * |
21 | * @since 1.0.0 |
22 | */ |
23 | public class BundleVersionRange implements IVersionRange { |
24 | |
25 | private VersionRange fRange; |
26 | |
27 | |
28 | /** |
29 | * Constructs a new version range based on the given |
30 | * required bundle version interval. |
31 | * |
32 | * @param versionInterval string representing mathematical interval |
33 | * describing range of compatible versions |
34 | */ |
35 | public BundleVersionRange(String versionInterval) { |
36 | fRange = new VersionRange(versionInterval); |
37 | } |
38 | |
39 | /** |
40 | * Constructs a new version range based on the given range. |
41 | * |
42 | * @param range version range |
43 | */ |
44 | public BundleVersionRange(VersionRange range) { |
45 | fRange = range; |
46 | } |
47 | |
48 | /* (non-Javadoc) |
49 | * @see org.eclipse.pde.api.tools.manifest.IRequiredComponentDescription#getMaximumVersion() |
50 | */ |
51 | public String getMaximumVersion() { |
52 | return fRange.getMaximum().toString(); |
53 | } |
54 | |
55 | /* (non-Javadoc) |
56 | * @see org.eclipse.pde.api.tools.manifest.IRequiredComponentDescription#getMinimumVersion() |
57 | */ |
58 | public String getMinimumVersion() { |
59 | return fRange.getMinimum().toString(); |
60 | } |
61 | |
62 | /* (non-Javadoc) |
63 | * @see org.eclipse.pde.api.tools.manifest.IRequiredComponentDescription#isIncludeMaximum() |
64 | */ |
65 | public boolean isIncludeMaximum() { |
66 | return fRange.getIncludeMaximum(); |
67 | } |
68 | |
69 | /* (non-Javadoc) |
70 | * @see org.eclipse.pde.api.tools.manifest.IRequiredComponentDescription#isIncludeMinimum() |
71 | */ |
72 | public boolean isIncludeMinimum() { |
73 | return fRange.getIncludeMinimum(); |
74 | } |
75 | |
76 | public boolean equals(Object obj) { |
77 | if (obj instanceof BundleVersionRange) { |
78 | BundleVersionRange range = (BundleVersionRange) obj; |
79 | return fRange.equals(range.fRange); |
80 | } |
81 | return false; |
82 | } |
83 | |
84 | /* (non-Javadoc) |
85 | * @see java.lang.Object#hashCode() |
86 | */ |
87 | public int hashCode() { |
88 | return fRange.hashCode(); |
89 | } |
90 | |
91 | public String toString() { |
92 | return fRange.toString(); |
93 | } |
94 | |
95 | /* (non-Javadoc) |
96 | * @see org.eclipse.pde.api.tools.manifest.IVersionRange#isIncluded(java.lang.String) |
97 | */ |
98 | public boolean isIncluded(String version) { |
99 | return fRange.isIncluded(new Version(version)); |
100 | } |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | } |