]> git.basschouten.com Git - openhab-addons.git/blob
33a2d63915b6b737ddef3e43ca092ac277f14562
[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 java.util.stream.Stream;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * The {@link Index} enum lists standard ranges of AQI indices
22  * along with their appreciation category.
23  *
24  * @author GaĆ«l L'hopital - Initial contribution
25  */
26 @NonNullByDefault
27 public enum Index {
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);
35
36     private double min;
37     private double max;
38     private Appreciation category;
39
40     Index(double min, double max, Appreciation category) {
41         this.min = min;
42         this.max = max;
43         this.category = category;
44     }
45
46     public double getMin() {
47         return min;
48     }
49
50     public double getSpan() {
51         return max - min;
52     }
53
54     boolean contains(double idx) {
55         return min <= idx && idx <= max;
56     }
57
58     public static @Nullable Index find(double idx) {
59         return Stream.of(Index.values()).filter(i -> i.contains(idx)).findFirst().orElse(null);
60     }
61
62     public Appreciation getCategory() {
63         return category;
64     }
65 }