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 * Contains a reading related to a given Wi-Fi access point.
22 *
23 * @param <S> a {@link RadioSource} type.
24 */
25 public abstract class Reading<S extends RadioSource> implements Serializable {
26
27 /**
28 * Radio source associated to this reading.
29 */
30 private S source;
31
32 /**
33 * Constructor.
34 *
35 * @param source radio source associated to this reading.
36 * @throws IllegalArgumentException if radios source data is null.
37 */
38 protected Reading(final S source) {
39 if (source == null) {
40 throw new IllegalArgumentException();
41 }
42 this.source = source;
43 }
44
45 /**
46 * Empty constructor.
47 */
48 protected Reading() {
49 }
50
51 /**
52 * Gets radio source associated to this reading.
53 *
54 * @return radio source associated to this reading.
55 */
56 public S getSource() {
57 return source;
58 }
59
60 /**
61 * Determine whether another reading is made for the same radio source as
62 * this reading or not.
63 *
64 * @param otherReading other reading to be compared.
65 * @return true if both readings are associated to the same access point,
66 * false otherwise.
67 */
68 public boolean hasSameSource(final Reading<S> otherReading) {
69 return otherReading != null && otherReading.source.equals(source);
70 }
71
72 /**
73 * Contains radio source reading type.
74 *
75 * @return reading type.
76 */
77 public abstract ReadingType getType();
78 }