]> git.basschouten.com Git - openhab-addons.git/blob
f4fbbf505ccad92e65f2ab7ad2c3d6f4c1dcfedc
[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.linuxinput.internal.evdev4j;
14
15 import java.util.Optional;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 import jnr.constants.Constant;
20
21 /**
22  * @author Thomas Weißschuh - Initial contribution
23  */
24 @NonNullByDefault
25 public class Utils {
26     private Utils() {
27     }
28
29     @SafeVarargs
30     static <T extends Constant> int combineFlags(Class<T> klazz, T... flags) {
31         if (klazz == Constant.class) {
32             throw new IllegalArgumentException();
33         }
34         int result = 0;
35         for (Constant c : flags) {
36             result |= c.intValue();
37         }
38         return result;
39     }
40
41     public static <T extends Constant> Optional<T> constantFromInt(T[] cs, int i) {
42         for (T c : cs) {
43             if (c.intValue() == i) {
44                 return Optional.of(c);
45             }
46         }
47         return Optional.empty();
48     }
49 }