Knopflerfish OSGi 4.0.1

org.knopflerfish.util.framework
Class VersionRange

java.lang.Object
  extended by org.knopflerfish.util.framework.VersionRange
All Implemented Interfaces:
java.lang.Comparable<VersionRange>

public class VersionRange
extends java.lang.Object
implements java.lang.Comparable<VersionRange>

Class representing OSGi version ranges.

Author:
Jan Stein

Field Summary
static VersionRange defaultVersionRange
          The empty version range "[0.0.0,inf)".
 
Constructor Summary
protected VersionRange()
          Construct the default VersionRange object.
  VersionRange(java.lang.String vr)
          Construct a VersionRange object.
  VersionRange(java.lang.String filter, java.lang.String key, boolean defaultIfNotSpecified)
          Extract a version range from an OSGi LDAP filter.
 
Method Summary
 int compareTo(VersionRange o)
          Compare object to another VersionRange.
 boolean equals(java.lang.Object obj)
          Check if object is equal to this object.
 int hashCode()
          Hash code for this package entry.
 boolean isSpecified()
           
 java.lang.String toHtmlString()
          HTML-formated range that allays has both a lower and an upper limit.
 java.lang.String toString()
          String with version number.
 boolean withinRange(Version ver)
          Check if specified version is within our range.
 boolean withinRange(VersionRange range)
          Check if objects range is within another VersionRange.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultVersionRange

public static final VersionRange defaultVersionRange
The empty version range "[0.0.0,inf)".

Constructor Detail

VersionRange

public VersionRange(java.lang.String vr)
             throws java.lang.NumberFormatException
Construct a VersionRange object. Format for a range: ( "(" | "[" ) LOW_VERSION "," HIGH_VERSION ( ")" | "]" ) Format for at least a version: VERSION

Parameters:
vr - Input string.
Throws:
java.lang.NumberFormatException

VersionRange

protected VersionRange()
Construct the default VersionRange object.


VersionRange

public VersionRange(java.lang.String filter,
                    java.lang.String key,
                    boolean defaultIfNotSpecified)
Extract a version range from an OSGi LDAP filter. E.g. from a require capability filter like
  (&(osgi.wiring.package=org.kxml.io)(&(version>=0.0.0)(!(version>=1.0.0))))
 

Parameters:
filter - The filter string to process.
key - The attribute name of the version.
defaultIfNotSpecified - if no version is found in the filter then this controls whether to return the default version range or throw IllegalArgumentException.
Throws:
java.lang.IllegalArgumentException - when no version range was found in the filter.
Method Detail

isSpecified

public boolean isSpecified()

withinRange

public boolean withinRange(Version ver)
Check if specified version is within our range.

Parameters:
ver - Version to compare to.
Returns:
Return true if within range, otherwise false.

withinRange

public boolean withinRange(VersionRange range)
Check if objects range is within another VersionRange.

Parameters:
range - VersionRange to compare to.
Returns:
Return true if within range, otherwise false.

compareTo

public int compareTo(VersionRange o)
Compare object to another VersionRange. VersionRanges are compared on the lower bound.

Specified by:
compareTo in interface java.lang.Comparable<VersionRange>
Parameters:
o - VersionRange to compare to.
Returns:
Return 0 if equals, negative if this object is less than obj and positive if this object is larger then obj.
Throws:
java.lang.ClassCastException - if object is not a VersionRange object.

toString

public java.lang.String toString()
String with version number. If version is not specified return an empty string.

Overrides:
toString in class java.lang.Object
Returns:
String.

toHtmlString

public java.lang.String toHtmlString()
HTML-formated range that allays has both a lower and an upper limit.

Returns:
String.

equals

public boolean equals(java.lang.Object obj)
               throws java.lang.ClassCastException
Check if object is equal to this object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Package entry to compare to.
Returns:
true if equal, otherwise false.
Throws:
java.lang.ClassCastException

hashCode

public int hashCode()
Hash code for this package entry.

Overrides:
hashCode in class java.lang.Object
Returns:
int value.

Knopflerfish OSGi 4.0.1