2 * Copyright (c) 2010-2020 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
13 package org.openhab.binding.homematic.internal.misc;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Global utility class with helper methods.
21 * @author Gerhard Riegler - Initial contribution
23 public class MiscUtils {
24 private static final Logger logger = LoggerFactory.getLogger(MiscUtils.class);
27 * Replaces invalid characters of the text to fit into a openHAB UID.
29 public static String validateCharacters(String text, String textType, String replaceChar) {
33 String cleanedText = text.replaceAll("[^A-Za-z0-9_-]", replaceChar);
34 if (!text.equals(cleanedText)) {
35 logger.info("{} '{}' contains invalid characters, new {} '{}'", textType, text, textType, cleanedText);
41 * Returns true, if the value is not null and true.
43 public static boolean isTrueValue(Object value) {
44 return value != null && value == Boolean.TRUE;
48 * Returns true, if the value is not null and false.
50 public static boolean isFalseValue(Object value) {
51 return value != null && value == Boolean.FALSE;