Class CSSValue

  • All Implemented Interfaces:
    ICSSWriteable, ICSSValue

    @NotThreadSafe
    public class CSSValue
    extends Object
    implements ICSSValue
    Represents the combination of a single CSS property (ICSSProperty) and it's according value plus the important state (!important or not). The main purpose of this class to make building a CSS from scratch simpler. When an existing CSS is read the information resides in a CSSDeclaration because it contains the declaration value in a more structured form.
    Instances of this class are mutable since 3.7.3.
    Author:
    Philip Helger
    • Field Detail

      • DEFAULT_CONSISTENCY_CHECKS_ENABLED

        public static final boolean DEFAULT_CONSISTENCY_CHECKS_ENABLED
        See Also:
        Constant Field Values
    • Constructor Detail

      • CSSValue

        public CSSValue​(@Nonnull
                        ICSSProperty aProperty,
                        @Nonnull
                        String sValue,
                        boolean bIsImportant)
        Constructor
        Parameters:
        aProperty - The CSS property. May not be null.
        sValue - The String value to use. May be null. The value may NOT contain the !important flag! The value is internally trimmed to avoid leading and trailing.
        bIsImportant - true if the value should be important, false otherwise
    • Method Detail

      • areConsistencyChecksEnabled

        public static boolean areConsistencyChecksEnabled()
        Returns:
        true if consistency checks are enabled (by default), false if not.
        Since:
        5.0.2
      • setConsistencyChecksEnabled

        public static void setConsistencyChecksEnabled​(boolean bEnabled)
        Enable or disable consistency checks. By default the consistency checks are enabled (for backwards compatibility) but if performance is a real matter, you may want to disable them globally.
        Parameters:
        bEnabled - true to enable them, false to disable them.
        Since:
        5.0.2
      • getProperty

        @Nonnull
        public ICSSProperty getProperty()
        Returns:
        The CSS property used. Never null.
      • getPropertyName

        @Nonnull
        @Nonempty
        public String getPropertyName()
        Returns:
        The property name including an eventually contained vendor prefix. Neither null nor empty.
        Since:
        3.9.0
      • setProperty

        @Nonnull
        public CSSValue setProperty​(@Nonnull
                                    ICSSProperty aProperty)
        Set the property of this CSS value (e.g. background-color).
        Parameters:
        aProperty - The CSS property to set. May not be null.
        Returns:
        this
        Since:
        3.7.3
      • getValue

        @Nonnull
        public String getValue()
        Returns:
        The CSS value used. May not be null but maybe empty.
      • setValue

        @Nonnull
        public CSSValue setValue​(@Nonnull
                                 String sValue)
        Set the value of this CSS value (e.g. red in case the property is background-color).
        Parameters:
        sValue - The value to be set. May not be null. The value may NOT contain the !important flag! The value is internally trimmed to avoid leading and trailing.
        Returns:
        this
        Since:
        3.7.3
      • isImportant

        public boolean isImportant()
        Returns:
        true if it is important, false if not
      • setImportant

        @Nonnull
        public CSSValue setImportant​(boolean bIsImportant)
        Set the important flag of this value.
        Parameters:
        bIsImportant - true to mark it important, false to remove it.
        Returns:
        this
        Since:
        3.7.3
      • 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 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object