View Javadoc
1   /*
2    * Copyright (C) 2018 Alberto Irurueta Carro (alberto@irurueta.com)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.irurueta.navigation.indoor;
17  
18  import java.io.Serializable;
19  
20  /**
21   * Data related to a WiFi access point.
22   */
23  public class WifiAccessPoint implements Serializable, RadioSource {
24  
25      /**
26       * Basic service set identifier of this access point in the form of a six-byte MAC address:
27       * xx:xx:xx:xx:xx:xx.
28       */
29      private String bssid;
30  
31      /**
32       * Frequency used by this Access Point (expressed in Hz).
33       */
34      private double frequency;
35  
36      /**
37       * Service set identifier (SSID) of this 802.11 network. This value is optional.
38       */
39      private String ssid;
40  
41      /**
42       * Constructor.
43       *
44       * @param bssid     basic service set identifier of this access point in the form of a six-byte MAC address:
45       *                  xx:xx:xx:xx:xx:xx.
46       * @param frequency frequency used by this Access Point (expressed in Hz).
47       * @throws IllegalArgumentException if BSSID is null or frequency is negative.
48       */
49      public WifiAccessPoint(final String bssid, final double frequency) {
50          if (bssid == null) {
51              throw new IllegalArgumentException();
52          }
53  
54          if (frequency < 0.0) {
55              throw new IllegalArgumentException();
56          }
57  
58          this.bssid = bssid;
59          this.frequency = frequency;
60      }
61  
62      /**
63       * Constructor.
64       *
65       * @param bssid     basic service set identifier of this access point in the form of a six-byte MAC address:
66       *                  xx:xx:xx:xx:xx:xx.
67       * @param frequency frequency used by this Access Point (expressed in Hz).
68       * @param ssid      service set identifier (SSID) of this 802.11 network.
69       * @throws IllegalArgumentException if BSSID is null or frequency is negative.
70       */
71      public WifiAccessPoint(final String bssid, final double frequency, final String ssid) {
72          this(bssid, frequency);
73          this.ssid = ssid;
74      }
75  
76      /**
77       * Empty constructor.
78       */
79      protected WifiAccessPoint() {
80      }
81  
82      /**
83       * Gets the basic service set identifier of this access point in the form of a six-byte MAC address:
84       * xx:xx:xx:xx:xx:xx.
85       *
86       * @return the basic service set identifier.
87       */
88      public String getBssid() {
89          return bssid;
90      }
91  
92      /**
93       * Gets frequency used by this Access Point (expressed in Hz).
94       *
95       * @return frequency used by this Access Point (expressed in Hz).
96       */
97      @Override
98      public double getFrequency() {
99          return frequency;
100     }
101 
102     /**
103      * Gets service set identifier (SSID) of this 802.11 network.
104      *
105      * @return service set identifier (SSID).
106      */
107     public String getSsid() {
108         return ssid;
109     }
110 
111     /**
112      * Indicates whether two access points are considered to be equal or not.
113      * Two access points are considered equal if they have the same BSSID.
114      *
115      * @param obj other object to be compared.
116      * @return true if both access points are considered to be equal, false otherwise.
117      */
118     @Override
119     public boolean equals(final Object obj) {
120         if (obj == null) {
121             return false;
122         }
123         if (obj == this) {
124             return true;
125         }
126 
127         if (!(obj instanceof WifiAccessPoint other)) {
128             return false;
129         }
130 
131         return bssid.equals(other.bssid);
132     }
133 
134     /**
135      * Returns hashcode associated to this access point.
136      *
137      * @return hashcode associated to this access point.
138      */
139     @Override
140     public int hashCode() {
141         return bssid.hashCode();
142     }
143 
144     /**
145      * Gets radio source type, which can be either a Wi-Fi Access point or a bluetooth Beacon.
146      *
147      * @return radio source type.
148      */
149     @Override
150     public RadioSourceType getType() {
151         return RadioSourceType.WIFI_ACCESS_POINT;
152     }
153 }