]> git.basschouten.com Git - openhab-addons.git/blob
58ff6df297e29c7ad75c117f4599400d74e38b70
[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.airquality.internal.api;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link ConcentrationRange} is responsible to store the range of
19  * a given physical measure associated with the corresponding AQI
20  * index.
21  *
22  * @author GaĆ«l L'hopital - Initial contribution
23  */
24 @NonNullByDefault
25 public class ConcentrationRange {
26     private final double min;
27     private final double span;
28     private final Index index;
29
30     ConcentrationRange(double min, double max, Index index) {
31         this.min = min;
32         this.span = max - min;
33         this.index = index;
34     }
35
36     /*
37      * Computes the concentration corresponding to the index
38      * if contained in the range
39      *
40      * @return : a physical concentration or -1 if not in range
41      */
42     double getConcentration(double idx) {
43         return index.contains(idx) ? span / index.getSpan() * (idx - index.getMin()) + min : -1;
44     }
45 }