# Class PackageInfo

java.lang.Object
org.apache.sling.feature.scanner.PackageInfo

All Implemented Interfaces:
  `Comparable<PackageInfo>`

public class PackageInfo extends Object implements Comparable<PackageInfo>
A package info object contains information about a package, its name, its version and the uses constraints. For example, it is used to return the information about bundle exports and imports. A package info object is immutable.

## Constructor Summary

Constructors
Constructor
Description
`PackageInfo(String name, String version, boolean optional)`
Constructor for a package info
`PackageInfo(String name, String version, boolean optional, Set<String> uses)`
Constructor for a package info

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(PackageInfo o)`
`boolean`
`equals(Object obj)`
`String`
`getName()`
The package name
`org.osgi.framework.Version`
`getPackageVersion()`
Return the package version as a `Version` object.
`org.osgi.framework.VersionRange`
`getPackageVersionRange()`
Return the version as a version range If this package info is used to return info about an export package statement, don't use this method but rather use `getPackageVersion()`
`Set<String>`
`getUses()`
Return the uses constraints
`String`
`getVersion()`
Return the package version
`int`
`hashCode()`
`boolean`
`isOptional()`
Return whether the package is optional
`String`
`toString()`

### Methods inherited from class Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### PackageInfo

public PackageInfo(String name, String version, boolean optional)
Constructor for a package info

Parameters:
  `name` - package name
  `version` - package version
  `optional` - is the package optional

### PackageInfo

public PackageInfo(String name, String version, boolean optional, Set<String> uses)
Constructor for a package info

Parameters:
  `name` - package name
  `version` - package version
  `optional` - is the package optional
  `uses` - Optional uses constraints

## Method Details

### getName

public String getName()
The package name

Returns:
  The package name

### getVersion

public String getVersion()
Return the package version

Returns:
  The package version or {code null}

### isOptional

public boolean isOptional()
Return whether the package is optional

Returns:
  `true` if it is optional

### getPackageVersion

public org.osgi.framework.Version getPackageVersion()
Return the package version as a `Version` object. If this package info is used to return info about an import package statement, don't use this method but rather use `getPackageVersionRange()`

Returns:
  The version or `null`
Throws:
  `IllegalArgumentException` - If the version is not well formed.

### getPackageVersionRange

public org.osgi.framework.VersionRange getPackageVersionRange()
Return the version as a version range If this package info is used to return info about an export package statement, don't use this method but rather use `getPackageVersion()`

Returns:
  The version range or `null`
Throws:
  `IllegalArgumentException` - If the range is not well formed.

### getUses

public Set<String> getUses()
Return the uses constraints

Returns:
  Optional uses constraints, might be empty

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### compareTo

public int compareTo(PackageInfo o)

Specified by:
  `compareTo` in interface `Comparable<PackageInfo>`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`