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 ColorXyz {
020
021    /**
022     * A constant for color black. Color components are:
023     * <pre>
024     *     X: 0
025     *     Y: 0
026     *     Z: 0
027     * </pre>
028     */
029    public static final ColorXyz BLACK = new ColorXyz(0, 0, 0);
030
031    /**
032     * A constant for color white. Color components are:
033     * <pre>
034     *     X:  95.05
035     *     Y: 100.00
036     *     Z: 108.90
037     * </pre>
038     */
039    public static final ColorXyz WHITE = new ColorXyz(95.05, 100, 108.9);
040
041    /**
042     * A constant for color red. Color components are:
043     * <pre>
044     *     X: 41.24
045     *     Y: 21.26
046     *     Z:  1.93
047     * </pre>
048     */
049    public static final ColorXyz RED = new ColorXyz(41.24, 21.26, 1.93);
050
051    /**
052     * A constant for color green. Color components are:
053     * <pre>
054     *     X: 35.76
055     *     Y: 71.52
056     *     Z: 11.92
057     * </pre>
058     */
059    public static final ColorXyz GREEN = new ColorXyz(35.76, 71.52, 11.92);
060
061    /**
062     * A constant for color blue. Color components are:
063     * <pre>
064     *     X: 18.05
065     *     Y:  7.22
066     *     Z: 95.05
067     * </pre>
068     */
069    public static final ColorXyz BLUE = new ColorXyz(18.05, 7.22, 95.05);
070
071    public final double X;
072    public final double Y;
073    public final double Z;
074
075    public ColorXyz(final double X, final double Y, final double Z) {
076        this.X = X;
077        this.Y = Y;
078        this.Z = Z;
079    }
080
081    @Override
082    public String toString() {
083        return "{X: " + X + ", Y: " + Y + ", Z: " + Z + "}";
084    }
085
086    @Override
087    public boolean equals(final Object o) {
088        if (this == o) {
089            return true;
090        }
091        if (o == null || getClass() != o.getClass()) {
092            return false;
093        }
094
095        final ColorXyz colorXyz = (ColorXyz) o;
096        if (Double.compare(colorXyz.X, X) != 0) {
097            return false;
098        }
099        if (Double.compare(colorXyz.Y, Y) != 0) {
100            return false;
101        }
102        if (Double.compare(colorXyz.Z, Z) != 0) {
103            return false;
104        }
105
106        return true;
107    }
108
109    @Override
110    public int hashCode() {
111        int result;
112        long temp;
113        temp = Double.doubleToLongBits(X);
114        result = (int) (temp ^ (temp >>> 32));
115        temp = Double.doubleToLongBits(Y);
116        result = 31 * result + (int) (temp ^ (temp >>> 32));
117        temp = Double.doubleToLongBits(Z);
118        result = 31 * result + (int) (temp ^ (temp >>> 32));
119        return result;
120    }
121}