]> git.basschouten.com Git - openhab-addons.git/blob
6bfe86e4773e84bf079006579e1ec5759d658d09
[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.ahawastecollection.internal;
14
15 import java.util.Collections;
16 import java.util.Date;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * Contains the next collection dates for a given waste type.
23  * 
24  * @author Sönke Küper - Initial contribution
25  */
26 @NonNullByDefault
27 final class CollectionDate {
28
29     /**
30      * Type of waste that is collected.
31      */
32     public enum WasteType {
33         /**
34          * General waste.
35          */
36         GENERAL_WASTE,
37         /**
38          * Bio waste.
39          */
40         BIO_WASTE,
41         /**
42          * Paper.
43          */
44         PAPER,
45         /**
46          * Light packaging.
47          */
48         LIGHT_PACKAGES;
49
50         /**
51          * Parses the {@link WasteType} from the given Value from the Web-page.
52          */
53         public static WasteType parseValue(String value) {
54             switch (value) {
55                 case "Restabfall":
56                     return GENERAL_WASTE;
57                 case "Bioabfall":
58                     return BIO_WASTE;
59                 case "Papier":
60                     return PAPER;
61                 case "Leichtverpackungen":
62                     return LIGHT_PACKAGES;
63                 default:
64                     throw new IllegalArgumentException("Unknown waste type: " + value);
65             }
66         }
67     }
68
69     private final WasteType type;
70     private final List<Date> dates;
71
72     /**
73      * Creates a new {@link CollectionDate}.
74      */
75     public CollectionDate(final WasteType type, final List<Date> dates) {
76         this.type = type;
77         this.dates = dates;
78         Collections.sort(this.dates);
79     }
80
81     /**
82      * Returns the (non empty list) of next collection dates, for the given {@link WasteType}, ordered ascending.
83      */
84     public List<Date> getDates() {
85         return this.dates;
86     }
87
88     /**
89      * Returns the {@link WasteType} that is collected at the given times.
90      */
91     public WasteType getType() {
92         return this.type;
93     }
94
95     @Override
96     public String toString() {
97         return String.format("waste type: %s, collection dates: %s", this.type, this.dates);
98     }
99 }