Package com.helger.css.decl
Class AbstractHasTopLevelRules
- java.lang.Object
-
- com.helger.css.decl.AbstractHasTopLevelRules
-
- Direct Known Subclasses:
CascadingStyleSheet
,CSSMediaRule
,CSSSupportsRule
@NotThreadSafe public abstract class AbstractHasTopLevelRules extends Object
Abstract base class for all classes having top-level rules.- Since:
- 5.0.5
- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description protected com.helger.commons.collection.impl.ICommonsList<ICSSTopLevelRule>
m_aRules
-
Constructor Summary
Constructors Constructor Description AbstractHasTopLevelRules()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AbstractHasTopLevelRules
addRule(int nIndex, ICSSTopLevelRule aRule)
Add a new top-level rule at the specified index.AbstractHasTopLevelRules
addRule(ICSSTopLevelRule aRule)
Add a new top-level rule at the end.com.helger.commons.collection.impl.ICommonsList<CSSFontFaceRule>
getAllFontFaceRules()
Get a list of all top-level rules that are font-face rules (implementingCSSFontFaceRule
).com.helger.commons.collection.impl.ICommonsList<CSSKeyframesRule>
getAllKeyframesRules()
Get a list of all top-level rules that are keyframes rules (implementingCSSKeyframesRule
).com.helger.commons.collection.impl.ICommonsList<CSSMediaRule>
getAllMediaRules()
Get a list of all top-level rules that are media rules (implementingCSSMediaRule
).com.helger.commons.collection.impl.ICommonsList<CSSPageRule>
getAllPageRules()
Get a list of all top-level rules that are page rules (implementingCSSPageRule
).com.helger.commons.collection.impl.ICommonsList<ICSSTopLevelRule>
getAllRules()
Get a copy of all contained top-level rules.com.helger.commons.collection.impl.ICommonsList<ICSSTopLevelRule>
getAllRules(Predicate<? super ICSSTopLevelRule> aFilter)
Get a copy of all contained top-level rules.com.helger.commons.collection.impl.ICommonsList<CSSStyleRule>
getAllStyleRules()
Get a list of all top-level rules that are style rules (implementingCSSStyleRule
).com.helger.commons.collection.impl.ICommonsList<CSSSupportsRule>
getAllSupportsRules()
Get a list of all top-level rules that are support rules (implementingCSSSupportsRule
).com.helger.commons.collection.impl.ICommonsList<CSSUnknownRule>
getAllUnknownRules()
Get a list of all top-level rules that are unknown rules (implementingCSSUnknownRule
).com.helger.commons.collection.impl.ICommonsList<CSSViewportRule>
getAllViewportRules()
Get a list of all top-level rules that are viewport rules (implementingCSSViewportRule
).CSSFontFaceRule
getFontFaceRuleAtIndex(int nIndex)
Get the@font-face
rule at the specified index.int
getFontFaceRuleCount()
Get the number of top-level rules that are font-face rules (implementingCSSFontFaceRule
).CSSKeyframesRule
getKeyframesRuleAtIndex(int nIndex)
Get the@keyframes
rule at the specified index.int
getKeyframesRuleCount()
Get the number of top-level rules that are keyframes rules (implementingCSSKeyframesRule
).CSSMediaRule
getMediaRuleAtIndex(int nIndex)
Get the@media
rule at the specified index.int
getMediaRuleCount()
Get the number of top-level rules that are media rules (implementingCSSMediaRule
).CSSPageRule
getPageRuleAtIndex(int nIndex)
Get the@page
rule at the specified index.int
getPageRuleCount()
Get the number of top-level rules that are page rules (implementingCSSPageRule
).ICSSTopLevelRule
getRule(int nIndex)
Deprecated.UsegetRuleAtIndex(int)
insteadICSSTopLevelRule
getRuleAtIndex(int nIndex)
Get the top-level rule at the specified index.int
getRuleCount()
Get the number of total contained top-level rules.CSSStyleRule
getStyleRuleAtIndex(int nIndex)
Get the style rule at the specified index.int
getStyleRuleCount()
Get the number of top-level rules that are style rules (implementingCSSStyleRule
).CSSSupportsRule
getSupportsRuleAtIndex(int nIndex)
Get the@supports
rule at the specified index.int
getSupportsRuleCount()
Get the number of top-level rules that are support rules (implementingCSSSupportsRule
).CSSUnknownRule
getUnknownRuleAtIndex(int nIndex)
Get the unknown rule at the specified index.int
getUnknownRuleCount()
Get the number of top-level rules that are unknown rules (implementingCSSUnknownRule
).CSSViewportRule
getViewportRuleAtIndex(int nIndex)
Get the@viewport
rule at the specified index.int
getViewportRuleCount()
Get the number of top-level rules that are viewport rules (implementingCSSViewportRule
).boolean
hasFontFaceRules()
Check if at least one of the top-level rules is a font-face rule (implementingCSSFontFaceRule
).boolean
hasKeyframesRules()
Check if at least one of the top-level rules is a keyframes rule (implementingCSSKeyframesRule
).boolean
hasMediaRules()
Check if at least one of the top-level rules is a media rule (implementingCSSMediaRule
).boolean
hasPageRules()
Check if at least one of the top-level rules is a page rule (implementingCSSPageRule
).boolean
hasRules()
Check if any top-level rule.boolean
hasStyleRules()
Check if at least one of the top-level rules is a style rule (implementingCSSStyleRule
).boolean
hasSupportsRules()
Check if at least one of the top-level rules is a supports rule (implementingCSSSupportsRule
).boolean
hasUnknownRules()
Check if at least one of the top-level rules is an unknown rule (implementingCSSUnknownRule
).boolean
hasViewportRules()
Check if at least one of the top-level rules is a viewport rule (implementingCSSViewportRule
).com.helger.commons.state.EChange
removeAllRules()
Remove all top-level rules.com.helger.commons.state.EChange
removeRule(int nRuleIndex)
Remove the rule at the specified index.com.helger.commons.state.EChange
removeRule(ICSSTopLevelRule aRule)
Remove the specified top-level rule.com.helger.commons.state.EChange
removeRules(Predicate<? super ICSSTopLevelRule> aFilter)
Remove all rules matching the passed predicate.
-
-
-
Field Detail
-
m_aRules
protected final com.helger.commons.collection.impl.ICommonsList<ICSSTopLevelRule> m_aRules
-
-
Method Detail
-
hasRules
public boolean hasRules()
Check if any top-level rule. This method only considers top-level rules and not@import
and@namespace
rules!- Returns:
true
if at least one top-level rule is present,false
if otherwise.
-
getRuleCount
@Nonnegative public int getRuleCount()
Get the number of total contained top-level rules. This method only considers top-level rules and not@import
and@namespace
rules!- Returns:
- The number of total contained top-level rules. Always ≥ 0.
-
getRule
@Nullable @Deprecated public ICSSTopLevelRule getRule(@Nonnegative int nIndex)
Deprecated.UsegetRuleAtIndex(int)
insteadGet the top-level rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getRuleAtIndex
@Nullable public ICSSTopLevelRule getRuleAtIndex(@Nonnegative int nIndex)
Get the top-level rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
addRule
@Nonnull public AbstractHasTopLevelRules addRule(@Nonnull ICSSTopLevelRule aRule)
Add a new top-level rule at the end. This method only considers top-level rules and not@import
and@namespace
rules!- Parameters:
aRule
- The rule to be added. May not benull
.- Returns:
- this
-
addRule
@Nonnull public AbstractHasTopLevelRules addRule(@Nonnegative int nIndex, @Nonnull ICSSTopLevelRule aRule)
Add a new top-level rule at the specified index. This method only considers top-level rules and not@import
and@namespace
rules!- Parameters:
nIndex
- The index where the top-level rule should be added. Must be ≥ 0.aRule
- The rule to be added. May not benull
.- Returns:
- this
-
removeRule
@Nonnull public com.helger.commons.state.EChange removeRule(@Nullable ICSSTopLevelRule aRule)
Remove the specified top-level rule. This method only considers top-level rules and not@import
and@namespace
rules!- Parameters:
aRule
- The rule to be removed. May benull
.- Returns:
EChange.CHANGED
if the rule was successfully removed,EChange.UNCHANGED
otherwise. Nevernull
.
-
removeRule
@Nonnull public com.helger.commons.state.EChange removeRule(@Nonnegative int nRuleIndex)
Remove the rule at the specified index. This method only considers top-level rules and not@import
and@namespace
rules!- Parameters:
nRuleIndex
- The index of the rule to be removed. Should be ≥ 0.- Returns:
EChange.CHANGED
if the rule at the specified index was successfully removed,EChange.UNCHANGED
otherwise. Nevernull
.
-
removeRules
@Nonnull public com.helger.commons.state.EChange removeRules(@Nonnull Predicate<? super ICSSTopLevelRule> aFilter)
Remove all rules matching the passed predicate.- Parameters:
aFilter
- The predicate to apply for deletion. May not benull
.- Returns:
EChange.CHANGED
it at least one rule was removed,EChange.UNCHANGED
otherwise.- Since:
- 5.0.0
-
removeAllRules
@Nonnull public com.helger.commons.state.EChange removeAllRules()
Remove all top-level rules.- Returns:
EChange.CHANGED
if any rule was removed,EChange.UNCHANGED
otherwise. Nevernull
.- Since:
- 3.7.3
-
getAllRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<ICSSTopLevelRule> getAllRules()
Get a copy of all contained top-level rules. This method only considers top-level rules and not@import
and@namespace
rules!- Returns:
- A copy of all contained top-level rules. Never
null
.
-
getAllRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<ICSSTopLevelRule> getAllRules(@Nonnull Predicate<? super ICSSTopLevelRule> aFilter)
Get a copy of all contained top-level rules. This method only considers top-level rules and not@import
and@namespace
rules!- Parameters:
aFilter
- The predicate to be applied- Returns:
- A copy of all contained top-level rules. Never
null
.
-
hasStyleRules
public boolean hasStyleRules()
Check if at least one of the top-level rules is a style rule (implementingCSSStyleRule
).- Returns:
true
if at least one style rule is contained,false
otherwise.
-
getStyleRuleCount
@Nonnegative public int getStyleRuleCount()
Get the number of top-level rules that are style rules (implementingCSSStyleRule
).- Returns:
- The number of contained style rules. Always ≥ 0.
-
getStyleRuleAtIndex
@Nullable public CSSStyleRule getStyleRuleAtIndex(@Nonnegative int nIndex)
Get the style rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getStyleRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllStyleRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSStyleRule> getAllStyleRules()
Get a list of all top-level rules that are style rules (implementingCSSStyleRule
).- Returns:
- A copy of all contained style rules. Never
null
.
-
hasPageRules
public boolean hasPageRules()
Check if at least one of the top-level rules is a page rule (implementingCSSPageRule
).- Returns:
true
if at least one@page
rule is contained,false
otherwise.
-
getPageRuleCount
@Nonnegative public int getPageRuleCount()
Get the number of top-level rules that are page rules (implementingCSSPageRule
).- Returns:
- The number of contained
@page
rules. Always ≥ 0.
-
getPageRuleAtIndex
@Nullable public CSSPageRule getPageRuleAtIndex(@Nonnegative int nIndex)
Get the@page
rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getPageRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllPageRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSPageRule> getAllPageRules()
Get a list of all top-level rules that are page rules (implementingCSSPageRule
).- Returns:
- A copy of all contained
@page
rules. Nevernull
.
-
hasMediaRules
public boolean hasMediaRules()
Check if at least one of the top-level rules is a media rule (implementingCSSMediaRule
).- Returns:
true
if at least one@media
rule is contained,false
otherwise.
-
getMediaRuleCount
@Nonnegative public int getMediaRuleCount()
Get the number of top-level rules that are media rules (implementingCSSMediaRule
).- Returns:
- The number of contained
@media
rules. Always ≥ 0.
-
getMediaRuleAtIndex
@Nullable public CSSMediaRule getMediaRuleAtIndex(@Nonnegative int nIndex)
Get the@media
rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getMediaRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllMediaRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSMediaRule> getAllMediaRules()
Get a list of all top-level rules that are media rules (implementingCSSMediaRule
).- Returns:
- A copy of all contained
@media
rules. Nevernull
.
-
hasFontFaceRules
public boolean hasFontFaceRules()
Check if at least one of the top-level rules is a font-face rule (implementingCSSFontFaceRule
).- Returns:
true
if at least one@font-face
rule is contained,false
otherwise.
-
getFontFaceRuleCount
@Nonnegative public int getFontFaceRuleCount()
Get the number of top-level rules that are font-face rules (implementingCSSFontFaceRule
).- Returns:
- The number of contained
@font-face
rules. Always ≥ 0.
-
getFontFaceRuleAtIndex
@Nullable public CSSFontFaceRule getFontFaceRuleAtIndex(@Nonnegative int nIndex)
Get the@font-face
rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getFontFaceRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllFontFaceRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSFontFaceRule> getAllFontFaceRules()
Get a list of all top-level rules that are font-face rules (implementingCSSFontFaceRule
).- Returns:
- A copy of all contained
@font-face
rules. Nevernull
.
-
hasKeyframesRules
public boolean hasKeyframesRules()
Check if at least one of the top-level rules is a keyframes rule (implementingCSSKeyframesRule
).- Returns:
true
if at least one@keyframes
rule is contained,false
otherwise.
-
getKeyframesRuleCount
@Nonnegative public int getKeyframesRuleCount()
Get the number of top-level rules that are keyframes rules (implementingCSSKeyframesRule
).- Returns:
- The number of contained
@keyframes
rules. Always ≥ 0.
-
getKeyframesRuleAtIndex
@Nullable public CSSKeyframesRule getKeyframesRuleAtIndex(@Nonnegative int nIndex)
Get the@keyframes
rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getKeyframesRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllKeyframesRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSKeyframesRule> getAllKeyframesRules()
Get a list of all top-level rules that are keyframes rules (implementingCSSKeyframesRule
).- Returns:
- A copy of all contained
@keyframes
rules. Nevernull
.
-
hasViewportRules
public boolean hasViewportRules()
Check if at least one of the top-level rules is a viewport rule (implementingCSSViewportRule
).- Returns:
true
if at least one@viewport
rule is contained,false
otherwise.
-
getViewportRuleCount
@Nonnegative public int getViewportRuleCount()
Get the number of top-level rules that are viewport rules (implementingCSSViewportRule
).- Returns:
- The number of contained
@viewport
rules. Always ≥ 0.
-
getViewportRuleAtIndex
@Nullable public CSSViewportRule getViewportRuleAtIndex(@Nonnegative int nIndex)
Get the@viewport
rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getViewportRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllViewportRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSViewportRule> getAllViewportRules()
Get a list of all top-level rules that are viewport rules (implementingCSSViewportRule
).- Returns:
- A copy of all contained
@viewport
rules. Nevernull
.
-
hasSupportsRules
public boolean hasSupportsRules()
Check if at least one of the top-level rules is a supports rule (implementingCSSSupportsRule
).- Returns:
true
if at least one@supports
rule is contained,false
otherwise.
-
getSupportsRuleCount
@Nonnegative public int getSupportsRuleCount()
Get the number of top-level rules that are support rules (implementingCSSSupportsRule
).- Returns:
- The number of contained
@supports
rules. Always ≥ 0.
-
getSupportsRuleAtIndex
@Nullable public CSSSupportsRule getSupportsRuleAtIndex(@Nonnegative int nIndex)
Get the@supports
rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getSupportsRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllSupportsRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSSupportsRule> getAllSupportsRules()
Get a list of all top-level rules that are support rules (implementingCSSSupportsRule
).- Returns:
- A copy of all contained
@supports
rules. Nevernull
.
-
hasUnknownRules
public boolean hasUnknownRules()
Check if at least one of the top-level rules is an unknown rule (implementingCSSUnknownRule
).- Returns:
true
if at least one unknown@
rule is contained,false
otherwise.
-
getUnknownRuleCount
@Nonnegative public int getUnknownRuleCount()
Get the number of top-level rules that are unknown rules (implementingCSSUnknownRule
).- Returns:
- The number of contained unknown
@
rules. Always ≥ 0.
-
getUnknownRuleAtIndex
@Nullable public CSSUnknownRule getUnknownRuleAtIndex(@Nonnegative int nIndex)
Get the unknown rule at the specified index.- Parameters:
nIndex
- The index to be resolved. Should be ≥ 0 and <getUnknownRuleCount()
.- Returns:
null
if an invalid index was specified.- Since:
- 3.7.4
-
getAllUnknownRules
@Nonnull @ReturnsMutableCopy public com.helger.commons.collection.impl.ICommonsList<CSSUnknownRule> getAllUnknownRules()
Get a list of all top-level rules that are unknown rules (implementingCSSUnknownRule
).- Returns:
- A copy of all contained unknown
@
rules. Nevernull
.
-
-