001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.imaging.color;
018
019public final class ColorCmy {
020
021    /**
022     * A constant for color cyan. Color components are:
023     * <pre>
024     *     cyan:    100
025     *     magenta: 0
026     *     yellow:  0
027     * </pre>
028     */
029    public static final ColorCmy CYAN = new ColorCmy(100, 0, 0);
030
031    /**
032     * A constant for color magenta. Color components are:
033     * <pre>
034     *     cyan:    0
035     *     magenta: 100
036     *     yellow:  0
037     * </pre>
038     */
039    public static final ColorCmy MAGENTA = new ColorCmy(0, 100, 0);
040
041    /**
042     * A constant for color yellow. Color components are:
043     * <pre>
044     *     cyan:    0
045     *     magenta: 0
046     *     yellow:  100
047     * </pre>
048     */
049    public static final ColorCmy YELLOW = new ColorCmy(0, 0, 100);
050
051    /**
052     * A constant for color black. Color components are:
053     * <pre>
054     *     cyan:    100
055     *     magenta: 100
056     *     yellow:  100
057     * </pre>
058     */
059    public static final ColorCmy BLACK = new ColorCmy(100, 100, 100);
060
061    /**
062     * A constant for color white. Color components are:
063     * <pre>
064     *     cyan:    0
065     *     magenta: 0
066     *     yellow:  0
067     * </pre>
068     */
069    public static final ColorCmy WHITE = new ColorCmy(0, 0, 0);
070
071    /**
072     * A constant for color red. Color components are:
073     * <pre>
074     *     cyan:    0
075     *     magenta: 100
076     *     yellow:  100
077     * </pre>
078     */
079    public static final ColorCmy RED = new ColorCmy(0, 100, 100);
080
081    /**
082     * A constant for color green. Color components are:
083     * <pre>
084     *     cyan:    100
085     *     magenta: 0
086     *     yellow:  100
087     * </pre>
088     */
089    public static final ColorCmy GREEN = new ColorCmy(100, 0, 100);
090
091    /**
092     * A constant for color blue. Color components are:
093     * <pre>
094     *     cyan:    100
095     *     magenta: 100
096     *     yellow:  0
097     * </pre>
098     */
099    public static final ColorCmy BLUE = new ColorCmy(100, 100, 0);
100
101    public final double C;
102    public final double M;
103    public final double Y;
104
105    public ColorCmy(final double C, final double M, final double Y) {
106        this.C = C;
107        this.M = M;
108        this.Y = Y;
109    }
110
111    @Override
112    public String toString() {
113        return "{C: " + C + ", M: " + M + ", Y: " + Y + "}";
114    }
115
116    @Override
117    public boolean equals(final Object o) {
118        if (this == o) {
119            return true;
120        }
121        if (o == null || getClass() != o.getClass()) {
122            return false;
123        }
124
125        final ColorCmy colorCmy = (ColorCmy) o;
126        if (Double.compare(colorCmy.C, C) != 0) {
127            return false;
128        }
129        if (Double.compare(colorCmy.M, M) != 0) {
130            return false;
131        }
132        if (Double.compare(colorCmy.Y, Y) != 0) {
133            return false;
134        }
135
136        return true;
137    }
138
139    @Override
140    public int hashCode() {
141        int result;
142        long temp;
143        temp = Double.doubleToLongBits(C);
144        result = (int) (temp ^ (temp >>> 32));
145        temp = Double.doubleToLongBits(M);
146        result = 31 * result + (int) (temp ^ (temp >>> 32));
147        temp = Double.doubleToLongBits(Y);
148        result = 31 * result + (int) (temp ^ (temp >>> 32));
149        return result;
150    }
151}