Package nl.crashdata.chartjs.colors
Class ChartJsRGBAColor
- java.lang.Object
-
- nl.crashdata.chartjs.colors.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 javascriptrgbaobject.- Author:
- haster
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ChartJsRGBAColorBLUEstatic ChartJsRGBAColorGREENstatic ChartJsRGBAColorGREYstatic ChartJsRGBAColorORANGEstatic ChartJsRGBAColorPURPLEstatic ChartJsRGBAColorREDstatic ChartJsRGBAColorYELLOW
-
Constructor Summary
Constructors Constructor Description ChartJsRGBAColor(int red, int green, int blue)Parameters should be in the range 0-255, inclusive.ChartJsRGBAColor(int red, int green, int blue, int alpha)Parameters should be in the range 0-255, inclusive.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static shortensureValidAlphaValue(int value)Used by the constructors to ensure the provided alpha values are valid.static shortensureValidColourValue(int value)Used by the constructors to ensure the provided color values are valid.booleanequals(Object obj)shortgetAlpha()shortgetBlue()shortgetGreen()shortgetRed()inthashCode()StringtoJsonString()StringtoString()ChartJsRGBAColorwithAlpha(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.ChartJsRGBAColorwithBlue(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.ChartJsRGBAColorwithGreen(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.ChartJsRGBAColorwithRed(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.
-
-
-
Field Detail
-
RED
public static final ChartJsRGBAColor RED
-
ORANGE
public static final ChartJsRGBAColor ORANGE
-
YELLOW
public static final ChartJsRGBAColor YELLOW
-
GREEN
public static final ChartJsRGBAColor GREEN
-
BLUE
public static final ChartJsRGBAColor BLUE
-
PURPLE
public static final ChartJsRGBAColor PURPLE
-
GREY
public static final ChartJsRGBAColor GREY
-
-
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
rgbaobject, for example"rgba(25, 125, 208, 0.35)"
-
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.
-
-