# Class Selector

java.lang.Object
javafx.css.Selector

public abstract sealed class Selector extends Object
Used by `CSSRule` to determine whether or not the `Selector` applies to a given object.

Since:
  9

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Selector()`
  Constructor for subclasses to call.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract boolean`
  `applies(Styleable styleable)`
  Gets whether this `Selector` applies to the given `Styleable`.
  `abstract boolean`
  `applies(Styleable styleable, Set<PseudoClass>[] triggerStates, int depth)`
  Gets whether this `Selector` applies to the given `Styleable`.
  `final Match`
  `createMatch()`
  Creates a `Match`.
  `static Selector`
  `createSelector(String cssSelector)`
  Creates a `Selector` object.
  `int`
  `getOrdinal()`
  Gets the ordinal of this Selector.
  `Rule`
  `getRule()`
  Gets the `Rule` of this Selector.
  `abstract Set<String>`
  `getStyleClassNames()`
  Gets the immutable set of style class names of this Selector.
  `void`
  `setOrdinal(int ordinal)`
  Sets the ordinal of this Selector.
  `abstract boolean`
  `stateMatches(Styleable styleable, Set<PseudoClass> state)`
  Determines whether the current state of the `Node` and its parents matches the pseudo-classes defined (if any) for this selector.

  ### Methods declared in class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Selector

    protected Selector()
    Constructor for subclasses to call.
    Since:
      24

- ## Method Details

  - ### getRule

    public Rule getRule()
    Gets the `Rule` of this Selector.
    Returns:
      rule

  - ### setOrdinal

    public void setOrdinal(int ordinal)
    Sets the ordinal of this Selector.
    Parameters:
      `ordinal` - the ordinal of this Selector

  - ### getOrdinal

    public int getOrdinal()
    Gets the ordinal of this Selector.
    Returns:
      the ordinal of this Selector

  - ### getStyleClassNames

    public abstract Set<String> getStyleClassNames()
    Gets the immutable set of style class names of this Selector.
    Returns:
      an immutable set with style class names, never `null`, or contains `null`s, but can be empty
    Since:
      23

  - ### createMatch

    public final Match createMatch()
    Creates a `Match`.
    Returns:
      a match, never `null`

  - ### applies

    public abstract boolean applies(Styleable styleable)
    Gets whether this `Selector` applies to the given `Styleable`.
    Parameters:
      `styleable` - the `Styleable` to match
    Returns:
      `true` if this `Selector` applies to the given `Styleable`

  - ### applies

    public abstract boolean applies(Styleable styleable, Set<PseudoClass>[] triggerStates, int depth)
    Gets whether this `Selector` applies to the given `Styleable`. It is the same as the `applies(javafx.css.Styleable)` method except it also returns `PseudoClass` state that it finds along the way.
    Parameters:
      `styleable` - the `Styleable` to match
      `triggerStates` - a set of `PseudoClass` states
      `depth` - depth of the `Node` hierarchy to look for
    Returns:
      `true` if this `Selector` and a set of `PseudoClass` applies to the given `Styleable`

  - ### stateMatches

    public abstract boolean stateMatches(Styleable styleable, Set<PseudoClass> state)
    Determines whether the current state of the `Node` and its parents matches the pseudo-classes defined (if any) for this selector.
    Parameters:
      `styleable` - the styleable
      `state` - the state
    Returns:
      `true` if the current state of the node and its parents matches the pseudo-classes defined (if any) for this selector

  - ### createSelector

    public static Selector createSelector(String cssSelector)
    Creates a `Selector` object.
    Parameters:
      `cssSelector` - CSS selector string
    Returns:
      a `Selector`