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 java.util.stream.Stream;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
21 * The {@link Index} enum lists standard ranges of AQI indices
22 * along with their appreciation category.
24 * @author Gaƫl L'hopital - Initial contribution
28 ZERO(0, 50, Appreciation.GOOD),
29 FIFTY(51, 100, Appreciation.MODERATE),
30 ONE_HUNDRED(101, 150, Appreciation.UNHEALTHY_FSG),
31 ONE_HUNDRED_FIFTY(151, 200, Appreciation.UNHEALTHY),
32 TWO_HUNDRED(201, 300, Appreciation.VERY_UNHEALTHY),
33 THREE_HUNDRED(301, 400, Appreciation.HAZARDOUS),
34 FOUR_HUNDRED(401, 500, Appreciation.HAZARDOUS);
38 private Appreciation category;
40 Index(double min, double max, Appreciation category) {
43 this.category = category;
46 public double getMin() {
50 public double getSpan() {
54 boolean contains(double idx) {
55 return min <= idx && idx <= max;
58 public static @Nullable Index find(double idx) {
59 return Stream.of(Index.values()).filter(i -> i.contains(idx)).findFirst().orElse(null);
62 public Appreciation getCategory() {