]> git.basschouten.com Git - openhab-addons.git/blob
a9b835dce4704a1549147b735af337a30a2b0c16
[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.fmiweather.internal.client;
14
15 import java.math.BigDecimal;
16 import java.util.Objects;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Station location
23  *
24  * Note: For simplicity, location implements object equality and hashCode using only id.
25  *
26  * @author Sami Salonen - Initial contribution
27  *
28  */
29 @NonNullByDefault
30 public class Location {
31
32     public final String name;
33     public final String id;
34     public final BigDecimal latitude;
35     public final BigDecimal longitude;
36
37     /**
38      *
39      * @param name name for the location
40      * @param id string identifying this location uniquely. Typically FMISID or latitude-longitude pair
41      * @param latitude latitude of the location
42      * @param longitude longitude of the location
43      */
44     public Location(String name, String id, BigDecimal latitude, BigDecimal longitude) {
45         this.name = name;
46         this.id = id;
47         this.latitude = latitude;
48         this.longitude = longitude;
49     }
50
51     @Override
52     public boolean equals(@Nullable Object obj) {
53         if (obj == null) {
54             return false;
55         }
56         if (!(obj instanceof Location)) {
57             return false;
58         }
59         Location other = (Location) obj;
60         return Objects.equals(id, other.id);
61     }
62
63     @Override
64     public int hashCode() {
65         return id.hashCode();
66     }
67
68     @Override
69     public String toString() {
70         return new StringBuilder("Location(name=\"").append(name).append("\", id=\"").append(id).append("\", latitude=")
71                 .append(latitude).append(", longitude=").append(longitude).append(")").toString();
72     }
73 }