Class CSSMediaQuery

java.lang.Object
com.helger.css.decl.CSSMediaQuery
All Implemented Interfaces:
ICSSSourceLocationAware, ICSSWriteable

@NotThreadSafe public class CSSMediaQuery extends Object implements ICSSWriteable, ICSSSourceLocationAware
Represents a single media query
Author:
Philip Helger
  • Constructor Details

  • Method Details

    • getModifier

      @Nonnull public final CSSMediaQuery.EModifier getModifier()
      Returns:
      The media query modifier that was used. Never null.
    • isNot

      public final boolean isNot()
      Returns:
      true if the modifier is CSSMediaQuery.EModifier.NOT.
      See Also:
    • isOnly

      public final boolean isOnly()
      Returns:
      true if the modifier is CSSMediaQuery.EModifier.ONLY.
      See Also:
    • getMedium

      @Nullable public final String getMedium()
      Returns:
      The medium passed in the constructor.
    • hasMediaExpressions

      public boolean hasMediaExpressions()
      Returns:
      true if at least a single media expression is present.
    • getMediaExpressionCount

      @Nonnegative public int getMediaExpressionCount()
      Returns:
      The number of contained media expressions. Always ≥ 0.
    • addMediaExpression

      @Nonnull public CSSMediaQuery addMediaExpression(@Nonnull CSSMediaExpression aMediaExpression)
      Append a media expression to the list.
      Parameters:
      aMediaExpression - The media expression to be added. May not be null.
      Returns:
      this
    • addMediaExpression

      @Nonnull public CSSMediaQuery addMediaExpression(@Nonnegative int nIndex, @Nonnull CSSMediaExpression aMediaExpression)
      Add a media expression to the list at the specified index.
      Parameters:
      nIndex - The index where the media expression should be added. Must be ≥ 0.
      aMediaExpression - The media expression to be added. May not be null.
      Returns:
      this
    • removeMediaExpression

      @Nonnull public com.helger.commons.state.EChange removeMediaExpression(@Nullable CSSMediaExpression aMediaExpression)
      Remove the specified media expression.
      Parameters:
      aMediaExpression - The media expression to be removed. May be null.
      Returns:
      EChange.CHANGED if removal succeeded, EChange.UNCHANGED otherwise.
    • removeMediaExpression

      @Nonnull public com.helger.commons.state.EChange removeMediaExpression(int nExpressionIndex)
      Remove the media expression at the specified index.
      Parameters:
      nExpressionIndex - The index of the media expression to be removed.
      Returns:
      EChange.CHANGED if removal succeeded, EChange.UNCHANGED otherwise.
    • removeAllMediaExpressions

      @Nonnull public com.helger.commons.state.EChange removeAllMediaExpressions()
      Remove all media expressions.
      Returns:
      EChange.CHANGED if any media expression was removed, EChange.UNCHANGED otherwise. Never null.
      Since:
      3.7.3
    • getMediaExpression

      @Nullable public CSSMediaExpression getMediaExpression(@Nonnegative int nExpressionIndex)
      Get the media expression at the specified index.
      Parameters:
      nExpressionIndex - The index to be retrieved.
      Returns:
      null if the index is < 0 or too large.
    • getAllMediaExpressions

      @Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSMediaExpression> getAllMediaExpressions()
      Returns:
      A copy of all media expression. Never null but maybe empty.
    • getAsCSSString

      @Nonnull @Nonempty public String getAsCSSString(@Nonnull ICSSWriterSettings aSettings, @Nonnegative int nIndentLevel)
      Description copied from interface: ICSSWriteable
      Get the contents of this object as a serialized CSS string for writing to an output.
      Specified by:
      getAsCSSString in interface ICSSWriteable
      Parameters:
      aSettings - The settings to be used to format the output. May not be null.
      nIndentLevel - The current indentation level
      Returns:
      The content of this object as CSS string. Never null.
    • getSourceLocation

      @Nullable public final CSSSourceLocation getSourceLocation()
      Specified by:
      getSourceLocation in interface ICSSSourceLocationAware
      Returns:
      The source location of this object when it was read by the parser. May be null if an object was not read but manually created.
    • setSourceLocation

      public final void setSourceLocation(@Nullable CSSSourceLocation aSourceLocation)
      Description copied from interface: ICSSSourceLocationAware
      Set the source location of the object, determined while parsing.
      Specified by:
      setSourceLocation in interface ICSSSourceLocationAware
      Parameters:
      aSourceLocation - The source location to use. May be null.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object