[WIP] CFV Refactor
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / provisional / tmf / core / views / timegraph2 / ColorDefinition.java
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.internal.provisional.tmf.core.views.timegraph2;
11
12 import java.util.Objects;
13
14 import org.eclipse.jdt.annotation.Nullable;
15
16 public class ColorDefinition {
17
18 public static final int MIN = 0;
19 public static final int MAX = 255;
20
21 public final int fRed;
22 public final int fGreen;
23 public final int fBlue;
24 public final int fAlpha;
25
26 public ColorDefinition(int red, int green, int blue) {
27 this(red, green, blue, MAX);
28 }
29
30 public ColorDefinition(int red, int green, int blue, int alpha) {
31 checkValue(red);
32 checkValue(green);
33 checkValue(blue);
34 checkValue(alpha);
35
36 fRed = red;
37 fGreen = green;
38 fBlue = blue;
39 fAlpha = alpha;
40 }
41
42 private static void checkValue(int value) throws IllegalArgumentException {
43 if (value < MIN || value > MAX) {
44 throw new IllegalArgumentException();
45 }
46 }
47
48 @Override
49 public int hashCode() {
50 return Objects.hash(fRed, fGreen, fBlue, fAlpha);
51 }
52
53 @Override
54 public boolean equals(@Nullable Object obj) {
55 if (this == obj) {
56 return true;
57 }
58 if (obj == null) {
59 return false;
60 }
61 if (getClass() != obj.getClass()) {
62 return false;
63 }
64 ColorDefinition other = (ColorDefinition) obj;
65 if (fAlpha != other.fAlpha ||
66 fBlue != other.fBlue ||
67 fGreen != other.fGreen ||
68 fRed != other.fRed) {
69 return false;
70 }
71 return true;
72 }
73
74
75 }
This page took 0.032621 seconds and 5 git commands to generate.