]> git.basschouten.com Git - openhab-addons.git/blob
5a24ce4a7353a5655fd11e2428ed37aee4cac15a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.HashMap;
16 import java.util.Map;
17
18 import javax.validation.constraints.NotNull;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22
23 /**
24  * Stores a mapping between override ids and overrides that are in place.
25  *
26  * @author Jørgen Austvik - Initial contribution
27  * @author Espen Fossen - Initial contribution
28  */
29 @NonNullByDefault
30 public final class OverrideRegister {
31
32     private final @NotNull Map<Integer, OverridePlan> register = new HashMap<>();
33
34     /**
35      * Stores a new Override in the register. If an override exists with the same id, that value is overwritten.
36      *
37      * @param overridePlan The Override to store.
38      */
39     public void put(OverridePlan overridePlan) {
40         register.put(overridePlan.getId(), overridePlan);
41     }
42
43     /**
44      * Removes an override from the registry.
45      *
46      * @param overrideId The override to remove
47      * @return The override that is removed. Null if the override is not found.
48      */
49     public @Nullable OverridePlan remove(int overrideId) {
50         return register.remove(overrideId);
51     }
52
53     /**
54      * Returns an Override from the registry.
55      *
56      * @param overrideId The id of the override to return.
57      * @return Returns the override, or null if it doesnt exist in the regestry.
58      */
59     public @Nullable OverridePlan get(int overrideId) {
60         return register.get(overrideId);
61     }
62 }