|
| 1 | +/* |
| 2 | + * Copyright (c) 2010-2025 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.core.model.yaml.internal.sitemaps; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | +import java.util.Objects; |
| 17 | + |
| 18 | +import org.eclipse.jdt.annotation.NonNull; |
| 19 | +import org.eclipse.jdt.annotation.Nullable; |
| 20 | +import org.openhab.core.model.yaml.YamlElement; |
| 21 | +import org.openhab.core.model.yaml.YamlElementName; |
| 22 | + |
| 23 | +/** |
| 24 | + * The {@link YamlRuleDTO} is a data transfer object used to serialize a sitemap widget rule in a YAML configuration |
| 25 | + * file. |
| 26 | + * |
| 27 | + * @author Mark Herwege - Initial contribution |
| 28 | + */ |
| 29 | +@YamlElementName("rule") |
| 30 | +public class YamlRuleDTO implements YamlElement, Cloneable { |
| 31 | + |
| 32 | + public String uid; |
| 33 | + public List<Condition> conditions; |
| 34 | + public String argument; |
| 35 | + |
| 36 | + public YamlRuleDTO() { |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public @NonNull String getId() { |
| 41 | + return uid == null ? "" : uid; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public void setId(@NonNull String id) { |
| 46 | + uid = id; |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public YamlElement cloneWithoutId() { |
| 51 | + YamlRuleDTO copy; |
| 52 | + try { |
| 53 | + copy = (YamlRuleDTO) super.clone(); |
| 54 | + copy.uid = null; |
| 55 | + return copy; |
| 56 | + } catch (CloneNotSupportedException e) { |
| 57 | + // Will never happen |
| 58 | + return new YamlRuleDTO(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public boolean isValid(@Nullable List<@NonNull String> errors, @Nullable List<@NonNull String> warnings) { |
| 64 | + return true; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public int hashCode() { |
| 69 | + return Objects.hash(uid, conditions); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public boolean equals(@Nullable Object obj) { |
| 74 | + if (this == obj) { |
| 75 | + return true; |
| 76 | + } else if (obj == null || getClass() != obj.getClass()) { |
| 77 | + return false; |
| 78 | + } |
| 79 | + YamlRuleDTO other = (YamlRuleDTO) obj; |
| 80 | + return Objects.equals(uid, other.uid) && Objects.equals(conditions, other.conditions); |
| 81 | + } |
| 82 | + |
| 83 | + public class Condition { |
| 84 | + public String item; |
| 85 | + public String condition; |
| 86 | + public String value; |
| 87 | + } |
| 88 | +} |
0 commit comments