2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.hue.internal.dto.clip2;
15 import java.util.Objects;
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;
23 * DTO for colour X/Y of a light.
25 * @author Andrew Fiddian-Green - Initial contribution
28 public class ColorXy {
29 private @Nullable PairXy xy;
30 private @Nullable Gamut2 gamut;
32 public @Nullable Gamut getGamut() {
33 Gamut2 gamut = this.gamut;
34 return Objects.nonNull(gamut) ? gamut.getGamut() : null;
37 public @Nullable Gamut2 getGamut2() {
42 * @throws DTOPresentButEmptyException to indicate that the DTO is present but empty.
44 public double[] getXY() throws DTOPresentButEmptyException {
45 PairXy pairXy = this.xy;
46 if (Objects.nonNull(pairXy)) {
47 return pairXy.getXY();
49 throw new DTOPresentButEmptyException("'color' DTO is present but empty");
52 public ColorXy setGamut(@Nullable Gamut gamut) {
53 this.gamut = Objects.nonNull(gamut) ? new Gamut2().setGamut(gamut) : null;
57 public ColorXy setXY(double[] xyValues) {
58 PairXy pairXy = this.xy;
59 pairXy = Objects.nonNull(pairXy) ? pairXy : new PairXy();
60 pairXy.setXY(xyValues);