public final class Selectors extends Object
Selector
s and SelectorPart
s.Modifier and Type | Method and Description |
---|---|
static Iterable<SelectorPart> |
adjoining(SelectorPart part)
Gets the non-combinator
SelectorPart s contiguous to this one. |
static <T extends SelectorPart> |
as(Class<T> klass,
SelectorPart part)
Gets the given part as an instance of the given
SelectorPart type. |
static Optional<ClassSelector> |
asClassSelector(SelectorPart part)
Gets the given part as an instance of a
ClassSelector , if it is one. |
static Optional<IdSelector> |
asIdSelector(SelectorPart part)
Gets the given part as an instance of an
IdSelector , if it is one. |
static Optional<PseudoClassSelector> |
asPseudoClassSelector(SelectorPart part)
Gets the given part as an instance of a
PseudoClassSelector if it is one. |
static Optional<PseudoElementSelector> |
asPseudoElementSelector(SelectorPart part)
Gets the given part as an instance of a
PseudoElementSelector if it is one. |
static Optional<TypeSelector> |
asTypeSelector(SelectorPart part)
Gets the given part as an instance of a
TypeSelector if it is one. |
static <T extends SelectorPart> |
filter(Class<T> klass,
Selector selector)
Filters the selector parts in the given
Selector to only the ones of the given class type. |
static Optional<ClassSelector> |
findClassSelector(Iterable<SelectorPart> parts,
String name)
Checks the given parts for the first
ClassSelector that matches the given name. |
static Optional<ClassSelector> |
findClassSelector(Selector selector,
String name)
Checks the given
Selector for a ClassSelector that matches the given name. |
static Optional<IdSelector> |
findIdSelector(Iterable<SelectorPart> parts,
String name)
Checks the given parts for the first
IdSelector that matches the given name. |
static Optional<IdSelector> |
findIdSelector(Selector selector,
String name)
Checks the given
Selector for the first IdSelector that matches the given name. |
static Optional<PseudoClassSelector> |
findPseudoClassSelector(Iterable<SelectorPart> parts,
String name,
boolean exact)
Checks the given parts for the first
PseudoClassSelector that matches the given name. |
static Optional<PseudoClassSelector> |
findPseudoClassSelector(Selector selector,
String name,
boolean exact)
Checks the given
Selector for the first PseudoClassSelector that matches the given name. |
static Optional<PseudoElementSelector> |
findPseudoElementSelector(Iterable<SelectorPart> parts,
String name,
boolean exact)
Checks the given parts for the first
PseudoElementSelector that matches the given name. |
static Optional<PseudoElementSelector> |
findPseudoElementSelector(Selector selector,
String name,
boolean exact)
Checks the given
Selector for the first PseudoElementSelector that matches the given name. |
static Optional<TypeSelector> |
findTypeSelector(Iterable<SelectorPart> parts,
String name)
Checks the given parts for the first
TypeSelector that matches the given name. |
static Optional<TypeSelector> |
findTypeSelector(Selector selector,
String name)
Checks the given
Selector for the first TypeSelector that matches the given name. |
static boolean |
hasClassSelector(Iterable<SelectorPart> parts,
String name)
Checks the given parts for a
ClassSelector that matches the given name. |
static boolean |
hasClassSelector(Selector selector,
String name)
Checks the given parts for a
ClassSelector that matches the given name. |
static boolean |
hasIdSelector(Iterable<SelectorPart> parts,
String name)
Checks the given parts for a
IdSelector that matches the given name. |
static boolean |
hasIdSelector(Selector selector,
String name)
Checks the given parts for a
IdSelector that matches the given name. |
static boolean |
hasPseudoClassSelector(Iterable<SelectorPart> parts,
String name,
boolean exact)
Checks the given parts for a
PseudoClassSelector that matches the given name. |
static boolean |
hasPseudoClassSelector(Selector selector,
String name,
boolean exact)
Checks the given parts for a
PseudoClassSelector that matches the given name. |
static boolean |
hasPseudoElementSelector(Iterable<SelectorPart> parts,
String name,
boolean exact)
Checks the given parts for a
PseudoElementSelector that matches the given name. |
static boolean |
hasPseudoElementSelector(Selector selector,
String name,
boolean exact)
Checks the given parts for a
PseudoElementSelector that matches the given name. |
static boolean |
hasTypeSelector(Iterable<SelectorPart> parts,
String name)
Checks the given parts for a
TypeSelector that matches the given name. |
static boolean |
hasTypeSelector(Selector selector,
String name)
Checks the given parts for a
TypeSelector that matches the given name. |
public static Optional<ClassSelector> asClassSelector(SelectorPart part)
ClassSelector
, if it is one.part
- Check if this part is a ClassSelector
.Optional
if the part is a different type.public static Optional<IdSelector> asIdSelector(SelectorPart part)
IdSelector
, if it is one.part
- Check if this part is a IdSelector
.Optional
if the part is a different type.public static Optional<TypeSelector> asTypeSelector(SelectorPart part)
TypeSelector
if it is one.part
- Check if this part is a TypeSelector
.Optional
if the part is a different type.public static Optional<PseudoElementSelector> asPseudoElementSelector(SelectorPart part)
PseudoElementSelector
if it is one.part
- Check if this part is a PseudoElementSelector
.Optional
if the part is a different type.public static Optional<PseudoClassSelector> asPseudoClassSelector(SelectorPart part)
PseudoClassSelector
if it is one.part
- Check if this part is a PseudoClassSelector
.Optional
if the part is a different type.public static <T extends SelectorPart> Optional<T> as(Class<T> klass, SelectorPart part)
SelectorPart
type.T
- Check if the part is an instance of this class.klass
- Check if the part is an instance of this class.part
- The part to check.Optional
if it doesn't match.public static Optional<ClassSelector> findClassSelector(Selector selector, String name)
Selector
for a ClassSelector
that matches the given name. If you don't actually need the
instance itself then you can use hasClassSelector(Selector, String)
instead.selector
- The selector to check.name
- Check for a ClassSelector
with this name.Optional
if not found.public static Optional<ClassSelector> findClassSelector(Iterable<SelectorPart> parts, String name)
ClassSelector
that matches the given name. If you don't actually need
the instance itself then you can use hasClassSelector(Iterable, String)
instead.parts
- The parts to check.name
- Check for a ClassSelector
with this name.Optional
if not found.public static Optional<IdSelector> findIdSelector(Selector selector, String name)
Selector
for the first IdSelector
that matches the given name. If you don't
actually need the instance itself then you can use hasIdSelector(Selector, String)
instead.selector
- The selector to check.name
- Check for a IdSelector
with this name.Optional
if not found.public static Optional<IdSelector> findIdSelector(Iterable<SelectorPart> parts, String name)
IdSelector
that matches the given name. If you don't actually need
the instance itself then you can use hasIdSelector(Iterable, String)
instead.parts
- The parts to check.name
- Check for a IdSelector
with this name.Optional
if not found.public static Optional<TypeSelector> findTypeSelector(Selector selector, String name)
Selector
for the first TypeSelector
that matches the given name. If you don't
actually need the instance itself then you can use hasTypeSelector(Selector, String)
instead.selector
- The selector to check.name
- Check for a TypeSelector
with this name.Optional
if not found.public static Optional<TypeSelector> findTypeSelector(Iterable<SelectorPart> parts, String name)
TypeSelector
that matches the given name. If you don't actually need
the instance itself then you can use hasTypeSelector(Iterable, String)
instead.parts
- The parts to check.name
- Check for a TypeSelector
with this name.Optional
if not found.public static Optional<PseudoElementSelector> findPseudoElementSelector(Selector selector, String name, boolean exact)
Selector
for the first PseudoElementSelector
that matches the given name. If you
don't actually need the instance itself then you can use hasPseudoElementSelector(Selector, String, boolean)
instead.selector
- The selector to check.name
- Check for a PseudoElementSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.Optional
if not found.public static Optional<PseudoElementSelector> findPseudoElementSelector(Iterable<SelectorPart> parts, String name, boolean exact)
PseudoElementSelector
that matches the given name. If you don't
actually need the instance itself then you can use hasPseudoElementSelector(Iterable, String, boolean)
instead.parts
- The parts to check.name
- Check for a PseudoElementSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.Optional
if not found.public static Optional<PseudoClassSelector> findPseudoClassSelector(Selector selector, String name, boolean exact)
Selector
for the first PseudoClassSelector
that matches the given name. If you
don't actually need the instance itself then you can use hasPseudoClassSelector(Selector, String, boolean)
instead.selector
- The selector to check.name
- Check for a PseudoClassSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.Optional
if not found.public static Optional<PseudoClassSelector> findPseudoClassSelector(Iterable<SelectorPart> parts, String name, boolean exact)
PseudoClassSelector
that matches the given name. If you don't
actually need the instance itself then you can use hasPseudoClassSelector(Iterable, String, boolean)
instead.parts
- The parts to check.name
- Check for a PseudoClassSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.Optional
if not found.public static boolean hasClassSelector(Selector selector, String name)
ClassSelector
that matches the given name.
If you would like access to the found instance itself then use findClassSelector(Selector, String)
instead.
selector
- The Selector
to check.name
- Check for a ClassSelector
with this name.ClassSelector
with the given name.public static boolean hasClassSelector(Iterable<SelectorPart> parts, String name)
ClassSelector
that matches the given name.
If you would like access to the found instance itself then use findClassSelector(Iterable, String)
instead.
parts
- The parts to check.name
- Check for a ClassSelector
with this name.ClassSelector
with the given name.public static boolean hasIdSelector(Selector selector, String name)
IdSelector
that matches the given name.
If you would like access to the found instance itself then use findIdSelector(Selector, String)
instead.
selector
- The Selector
to check.name
- Check for a IdSelector
with this name.IdSelector
with the given name.public static boolean hasIdSelector(Iterable<SelectorPart> parts, String name)
IdSelector
that matches the given name.
If you would like access to the found instance itself then use findIdSelector(Iterable, String)
instead.
parts
- The parts to check.name
- Check for a IdSelector
with this name.IdSelector
with the given name.public static boolean hasTypeSelector(Selector selector, String name)
TypeSelector
that matches the given name.
If you would like access to the found instance itself then use findTypeSelector(Selector, String)
instead.
selector
- The Selector
to check.name
- Check for a TypeSelector
with this name.TypeSelector
with the given name.public static boolean hasTypeSelector(Iterable<SelectorPart> parts, String name)
TypeSelector
that matches the given name.
If you would like access to the found instance itself then use findTypeSelector(Iterable, String)
instead.
parts
- The parts to check.name
- Check for a TypeSelector
with this name.TypeSelector
with the given name.public static boolean hasPseudoElementSelector(Selector selector, String name, boolean exact)
PseudoElementSelector
that matches the given name.
If you would like access to the found instance itself then use findPseudoElementSelector(Selector, String,
boolean)
instead.
selector
- The Selector
to check.name
- Check for a PseudoElementSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.PseudoElementSelector
with the given name.public static boolean hasPseudoElementSelector(Iterable<SelectorPart> parts, String name, boolean exact)
PseudoElementSelector
that matches the given name.
If you would like access to the found instance itself then use findPseudoElementSelector(Iterable, String,
boolean)
instead.
parts
- The parts to check.name
- Check for a PseudoElementSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.PseudoElementSelector
with the given name.public static boolean hasPseudoClassSelector(Selector selector, String name, boolean exact)
PseudoClassSelector
that matches the given name.
If you would like access to the found instance itself then use findPseudoClassSelector(Selector, String, boolean)
instead.
selector
- The Selector
to check.name
- Check for a PseudoClassSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.PseudoClassSelector
with the given name.public static boolean hasPseudoClassSelector(Iterable<SelectorPart> parts, String name, boolean exact)
PseudoClassSelector
that matches the given name.
If you would like access to the found instance itself then use findPseudoClassSelector(Iterable, String, boolean)
instead.
parts
- The parts to check.name
- Check for a PseudoClassSelector
with this name.exact
- Specify true to match the exact name, false to only check the unprefixed portion.PseudoClassSelector
with the given name.public static Iterable<SelectorPart> adjoining(SelectorPart part)
SelectorPart
s contiguous to this one.
If this part is a Combinator
then this method will return a collection of one, containing only this Combinator
instance itself.
If this part is not a Combinator
then this method will return all preceding and subsequent SelectorPart
s up until the first encountered Combinator
. In other words, this will return all parts matching a
single element, such as multiple class selectors.
For example, in this selector:
.test1.test2#test3 .testA.testB#testC
If this
is ".test2", this method will return the ".test1", ".test2", and "#test3" parts.
part
- Get the selector parts adjoining this one.SelectorPart
s.public static <T extends SelectorPart> Iterable<T> filter(Class<T> klass, Selector selector)
Selector
to only the ones of the given class type.
Example:
Iterable<ClassSelector> classes = Selectors.filter(ClassSelector.class, selector);
T
- Filters to parts of this type.klass
- Filter to parts of this class.selector
- The Selector
to filter.Copyright (c) 2019, Salesforce.com, Inc. All rights reserved. Licensed under the BSD 3-Clause license. For full license text, see the LICENSE file in the repository.