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:
div { color: red; }
- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description CSSStyleRule()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CSSStyleRule
addDeclaration(int nIndex, CSSDeclaration aNewDeclaration)
Add a new declaration at the specified index.CSSStyleRule
addDeclaration(CSSDeclaration aDeclaration)
Add a new declaration.CSSStyleRule
addSelector(int nIndex, CSSSelector aSelector)
CSSStyleRule
addSelector(int nIndex, ICSSSelectorMember aSingleSelectorMember)
CSSStyleRule
addSelector(CSSSelector aSelector)
CSSStyleRule
addSelector(ICSSSelectorMember aSingleSelectorMember)
boolean
equals(Object o)
com.helger.commons.collection.impl.ICommonsList<CSSDeclaration>
getAllDeclarations()
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>
getAllSelectors()
String
getAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel)
Get the contents of this object as a serialized CSS string for writing to an output.CSSDeclaration
getDeclarationAtIndex(int nIndex)
int
getDeclarationCount()
CSSDeclaration
getDeclarationOfPropertyName(String sPropertyName)
Get the first declaration with the specified property name.CSSSelector
getSelectorAtIndex(int nSelectorIndex)
int
getSelectorCount()
String
getSelectorsAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel)
CSSSourceLocation
getSourceLocation()
boolean
hasDeclarations()
int
hashCode()
boolean
hasSelectors()
com.helger.commons.state.EChange
removeAllDeclarations()
Remove all declarations.com.helger.commons.state.EChange
removeAllSelectors()
Remove all selectors.com.helger.commons.state.EChange
removeDeclaration(int nDeclarationIndex)
Remove the declaration at the specified indexcom.helger.commons.state.EChange
removeDeclaration(CSSDeclaration aDeclaration)
Remove the given declarationcom.helger.commons.state.EChange
removeSelector(int nSelectorIndex)
com.helger.commons.state.EChange
removeSelector(CSSSelector aSelector)
CSSStyleRule
setDeclarationAtIndex(int nIndex, CSSDeclaration aNewDeclaration)
Set the declaration at the specified index with a new one.void
setSourceLocation(CSSSourceLocation aSourceLocation)
Set the source location of the object, determined while parsing.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.css.ICSSWriteable
getAsCSSString, getAsCSSString
-
Methods inherited from interface com.helger.css.decl.IHasCSSDeclarations
addDeclaration, getAllDeclarationsOfPropertyNameCaseInsensitive, getDeclarationOfPropertyNameCaseInsensitive
-
-
-
-
Method Detail
-
hasSelectors
public boolean hasSelectors()
-
getSelectorCount
@Nonnegative public int getSelectorCount()
-
addSelector
@Nonnull public CSSStyleRule addSelector(@Nonnull ICSSSelectorMember aSingleSelectorMember)
-
addSelector
@Nonnull public CSSStyleRule addSelector(@Nonnull CSSSelector aSelector)
-
addSelector
@Nonnull public CSSStyleRule addSelector(@Nonnegative int nIndex, @Nonnull ICSSSelectorMember aSingleSelectorMember)
-
addSelector
@Nonnull public CSSStyleRule addSelector(@Nonnegative int nIndex, @Nonnull CSSSelector aSelector)
-
removeSelector
@Nonnull public com.helger.commons.state.EChange removeSelector(@Nonnull CSSSelector aSelector)
-
removeSelector
@Nonnull public com.helger.commons.state.EChange removeSelector(@Nonnegative int nSelectorIndex)
-
removeAllSelectors
@Nonnull public com.helger.commons.state.EChange removeAllSelectors()
Remove all selectors.- Returns:
EChange.CHANGED
if any selector was removed,EChange.UNCHANGED
otherwise. Nevernull
.- Since:
- 3.7.3
-
getSelectorAtIndex
@Nullable public CSSSelector getSelectorAtIndex(@Nonnegative int nSelectorIndex)
-
getAllSelectors
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSSelector> getAllSelectors()
-
addDeclaration
@Nonnull public CSSStyleRule addDeclaration(@Nonnull CSSDeclaration aDeclaration)
Description copied from interface:IHasCSSDeclarations
Add a new declaration.- Specified by:
addDeclaration
in 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:IHasCSSDeclarations
Add a new declaration at the specified index.- Specified by:
addDeclaration
in 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:IHasCSSDeclarations
Remove the given declaration- Specified by:
removeDeclaration
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Parameters:
aDeclaration
- The declaration to be removed. May not benull
.- Returns:
EChange.CHANGED
if the declaration was successfully removed
-
removeDeclaration
@Nonnull public com.helger.commons.state.EChange removeDeclaration(@Nonnegative int nDeclarationIndex)
Description copied from interface:IHasCSSDeclarations
Remove the declaration at the specified index- Specified by:
removeDeclaration
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Parameters:
nDeclarationIndex
- The index of the declaration to be removed. Must be ≥ 0.- Returns:
EChange.CHANGED
if the declaration was successfully removed,EChange.UNCHANGED
if the index was invalid.
-
removeAllDeclarations
@Nonnull public com.helger.commons.state.EChange removeAllDeclarations()
Description copied from interface:IHasCSSDeclarations
Remove all declarations.- Specified by:
removeAllDeclarations
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Returns:
EChange.CHANGED
if any declaration was removed,EChange.UNCHANGED
otherwise. Nevernull
.
-
getAllDeclarations
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSDeclaration> getAllDeclarations()
- Specified by:
getAllDeclarations
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Returns:
- A mutable, non-
null
copy of all contained declarations.
-
getDeclarationAtIndex
@Nullable public CSSDeclaration getDeclarationAtIndex(@Nonnegative int nIndex)
- Specified by:
getDeclarationAtIndex
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Parameters:
nIndex
- The index to retrieve- Returns:
- The declaration at the specified index or
null
if the index is invalid
-
setDeclarationAtIndex
@Nonnull public CSSStyleRule setDeclarationAtIndex(@Nonnegative int nIndex, @Nonnull CSSDeclaration aNewDeclaration)
Description copied from interface:IHasCSSDeclarations
Set the declaration at the specified index with a new one. If an existing declaration is present at that index, it is overwritten.- Specified by:
setDeclarationAtIndex
in 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:
hasDeclarations
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Returns:
true
if at least one declaration is present,false
if no declaration is present.
-
getDeclarationCount
@Nonnegative public int getDeclarationCount()
- Specified by:
getDeclarationCount
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Returns:
- The number of contained declarations. Always ≥ 0.
-
getDeclarationOfPropertyName
@Nullable public CSSDeclaration getDeclarationOfPropertyName(@Nullable String sPropertyName)
Description copied from interface:IHasCSSDeclarations
Get the first declaration with the specified property name. If no such property name is present,null
is 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:
getDeclarationOfPropertyName
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Parameters:
sPropertyName
- The property name of the declaration to search (e.g.color
). May benull
.- Returns:
null
if 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:IHasCSSDeclarations
Get all declarations within this list that have the specified property name. The comparison happens case insensitive (since v6.0.0).- Specified by:
getAllDeclarationsOfPropertyName
in interfaceIHasCSSDeclarations<CSSStyleRule>
- Parameters:
sPropertyName
- The property name of the declaration to search (e.g.color
). May benull
.- Returns:
- Never
null
but 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:ICSSWriteable
Get the contents of this object as a serialized CSS string for writing to an output.- Specified by:
getAsCSSString
in 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
@Nullable public final CSSSourceLocation getSourceLocation()
- Specified by:
getSourceLocation
in interfaceICSSSourceLocationAware
- 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 interfaceICSSSourceLocationAware
- Parameters:
aSourceLocation
- The source location to use. May benull
.
-
-