com.mcdermottroe.exemplar.utils
Class Packages

java.lang.Object
  extended by com.mcdermottroe.exemplar.utils.Packages

public final class Packages
extends Object

General purpose utility methods that can be used anywhere in the program.

Since:
0.2

Field Summary
private static List<String> allPackages
          Package discovery is an expensive operation so it is done once and the result is cached here.
 
Constructor Summary
private Packages()
          Private constructor to prevent instantiation of this class.
 
Method Summary
private static List<String> findPackages()
          Find the available packages in the classpath.
static List<String> findSubPackages(String packageName)
          Find all of the packages below a certain package.
private static List<String> readPackagesFromDir(URL url, String pkg)
          Find the packages in a directory in a classpath.
private static List<String> readPackagesFromJar(URL url)
          Given a URL of a JAR file, read all of the packages contained within it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

allPackages

private static List<String> allPackages
Package discovery is an expensive operation so it is done once and the result is cached here.

See Also:
findPackages(), findSubPackages(String)
Constructor Detail

Packages

private Packages()
Private constructor to prevent instantiation of this class.

Method Detail

findSubPackages

public static List<String> findSubPackages(String packageName)
Find all of the packages below a certain package.

Parameters:
packageName - The package to search below.
Returns:
A List of all of the sub-packages of the given package, not including packageName itself.

findPackages

private static List<String> findPackages()
Find the available packages in the classpath. The result of this method call cannot change during one execution of the program and hence it is cached in the member allPackages after the first call.

Returns:
A list of all of the packages currently visible in the classpath.
See Also:
ClassLoader

readPackagesFromJar

private static List<String> readPackagesFromJar(URL url)
Given a URL of a JAR file, read all of the packages contained within it.

Parameters:
url - The URL of the JAR file to read from.
Returns:
A List of packages contained within the JAR file.

readPackagesFromDir

private static List<String> readPackagesFromDir(URL url,
                                                String pkg)
Find the packages in a directory in a classpath.

Parameters:
url - A URL pointing to the directory.
pkg - The root package to find from.
Returns:
A List of packages found in the given directory.