Package com.helger.css.decl
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CSSMediaQuery.EModifier
A global modifier that can be used in front of a single CSS media query.
-
Constructor Summary
Constructors Constructor Description CSSMediaQuery(CSSMediaQuery.EModifier eModifier, String sMedium)
ConstructorCSSMediaQuery(String sMedium)
Constructor without a modifier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CSSMediaQuery
addMediaExpression(int nIndex, CSSMediaExpression aMediaExpression)
Add a media expression to the list at the specified index.CSSMediaQuery
addMediaExpression(CSSMediaExpression aMediaExpression)
Append a media expression to the list.boolean
equals(Object o)
com.helger.commons.collection.impl.ICommonsList<CSSMediaExpression>
getAllMediaExpressions()
String
getAsCSSString(ICSSWriterSettings aSettings, int nIndentLevel)
Get the contents of this object as a serialized CSS string for writing to an output.CSSMediaExpression
getMediaExpression(int nExpressionIndex)
Get the media expression at the specified index.int
getMediaExpressionCount()
String
getMedium()
CSSMediaQuery.EModifier
getModifier()
CSSSourceLocation
getSourceLocation()
int
hashCode()
boolean
hasMediaExpressions()
boolean
isNot()
boolean
isOnly()
com.helger.commons.state.EChange
removeAllMediaExpressions()
Remove all media expressions.com.helger.commons.state.EChange
removeMediaExpression(int nExpressionIndex)
Remove the media expression at the specified index.com.helger.commons.state.EChange
removeMediaExpression(CSSMediaExpression aMediaExpression)
Remove the specified media expression.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
-
-
-
-
Constructor Detail
-
CSSMediaQuery
public CSSMediaQuery(@Nullable String sMedium)
Constructor without a modifier. This implicitly uses the modifierCSSMediaQuery.EModifier.NONE
.- Parameters:
sMedium
- The medium to use. May benull
.
-
CSSMediaQuery
public CSSMediaQuery(@Nonnull CSSMediaQuery.EModifier eModifier, @Nullable String sMedium)
Constructor- Parameters:
eModifier
- The modifier to use. May not benull
.sMedium
- The medium to use. May benull
.
-
-
Method Detail
-
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 isCSSMediaQuery.EModifier.NOT
.- See Also:
getModifier()
-
isOnly
public final boolean isOnly()
- Returns:
true
if the modifier isCSSMediaQuery.EModifier.ONLY
.- See Also:
getModifier()
-
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 benull
.- 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 benull
.- 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 benull
.- 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. Nevernull
.- 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 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
.
-
-