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 com.irurueta.algebra.Matrix;
19  import com.irurueta.geometry.Point;
20  
21  /**
22   * Data related to a Wi-Fi access point whose location is known.
23   *
24   * @param <P> a {@link Point} type.
25   */
26  public abstract class WifiAccessPointLocated<P extends Point<?>> extends WifiAccessPoint implements
27          RadioSourceLocated<P> {
28  
29      /**
30       * Position where access point is located.
31       */
32      private P position;
33  
34      /**
35       * Covariance of inhomogeneous coordinates of current position (if available).
36       */
37      private Matrix positionCovariance;
38  
39      /**
40       * Constructor.
41       *
42       * @param bssid     basic service set identifier of this access point in the form of a six-byte MAC address:
43       *                  xx:xx:xx:xx:xx:xx.
44       * @param frequency frequency used by this Access Point (expressed in Hz).
45       * @param position  position where access point is located.
46       * @throws IllegalArgumentException if either BSSID or position are null or
47       *                                  frequency is negative.
48       */
49      protected WifiAccessPointLocated(final String bssid, final double frequency, final P position) {
50          super(bssid, frequency);
51  
52          if (position == null) {
53              throw new IllegalArgumentException();
54          }
55  
56          this.position = position;
57      }
58  
59      /**
60       * Constructor.
61       *
62       * @param bssid     basic service set identifier of this access point in the form of a six-byte MAC address:
63       *                  xx:xx:xx:xx:xx:xx.
64       * @param frequency frequency used by this Access Point (expressed in Hz).
65       * @param ssid      service set identifier (SSID) of this 802.11 network.
66       * @param position  position where access point is located.
67       * @throws IllegalArgumentException if either BSSID or position are null or
68       *                                  frequency is negative.
69       */
70      protected WifiAccessPointLocated(
71              final String bssid, final double frequency, final String ssid, final P position) {
72          super(bssid, frequency, ssid);
73  
74          if (position == null) {
75              throw new IllegalArgumentException();
76          }
77  
78          this.position = position;
79      }
80  
81      /**
82       * Constructor.
83       *
84       * @param bssid              basic service set identifier of this access point in the form of a six-byte MAC address:
85       *                           xx:xx:xx:xx:xx:xx.
86       * @param frequency          frequency used by this Access Point (expressed in Hz).
87       * @param position           position where access point is located.
88       * @param positionCovariance covariance of inhomogeneous coordinates of current
89       *                           position (if available).
90       * @throws IllegalArgumentException if either BSSID or position are null or
91       *                                  frequency is negative, or covariance does not have proper size.
92       */
93      protected WifiAccessPointLocated(
94              final String bssid, final double frequency, final P position, final Matrix positionCovariance) {
95          this(bssid, frequency, position);
96  
97          if (positionCovariance != null) {
98              final var dims = position.getDimensions();
99              if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
100                 throw new IllegalArgumentException();
101             }
102         }
103         this.positionCovariance = positionCovariance;
104     }
105 
106     /**
107      * Constructor.
108      *
109      * @param bssid              basic service set identifier of this access point in the form of a six-byte MAC address:
110      *                           xx:xx:xx:xx:xx:xx.
111      * @param frequency          frequency used by this Access Point (expressed in Hz).
112      * @param ssid               service set identifier (SSID) of this 802.11 network.
113      * @param position           position where access point is located.
114      * @param positionCovariance covariance of inhomogeneous coordinates of current
115      *                           position (if available).
116      * @throws IllegalArgumentException if either BSSID or position are null or
117      *                                  frequency is negative, or covariance does not have proper size.
118      */
119     protected WifiAccessPointLocated(
120             final String bssid, final double frequency, final String ssid, final P position,
121             final Matrix positionCovariance) {
122         this(bssid, frequency, ssid, position);
123 
124         if (positionCovariance != null) {
125             final var dims = position.getDimensions();
126             if (positionCovariance.getRows() != dims || positionCovariance.getColumns() != dims) {
127                 throw new IllegalArgumentException();
128             }
129         }
130         this.positionCovariance = positionCovariance;
131     }
132 
133     /**
134      * Empty constructor.
135      */
136     protected WifiAccessPointLocated() {
137         super();
138     }
139 
140     /**
141      * Gets position where access point is located.
142      *
143      * @return position where access point is located.
144      */
145     public P getPosition() {
146         return position;
147     }
148 
149     /**
150      * Gets covariance of inhomogeneous coordinates of current position (if available).
151      *
152      * @return covariance of position or null.
153      */
154     public Matrix getPositionCovariance() {
155         return positionCovariance;
156     }
157 }