]> git.basschouten.com Git - openhab-addons.git/blob
aa3fa00d427ad9c4e0fb2bce232ef64f4a3aa24f
[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.nanoleaf.internal.model;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Represents panel layout of the light panels
20  *
21  * @author Martin Raepple - Initial contribution
22  */
23 @NonNullByDefault
24 public class PanelLayout {
25
26     private @Nullable Layout layout;
27     private @Nullable GlobalOrientation globalOrientation;
28
29     public PanelLayout() {
30     }
31
32     public PanelLayout(GlobalOrientation globalOrientation, Layout layout) {
33         this.globalOrientation = globalOrientation;
34         this.layout = layout;
35     }
36
37     public @Nullable Layout getLayout() {
38         return layout;
39     }
40
41     public void setLayout(Layout layout) {
42         this.layout = layout;
43     }
44
45     public @Nullable GlobalOrientation getGlobalOrientation() {
46         return globalOrientation;
47     }
48
49     public void setGlobalOrientation(GlobalOrientation globalOrientation) {
50         this.globalOrientation = globalOrientation;
51     }
52
53     @Override
54     public boolean equals(@Nullable Object o) {
55         if (this == o) {
56             return true;
57         }
58
59         if (o == null || getClass() != o.getClass()) {
60             return false;
61         }
62
63         PanelLayout pl = (PanelLayout) o;
64
65         // For a panel layout to be equal to another panel layouit, all inner data structures must
66         // be equal, or they must be null both in this object or the object it is compared with.
67
68         GlobalOrientation go = globalOrientation;
69         GlobalOrientation otherGo = pl.getGlobalOrientation();
70         boolean goEquals = false;
71         if (go == null || otherGo == null) {
72             if (go == null && otherGo == null) {
73                 // If one of the global oriantations are null, the other must also be null
74                 // for them to be equal
75                 goEquals = true;
76             }
77         } else {
78             goEquals = go.equals(otherGo);
79         }
80
81         if (!goEquals) {
82             // No reason to compare layout if global oriantation is different
83             return false;
84         }
85
86         Layout l = layout;
87         Layout otherL = pl.getLayout();
88
89         if (l == null && otherL == null) {
90             return true;
91         }
92
93         if (l == null || otherL == null) {
94             return false;
95         }
96
97         return l.equals(otherL);
98     }
99
100     @Override
101     public int hashCode() {
102         final int prime = 31;
103         int result = 1;
104
105         GlobalOrientation go = globalOrientation;
106         if (go != null) {
107             result = prime * result + go.hashCode();
108         }
109
110         Layout l = layout;
111         if (l != null) {
112             result = prime * result + l.hashCode();
113         }
114
115         return result;
116     }
117 }