]> git.basschouten.com Git - openhab-addons.git/blob
7bcdc76ece03e746d2cb573c69eb678059e4a4d4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.nobohub.internal.model;
14
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import javax.validation.constraints.NotNull;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23
24 /**
25  * Stores a mapping between week profile ids and week profiles that exists.
26  *
27  * @author Jørgen Austvik - Initial contribution
28  */
29 @NonNullByDefault
30 public final class WeekProfileRegister {
31
32     private @NotNull Map<Integer, WeekProfile> register = new HashMap<Integer, WeekProfile>();
33
34     /**
35      * Stores a new week profile in the register. If a week profile exists with the same id, that value is overwritten.
36      *
37      * @param profile The week profile to store.
38      */
39     public void put(WeekProfile profile) {
40         register.put(profile.getId(), profile);
41     }
42
43     /**
44      * Removes a WeekProfile from the registry.
45      *
46      * @param weekProfileId The week profile to remove
47      * @return The week profile that is removed. Null if the week profile is not found.
48      */
49     public @Nullable WeekProfile remove(int weekProfileId) {
50         return register.remove(weekProfileId);
51     }
52
53     /**
54      * Returns a WeekProfile from the registry.
55      *
56      * @param weekProfileId The id of the week profile to return.
57      * @return Returns the week profile, or null if it doesnt exist in the registry.
58      */
59     public @Nullable WeekProfile get(int weekProfileId) {
60         return register.get(weekProfileId);
61     }
62
63     /**
64      * Returns all WeekProfiles from the registry.
65      *
66      * @return Returns the week profile, or empty list if no profiles.
67      */
68     public Collection<WeekProfile> values() {
69         return register.values();
70     }
71
72     public boolean isEmpty() {
73         return register.isEmpty();
74     }
75 }