|
Qwylt | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.module.ModuleQuery
public abstract class ModuleQuery
A ModuleArchive Matcher that can be composed into boolean expression
trees. Used to select one or more ModuleArchive instances from a collection
(e.g., a ModuleRepository).
ModuleArchive collections, linear evaluation may be sufficient:
ModuleArchive find(ModuleQuery query, List<ModuleArchive> list) {
for (ModuleArchive archive : list) {
if (query.matches(archive)) {
return archive;
}
}
return null;
}
For scalability, the use of one or more indices is recommended. For example,
if searches using a module name are expected to be common, an index that
maps a module name to the subset of archives with that name will reduce
the number of required evaluations. It may also be desirable to index for
exported package names, attribute names, or even values from a future
ModuleQuery subtype; therefore, this class supports a fully generic
and extensible model for extracting such values from a ModuleQuery.
For example, given the query:
import static java.lang.module.ModuleQuery.*;
...
ModuleQuery query = moduleNameEquals("com.acme.dynamite")
.and(versionMatches(aVersionRange)
.or(attributeExists(anAttribute)));
the findIndexable() method can be used
to extract the name "com.acme.dynamite" and narrow the search:
List list = listAll();
ModuleNameEquals node = findIndexable(ModuleNameEquals.class);
if (node != null) {
String name = node.getModuleName();
list = listByName(name);
}
...
The findIndexable() method ensures that values
are returned only if they may be safely used to narrow a search using an index.
For example, the module name from the following query is not a candidate for
use in an index, so findIndexable() will return
null:
import static module.ModuleQuery.*;
...
ModuleQuery query = not(moduleNameEquals("my.module"));
| Field Summary | |
|---|---|
static ModuleQuery |
ANY
A query that matches any module archive. |
static ModuleQuery |
NONE
A query that does not match any module archive. |
| Constructor Summary | |
|---|---|
ModuleQuery()
|
|
| Method Summary | ||
|---|---|---|
protected java.util.List<ModuleQuery> |
addTo(java.util.List<ModuleQuery> list)
Add this ModuleQuery and any children to the specified list. |
|
protected static java.util.List<ModuleQuery> |
addTo(ModuleQuery query,
java.util.List<ModuleQuery> list)
Add the specified ModuleQuery and any children to the specified list. |
|
ModuleQuery |
and(ModuleQuery right)
Returns a ModuleQuery that is the conjunction of this
instance and the specified query. |
|
static ModuleQuery |
and(ModuleQuery left,
ModuleQuery right)
Returns a ModuleQuery that is the conjunction of two queries. |
|
static ModuleQuery |
any()
Returns a ModuleQuery that matches any archive. |
|
java.util.List<ModuleQuery> |
asList()
Returns this ModuleQuery and all child instances as a list. |
|
static ModuleQuery |
attributeEquals(java.lang.String attributeName,
java.lang.String attributeValue)
Returns a ModuleQuery that tests for the existence of an
attribute and that the values are equal. |
|
static ModuleQuery |
attributeExists(java.lang.String attributeName)
Returns a ModuleQuery that tests for the existence of an
attribute. |
|
static ModuleQuery |
exports(ExportMatcher exportMatcher)
Returns a ModuleQuery that tests for an export. |
|
static ModuleQuery |
exportsPackage(java.lang.String packageName)
Returns a ModuleQuery that tests for an exported package. |
|
static ModuleQuery |
exportsPackage(java.lang.String packageName,
Matcher<Version> versionMatcher)
Returns a ModuleQuery that tests for an exported package, with
optional version matching. |
|
protected
|
find(Indexable<T> indexable)
Match this ModuleQuery and any children against the specified
Indexable, stopping at the first match. |
|
protected static
|
find(ModuleQuery query,
Indexable<T> indexable)
Match the specified ModuleQuery and any children against the specified
Indexable, stopping at the first match. |
|
|
findIndexable(java.lang.Class<T> targetType)
Walk this ModuleQuery and return the first node of
the specified type that is safe to use in an index. |
|
|
instanceOf(java.lang.Class<T> targetType)
Test to see if this ModuleQuery is an instance of the
specified type. |
|
java.util.Iterator<ModuleQuery> |
iterator()
Returns an iterator over this and all child instances. |
|
abstract boolean |
matches(ModuleArchive target)
Tests if the specified target matches this instance. |
|
static ModuleQuery |
moduleNameAndVersionMatch(java.lang.String moduleName,
Matcher<Version> versionMatcher)
Returns a ModuleQuery that matches a module name and a
version, version range or version list. |
|
static ModuleQuery |
moduleNameEquals(java.lang.String moduleName)
Returns a ModuleQuery that matches a module name. |
|
ModuleQuery |
not()
Returns a ModuleQuery that inverts this query. |
|
static ModuleQuery |
not(ModuleQuery query)
Returns a ModuleQuery that inverts the specified query. |
|
ModuleQuery |
or(ModuleQuery right)
Returns a ModuleQuery that is the disjunction of this
instance and the specified query. |
|
static ModuleQuery |
or(ModuleQuery left,
ModuleQuery right)
Returns a ModuleQuery that is the disjunction of two queries. |
|
static ModuleQuery |
versionMatches(Matcher<Version> version)
Returns a ModuleQuery that matches a version, version
range or version list. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final ModuleQuery ANY
public static final ModuleQuery NONE
| Constructor Detail |
|---|
public ModuleQuery()
| Method Detail |
|---|
public abstract boolean matches(ModuleArchive target)
matches in interface Matcher<ModuleArchive>target - The target instance.
true if the specified target matches this instance;
false otherwise.public static ModuleQuery not(ModuleQuery query)
ModuleQuery that inverts the specified query.
query - the specified query.
ModuleQuery object.
public static ModuleQuery and(ModuleQuery left,
ModuleQuery right)
ModuleQuery that is the conjunction of two queries.
left - The left query.right - The right query.
ModuleQuery object.
public static ModuleQuery or(ModuleQuery left,
ModuleQuery right)
ModuleQuery that is the disjunction of two queries.
left - The left query.right - The right query.
ModuleQuery object.public static ModuleQuery any()
ModuleQuery that matches any archive.
ModuleQuery object.public static ModuleQuery versionMatches(Matcher<Version> version)
ModuleQuery that matches a version, version
range or version list.
version - The version matcher.
ModuleQuery object.public static ModuleQuery moduleNameEquals(java.lang.String moduleName)
ModuleQuery that matches a module name.
moduleName - The module name.
ModuleQuery object.
public static ModuleQuery moduleNameAndVersionMatch(java.lang.String moduleName,
Matcher<Version> versionMatcher)
ModuleQuery that matches a module name and a
version, version range or version list.
moduleName - The module name.versionMatcher - The version matcher.
ModuleQuery object.public static ModuleQuery exportsPackage(java.lang.String packageName)
ModuleQuery that tests for an exported package.
packageName - The package name.
ModuleQuery object.
public static ModuleQuery exportsPackage(java.lang.String packageName,
Matcher<Version> versionMatcher)
ModuleQuery that tests for an exported package, with
optional version matching.
packageName - The package name.versionMatcher - The version matcher. May be null.
ModuleQuery object.public static ModuleQuery exports(ExportMatcher exportMatcher)
ModuleQuery that tests for an export.
exportMatcher - The export matcher
ModuleQuery object.public static ModuleQuery attributeExists(java.lang.String attributeName)
ModuleQuery that tests for the existence of an
attribute.
attributeName - The attribute name.
ModuleQuery object.
public static ModuleQuery attributeEquals(java.lang.String attributeName,
java.lang.String attributeValue)
ModuleQuery that tests for the existence of an
attribute and that the values are equal.
attributeName - The attribute name.attributeValue - The attribute value.
ModuleQuery object.public ModuleQuery not()
ModuleQuery that inverts this query.
ModuleQuery object.public ModuleQuery and(ModuleQuery right)
ModuleQuery that is the conjunction of this
instance and the specified query.
right - The right query.
ModuleQuery object.public ModuleQuery or(ModuleQuery right)
ModuleQuery that is the disjunction of this
instance and the specified query.
right - The right query.
ModuleQuery object.public java.util.Iterator<ModuleQuery> iterator()
iterator in interface java.lang.Iterable<ModuleQuery>public java.util.List<ModuleQuery> asList()
ModuleQuery and all child instances as a list.
public <T extends ModuleQuery> T findIndexable(java.lang.Class<T> targetType)
ModuleQuery and return the first node of
the specified type that is safe to use in an index. In this
sequence:
ModuleQuery q = not(attributeExists("foo"));
AttributeExists exists = q.findIndexable(AttributeExists.class);
exists will be set to null. Double negation works
as expected, so that in this sequence:
ModuleQuery q = not(not(attributeExists("foo"));
AttributeExists exists = q.findIndexable(AttributeExists.class);
exists will be valid and can be used to extract the
original attribute name:
String attributeName = exists.getAttributeName();
targetType - The required ModuleQuery subtype.
ModuleQuery instance of the specified
type that may be used in an index or null if not
found or not usable in an index.public <T extends ModuleQuery> boolean instanceOf(java.lang.Class<T> targetType)
ModuleQuery is an instance of the
specified type.
targetType - The required ModuleQuery subtype.
true if this is an instance of the target type;
otherwise, returns false.protected java.util.List<ModuleQuery> addTo(java.util.List<ModuleQuery> list)
ModuleQuery and any children to the specified list.
list - The list to add to.
protected static java.util.List<ModuleQuery> addTo(ModuleQuery query,
java.util.List<ModuleQuery> list)
ModuleQuery and any children to the specified list.
query - The query.list - The list to add to.
protected <T extends ModuleQuery> Indexable<T> find(Indexable<T> indexable)
ModuleQuery and any children against the specified
Indexable, stopping at the first match.
indexable - The indexable to match.
protected static <T extends ModuleQuery> Indexable<T> find(ModuleQuery query,
Indexable<T> indexable)
ModuleQuery and any children against the specified
Indexable, stopping at the first match.
query - The query to walk.indexable - The indexable to match.
|
Qwylt | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||