| /* |
| * Copyright 2006 The Apache Software Foundation |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| * |
| */ |
| package org.apache.felix.bundlerepository; |
| |
| import org.osgi.framework.Version; |
| |
| public class VersionRange |
| { |
| private Version m_low = null; |
| private boolean m_isLowInclusive = false; |
| private Version m_high = null; |
| private boolean m_isHighInclusive = false; |
| |
| public VersionRange(Version low, boolean isLowInclusive, |
| Version high, boolean isHighInclusive) |
| { |
| m_low = low; |
| m_isLowInclusive = isLowInclusive; |
| m_high = high; |
| m_isHighInclusive = isHighInclusive; |
| } |
| |
| public Version getLow() |
| { |
| return m_low; |
| } |
| |
| public boolean isLowInclusive() |
| { |
| return m_isLowInclusive; |
| } |
| |
| public Version getHigh() |
| { |
| return m_high; |
| } |
| |
| public boolean isHighInclusive() |
| { |
| return m_isHighInclusive; |
| } |
| |
| public boolean isInRange(Version version) |
| { |
| // We might not have an upper end to the range. |
| if (m_high == null) |
| { |
| return (version.compareTo(m_low) >= 0); |
| } |
| else if (isLowInclusive() && isHighInclusive()) |
| { |
| return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) <= 0); |
| } |
| else if (isHighInclusive()) |
| { |
| return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) <= 0); |
| } |
| else if (isLowInclusive()) |
| { |
| return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) < 0); |
| } |
| return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) < 0); |
| } |
| |
| public static VersionRange parse(String range) |
| { |
| // Check if the version is an interval. |
| if (range.indexOf(',') >= 0) |
| { |
| String s = range.substring(1, range.length() - 1); |
| String vlo = s.substring(0, s.indexOf(',')); |
| String vhi = s.substring(s.indexOf(',') + 1, s.length()); |
| return new VersionRange ( |
| new Version(vlo), (range.charAt(0) == '['), |
| new Version(vhi), (range.charAt(range.length() - 1) == ']')); |
| } |
| else |
| { |
| return new VersionRange(new Version(range), true, null, false); |
| } |
| } |
| } |