Class ChartJsRGBAColor

  • All Implemented Interfaces:
    Serializable

    public final class ChartJsRGBAColor
    extends Object
    implements Serializable
    An immutable value object to represent colors for chartjs. Gets serialised to a javascript rgba object.
    Author:
    haster
    See Also:
    Serialized Form
    • Constructor Detail

      • ChartJsRGBAColor

        public ChartJsRGBAColor​(int red,
                                int green,
                                int blue)
        Parameters should be in the range 0-255, inclusive. The resulting object will have an alpha value of 100%
      • ChartJsRGBAColor

        public ChartJsRGBAColor​(int red,
                                int green,
                                int blue,
                                int alpha)
        Parameters should be in the range 0-255, inclusive. Alpha should be in the range 0-100, inclusive.
    • Method Detail

      • getRed

        public short getRed()
      • getGreen

        public short getGreen()
      • getBlue

        public short getBlue()
      • getAlpha

        public short getAlpha()
      • withRed

        public ChartJsRGBAColor withRed​(int red)
        Creates a new ChartJsRGBAColor object with the given value for its red component and the values for the other colors from the current object.
        Parameters:
        red - A value between 0 and 255, inclusive.
      • withGreen

        public ChartJsRGBAColor withGreen​(int green)
        Creates a new ChartJsRGBAColor object with the given value for its green component and the values for the other colors from the current object.
        Parameters:
        green - A value between 0 and 255, inclusive.
      • withBlue

        public ChartJsRGBAColor withBlue​(int blue)
        Creates a new ChartJsRGBAColor object with the given value for its blue component and the values for the other colors from the current object.
        Parameters:
        blue - A value between 0 and 255, inclusive.
      • withAlpha

        public ChartJsRGBAColor withAlpha​(int alpha)
        Creates a new ChartJsRGBAColor object with the given value for its alpha component and the values for the other colors from the current object.
        Parameters:
        alpha - A value between 0 and 100, inclusive.
      • toJsonString

        public String toJsonString()
        Returns:
        this object as javascript rgba object, for example "rgba(25, 125, 208, 0.35)"
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • ensureValidColourValue

        public static short ensureValidColourValue​(int value)
        Used by the constructors to ensure the provided color values are valid.
        Throws:
        IllegalArgumentException - if the given value is outside the [0-255] range.
      • ensureValidAlphaValue

        public static short ensureValidAlphaValue​(int value)
        Used by the constructors to ensure the provided alpha values are valid.
        Throws:
        IllegalArgumentException - if the given value is outside the [0-100] range.