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
14 package org.openhab.binding.ecovacs.internal.util;
16 import java.util.HashMap;
17 import java.util.Optional;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
22 * @author Danny Baumann - Initial contribution
25 public class StateOptionMapping<T extends Enum<T>> extends HashMap<T, StateOptionEntry<T>> {
26 private static final long serialVersionUID = -6828690091106259902L;
28 public String getMappedValue(T key) {
29 StateOptionEntry<T> entry = get(key);
33 throw new IllegalArgumentException("No mapping for key " + key);
36 public Optional<T> findMappedEnumValue(String value) {
37 return entrySet().stream().filter(entry -> entry.getValue().value.equals(value)).map(entry -> entry.getKey())
42 public static <T extends Enum<T>> StateOptionMapping<T> of(StateOptionEntry<T>... entries) {
43 StateOptionMapping<T> map = new StateOptionMapping<>();
44 for (StateOptionEntry<T> entry : entries) {
45 map.put(entry.enumValue, entry);