]> git.basschouten.com Git - openhab-addons.git/blob
066163286832501c50d47a033cd4b4fc399c23fe
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.satel.internal.util;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17
18 /**
19  * Replacement class for Apache's StringUtils.
20  *
21  * @author Krzysztof Goworek - Initial contribution
22  *
23  */
24 @NonNullByDefault
25 public class StringUtils {
26
27     /**
28      * Checks if a string is empty or null.
29      *
30      * @param str the string to check
31      * @return <code>true</code> if given string is empty or null
32      */
33     public static boolean isEmpty(@Nullable String str) {
34         return str == null || str.isEmpty();
35     }
36
37     /**
38      * Checks if a string is not empty and not null.
39      *
40      * @param str the string to check
41      * @return <code>true</code> if given string is not empty and not null
42      */
43     public static boolean isNotEmpty(@Nullable String str) {
44         return !isEmpty(str);
45     }
46
47     /**
48      * Checks if a string is null or empty or all characters are whitespace.
49      *
50      * @param str the string to check
51      * @return <code>true</code> if given string is blank
52      */
53     public static boolean isBlank(@Nullable String str) {
54         return str == null || str.isBlank();
55     }
56
57     /**
58      * Checks if a string is not null, not empty and contains at least one non-whitespace character.
59      *
60      * @param str the string to check
61      * @return <code>true</code> if given string is not blank
62      */
63     public static boolean isNotBlank(@Nullable String str) {
64         return !isBlank(str);
65     }
66 }