]> git.basschouten.com Git - openhab-addons.git/blob
9b909c51bc4d39faf6831622bd4bf2eefb8e9fc9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hue.internal.dto.clip2;
14
15 import java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.hue.internal.exceptions.DTOPresentButEmptyException;
20 import org.openhab.core.util.ColorUtil.Gamut;
21
22 /**
23  * DTO for colour X/Y of a light.
24  *
25  * @author Andrew Fiddian-Green - Initial contribution
26  */
27 @NonNullByDefault
28 public class ColorXy {
29     private @Nullable PairXy xy;
30     private @Nullable Gamut2 gamut;
31
32     public @Nullable Gamut getGamut() {
33         Gamut2 gamut = this.gamut;
34         return Objects.nonNull(gamut) ? gamut.getGamut() : null;
35     }
36
37     public @Nullable Gamut2 getGamut2() {
38         return this.gamut;
39     }
40
41     /**
42      * @throws DTOPresentButEmptyException to indicate that the DTO is present but empty.
43      */
44     public double[] getXY() throws DTOPresentButEmptyException {
45         PairXy pairXy = this.xy;
46         if (Objects.nonNull(pairXy)) {
47             return pairXy.getXY();
48         }
49         throw new DTOPresentButEmptyException("'color' DTO is present but empty");
50     }
51
52     public ColorXy setGamut(@Nullable Gamut gamut) {
53         this.gamut = Objects.nonNull(gamut) ? new Gamut2().setGamut(gamut) : null;
54         return this;
55     }
56
57     public ColorXy setXY(double[] xyValues) {
58         PairXy pairXy = this.xy;
59         pairXy = Objects.nonNull(pairXy) ? pairXy : new PairXy();
60         pairXy.setXY(xyValues);
61         this.xy = pairXy;
62         return this;
63     }
64 }