2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.airquality.internal.api;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
18 * The {@link ConcentrationRange} is responsible to store the range of
19 * a given physical measure associated with the corresponding AQI
22 * @author Gaƫl L'hopital - Initial contribution
25 public class ConcentrationRange {
26 private final double min;
27 private final double span;
28 private final Index index;
30 ConcentrationRange(double min, double max, Index index) {
32 this.span = max - min;
37 * Computes the concentration corresponding to the index
38 * if contained in the range
40 * @return : a physical concentration or -1 if not in range
42 double getConcentration(double idx) {
43 return index.contains(idx) ? span / index.getSpan() * (idx - index.getMin()) + min : -1;