]> git.basschouten.com Git - openhab-addons.git/blob
ad6b0148f26924976707017af2f47b3cb90a7758
[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.echonetlite.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * @author Michael Barker - Initial contribution
19  */
20 @NonNullByDefault
21 public class LangUtil {
22     public static byte b(int i) {
23         return (byte) (i & 0xFF);
24     }
25
26     public static String constantToVariable(CharSequence constant) {
27         final StringBuilder sb = new StringBuilder();
28         boolean shouldCapitalise = false;
29         for (int i = 0, n = constant.length(); i < n; i++) {
30             final char c = constant.charAt(i);
31             if ('_' == c) {
32                 shouldCapitalise = true;
33             } else if (shouldCapitalise) {
34                 sb.append(Character.toUpperCase(c));
35                 shouldCapitalise = false;
36             } else {
37                 sb.append(Character.toLowerCase(c));
38             }
39         }
40         return sb.toString();
41     }
42 }