Package com.globalmentor.java
Class Packages
java.lang.Object
com.globalmentor.java.Packages
Utilities for manipulating Java packages.
- Author:
- Garret Wilson
-
Method Summary
Modifier and TypeMethodDescriptionstatic Package
Determines the Java package represented by the given URI.static URI
createJavaURI
(Package objectPackage) Creates a Java URI for a Java package using the "java" scheme in the formjava:/com/example/package/
.static URI
createJavaURI
(String objectPackageName) Creates a Java URI for a named Java package using the "java" scheme in the formjava:/com/example/package/
.static String
getFullName
(Package objectPackage, String localName) Creates a full name given package and a local name.static String
getPackageName
(String fullName) Determines the package of the given full name (which can represent the full name of a package or a class).getParentPackageNames
(String packageName) Retrieves a list of names of all parent packages of the given named package.static boolean
isInsidePackage
(Package parentPackage, Class<?> childClass) Determines if the given class is inside the named package.static boolean
isInsidePackage
(Package parentPackage, Package childPackage) Determines if the given package is inside the named package.static boolean
isInsidePackage
(String packageName, String fullName) Determines if the given full name (which can represent the full name of a package or a class) is inside the named package.
-
Method Details
-
asPackage
Determines the Java package represented by the given URI. A URI represents a Java package if it has a "java" scheme in the formjava:/com/example/package/
.- Parameters:
resourceURI
- The URI which is expected to represent a Java package, ornull
.- Returns:
- The Java package represented by the given URI, or
null
if the URI is not ajava:
URI. - Throws:
IllegalArgumentException
- if the given URI represents a Java package that does not have the correct syntax, e.g. it does not have an absolute collection path.ClassNotFoundException
- if the package represented by the given URI could not be found.- See Also:
-
createJavaURI
Creates a Java URI for a Java package using the "java" scheme in the formjava:/com/example/package/
.- Parameters:
objectPackage
- The package to use in creating thejava:
URI.- Returns:
- A
java:
URI based upon the given class. - Throws:
NullPointerException
- if the given package name isnull
.
-
createJavaURI
Creates a Java URI for a named Java package using the "java" scheme in the formjava:/com/example/package/
.- Parameters:
objectPackageName
- The name of the package to use in creating thejava:
URI.- Returns:
- A
java:
URI based upon the given class. - Throws:
NullPointerException
- if the given package name isnull
.
-
getFullName
Creates a full name given package and a local name. For example, a package ofcom.example
and a local name ofBar
will result in a full name ofcom.example.Bar
.- Parameters:
objectPackage
- The object to supply the package name.localName
- The local name for constructing the full name within the package.- Returns:
- A full class name in the given package and the given local name.
- See Also:
-
isInsidePackage
Determines if the given class is inside the named package.- Parameters:
parentPackage
- The package against which to check.childClass
- The class to check to see if it is inside the given package.- Returns:
true
if the given class is inside the given package.- Throws:
NullPointerException
- if the given package and/or class isnull
.
-
isInsidePackage
Determines if the given package is inside the named package.- Parameters:
parentPackage
- The package against which to check.childPackage
- The package to check to see if it is inside the given package.- Returns:
true
if the given child package is inside the given parent package.- Throws:
NullPointerException
- if the given parent package and/or child package isnull
.
-
isInsidePackage
Determines if the given full name (which can represent the full name of a package or a class) is inside the named package.- Parameters:
packageName
- The name of the package against which to check (e.g.com.example
).fullName
- The full package or class name to check to see if it is inside the named package (e.g.com.example.foo
orcom.example.Bar
orcom.example.foo.Bar
).- Returns:
true
if the full-named entity is inside the named package.- Throws:
NullPointerException
- if the given package name and/or full name isnull
.- See Also:
-
getPackageName
Determines the package of the given full name (which can represent the full name of a package or a class).- Parameters:
fullName
- The full package or class name (e.g.Example
orcom.example.foo
orcom.example.Bar
orcom.example.foo.Bar
).- Returns:
- The name of the direct enclosing package, or
null
if the full-named entity is not in a package. - Throws:
NullPointerException
- if the given full name isnull
.- See Also:
-
getParentPackageNames
Retrieves a list of names of all parent packages of the given named package.- Parameters:
packageName
- The name of the package for which parent packages should be listed.- Returns:
- The list, possibly empty, of names of all parent packages, in order of child to parent packages.
- Throws:
NullPointerException
- if the given package name isnull
.- See Also:
-