]> git.basschouten.com Git - openhab-addons.git/blob
afb279f521d28c8044aa2c0766b00728b2991fe4
[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.digitalstrom.internal.lib.structure.devices.deviceparameters.impl;
14
15 /**
16  * The {@link DSID} represents the digitalSTROM-Device identifier.
17  *
18  * @author Alexander Betker - Initial contribution
19  * @author Alexander Friese - simplified constructor
20  */
21 public class DSID {
22
23     private final String dsid;
24     private static final String DEFAULT_DSID = "3504175fe000000000000001";
25     private static final String PRE = "3504175fe0000000";
26     private static final String ALL = "ALL";
27
28     /**
29      * Creates a new {@link DSID}.
30      *
31      * @param dsid to create
32      */
33     public DSID(String dsid) {
34         var trimmedDsid = dsid != null ? dsid.trim() : "";
35         if (trimmedDsid.length() == 24) {
36             this.dsid = trimmedDsid;
37         } else if (trimmedDsid.length() == 8) {
38             this.dsid = PRE + trimmedDsid;
39         } else if (trimmedDsid.toUpperCase().equals(ALL)) {
40             this.dsid = ALL;
41         } else {
42             this.dsid = DEFAULT_DSID;
43         }
44     }
45
46     /**
47      * Returns the dSID as {@link String}.
48      *
49      * @return dSID
50      */
51     public String getValue() {
52         return dsid;
53     }
54
55     @Override
56     public boolean equals(Object obj) {
57         if (obj instanceof DSID) {
58             return ((DSID) obj).getValue().equals(this.getValue());
59         }
60         return false;
61     }
62
63     @Override
64     public int hashCode() {
65         return dsid.hashCode();
66     }
67
68     @Override
69     public String toString() {
70         return dsid;
71     }
72 }