Package com.helger.css.decl
Class CSSStyleRule
java.lang.Object
com.helger.css.decl.CSSStyleRule
- All Implemented Interfaces:
com.helger.commons.traits.IGenericImplTrait<CSSStyleRule>,ICSSTopLevelRule,IHasCSSDeclarations<CSSStyleRule>,ICSSSourceLocationAware,ICSSWriteable
@NotThreadSafe
public class CSSStyleRule
extends Object
implements ICSSTopLevelRule, IHasCSSDeclarations<CSSStyleRule>, ICSSSourceLocationAware
Represents a single CSS style rule. A style rule consists of a number of
selectors (determine the element to which the style rule applies) and a
number of declarations (the rules to be applied to the selected elements).
Example:
Example:
div { color: red; }- Author:
- Philip Helger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddDeclaration(int nIndex, CSSDeclaration aNewDeclaration) Add a new declaration at the specified index.addDeclaration(CSSDeclaration aDeclaration) Add a new declaration.addSelector(int nIndex, CSSSelector aSelector) addSelector(int nIndex, ICSSSelectorMember aSingleSelectorMember) addSelector(CSSSelector aSelector) addSelector(ICSSSelectorMember aSingleSelectorMember) booleancom.helger.commons.collection.impl.ICommonsList<CSSDeclaration>com.helger.commons.collection.impl.ICommonsList<CSSDeclaration>getAllDeclarationsOfPropertyName(String sPropertyName) Get all declarations within this list that have the specified property name.com.helger.commons.collection.impl.ICommonsList<CSSSelector>getAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel) Get the contents of this object as a serialized CSS string for writing to an output.getDeclarationAtIndex(int nIndex) intgetDeclarationOfPropertyName(String sPropertyName) Get the first declaration with the specified property name.getSelectorAtIndex(int nSelectorIndex) intgetSelectorsAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel) final CSSSourceLocationbooleaninthashCode()booleancom.helger.commons.state.EChangeRemove all declarations.com.helger.commons.state.EChangeRemove all selectors.com.helger.commons.state.EChangeremoveDeclaration(int nDeclarationIndex) Remove the declaration at the specified indexcom.helger.commons.state.EChangeremoveDeclaration(CSSDeclaration aDeclaration) Remove the given declarationcom.helger.commons.state.EChangeremoveSelector(int nSelectorIndex) com.helger.commons.state.EChangeremoveSelector(CSSSelector aSelector) setDeclarationAtIndex(int nIndex, CSSDeclaration aNewDeclaration) Set the declaration at the specified index with a new one.final voidsetSourceLocation(CSSSourceLocation aSourceLocation) Set the source location of the object, determined while parsing.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.css.ICSSWriteable
getAsCSSString, getAsCSSStringMethods inherited from interface com.helger.commons.traits.IGenericImplTrait
thisAsTMethods inherited from interface com.helger.css.decl.IHasCSSDeclarations
addDeclaration, getAllDeclarationsOfPropertyNameCaseInsensitive, getDeclarationOfPropertyNameCaseInsensitive
-
Constructor Details
-
CSSStyleRule
public CSSStyleRule()
-
-
Method Details
-
hasSelectors
public boolean hasSelectors() -
getSelectorCount
-
addSelector
-
addSelector
-
addSelector
@Nonnull public CSSStyleRule addSelector(@Nonnegative int nIndex, @Nonnull ICSSSelectorMember aSingleSelectorMember) -
addSelector
-
removeSelector
-
removeSelector
-
removeAllSelectors
Remove all selectors.- Returns:
EChange.CHANGEDif any selector was removed,EChange.UNCHANGEDotherwise. Nevernull.- Since:
- 3.7.3
-
getSelectorAtIndex
-
getAllSelectors
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSSelector> getAllSelectors() -
addDeclaration
Description copied from interface:IHasCSSDeclarationsAdd a new declaration.- Specified by:
addDeclarationin interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
aDeclaration- The declaration to be added. May not benull.- Returns:
- this
-
addDeclaration
@Nonnull public CSSStyleRule addDeclaration(@Nonnegative int nIndex, @Nonnull CSSDeclaration aNewDeclaration) Description copied from interface:IHasCSSDeclarationsAdd a new declaration at the specified index.- Specified by:
addDeclarationin interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
nIndex- The index to retrieve. Must be ≥ 0. If the index is ≥ thangetDeclarationCount(), it behaves likeIHasCSSDeclarations.addDeclaration(CSSDeclaration).aNewDeclaration- The declaration to be added. May not benull.- Returns:
- this
-
removeDeclaration
@Nonnull public com.helger.commons.state.EChange removeDeclaration(@Nonnull CSSDeclaration aDeclaration) Description copied from interface:IHasCSSDeclarationsRemove the given declaration- Specified by:
removeDeclarationin interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
aDeclaration- The declaration to be removed. May not benull.- Returns:
EChange.CHANGEDif the declaration was successfully removed
-
removeDeclaration
@Nonnull public com.helger.commons.state.EChange removeDeclaration(@Nonnegative int nDeclarationIndex) Description copied from interface:IHasCSSDeclarationsRemove the declaration at the specified index- Specified by:
removeDeclarationin interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
nDeclarationIndex- The index of the declaration to be removed. Must be ≥ 0.- Returns:
EChange.CHANGEDif the declaration was successfully removed,EChange.UNCHANGEDif the index was invalid.
-
removeAllDeclarations
Description copied from interface:IHasCSSDeclarationsRemove all declarations.- Specified by:
removeAllDeclarationsin interfaceIHasCSSDeclarations<CSSStyleRule>- Returns:
EChange.CHANGEDif any declaration was removed,EChange.UNCHANGEDotherwise. Nevernull.
-
getAllDeclarations
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSDeclaration> getAllDeclarations()- Specified by:
getAllDeclarationsin interfaceIHasCSSDeclarations<CSSStyleRule>- Returns:
- A mutable, non-
nullcopy of all contained declarations.
-
getDeclarationAtIndex
- Specified by:
getDeclarationAtIndexin interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
nIndex- The index to retrieve- Returns:
- The declaration at the specified index or
nullif the index is invalid
-
setDeclarationAtIndex
@Nonnull public CSSStyleRule setDeclarationAtIndex(@Nonnegative int nIndex, @Nonnull CSSDeclaration aNewDeclaration) Description copied from interface:IHasCSSDeclarationsSet the declaration at the specified index with a new one. If an existing declaration is present at that index, it is overwritten.- Specified by:
setDeclarationAtIndexin interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
nIndex- The index to retrieve. Must be ≥ 0. If the index is ≥ thangetDeclarationCount(), it behaves likeIHasCSSDeclarations.addDeclaration(CSSDeclaration).aNewDeclaration- The new declaration to be set.- Returns:
- this
-
hasDeclarations
public boolean hasDeclarations()- Specified by:
hasDeclarationsin interfaceIHasCSSDeclarations<CSSStyleRule>- Returns:
trueif at least one declaration is present,falseif no declaration is present.
-
getDeclarationCount
- Specified by:
getDeclarationCountin interfaceIHasCSSDeclarations<CSSStyleRule>- Returns:
- The number of contained declarations. Always ≥ 0.
-
getDeclarationOfPropertyName
Description copied from interface:IHasCSSDeclarationsGet the first declaration with the specified property name. If no such property name is present,nullis returned. If more than one declaration ith the specified property name is present, always the first in the list will be returned. The comparison happens case insensitive (since v6.0.0).- Specified by:
getDeclarationOfPropertyNamein interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
sPropertyName- The property name of the declaration to search (e.g.color). May benull.- Returns:
nullif no such property name was found.
-
getAllDeclarationsOfPropertyName
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSDeclaration> getAllDeclarationsOfPropertyName(@Nullable String sPropertyName) Description copied from interface:IHasCSSDeclarationsGet all declarations within this list that have the specified property name. The comparison happens case insensitive (since v6.0.0).- Specified by:
getAllDeclarationsOfPropertyNamein interfaceIHasCSSDeclarations<CSSStyleRule>- Parameters:
sPropertyName- The property name of the declaration to search (e.g.color). May benull.- Returns:
- Never
nullbut maybe an empty list.
-
getSelectorsAsCSSString
@Nonnull public String getSelectorsAsCSSString(@Nonnull ICSSWriterSettings aSettings, @Nonnegative int nIndentLevel) -
getAsCSSString
@Nonnull public String getAsCSSString(@Nonnull ICSSWriterSettings aSettings, @Nonnegative int nIndentLevel) Description copied from interface:ICSSWriteableGet the contents of this object as a serialized CSS string for writing to an output.- Specified by:
getAsCSSStringin interfaceICSSWriteable- Parameters:
aSettings- The settings to be used to format the output. May not benull.nIndentLevel- The current indentation level- Returns:
- The content of this object as CSS string. Never
null.
-
getSourceLocation
- Specified by:
getSourceLocationin interfaceICSSSourceLocationAware- Returns:
- The source location of this object when it was read by the parser.
May be
nullif an object was not read but manually created.
-
setSourceLocation
Description copied from interface:ICSSSourceLocationAwareSet the source location of the object, determined while parsing.- Specified by:
setSourceLocationin interfaceICSSSourceLocationAware- Parameters:
aSourceLocation- The source location to use. May benull.
-
equals
-
hashCode
public int hashCode() -
toString
-