1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache license, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the license for the specific language governing permissions and 15 * limitations under the license. 16 */ 17 package org.apache.logging.log4j.core.helpers; 18 19 public class Strings { 20 21 /** 22 * <p>Checks if a CharSequence is empty ("") or null.</p> 23 * 24 * <pre> 25 * Strings.isEmpty(null) = true 26 * Strings.isEmpty("") = true 27 * Strings.isEmpty(" ") = false 28 * Strings.isEmpty("bob") = false 29 * Strings.isEmpty(" bob ") = false 30 * </pre> 31 * 32 * <p>NOTE: This method changed in Lang version 2.0. 33 * It no longer trims the CharSequence. 34 * That functionality is available in isBlank().</p> 35 * 36 * <p>Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isEmpty(CharSequence)</p> 37 * 38 * @param cs the CharSequence to check, may be null 39 * @return {@code true} if the CharSequence is empty or null 40 */ 41 public static boolean isEmpty(final CharSequence cs) { 42 return cs == null || cs.length() == 0; 43 } 44 45 /** 46 * <p>Checks if a CharSequence is not empty ("") and not null.</p> 47 * 48 * <pre> 49 * StringUtils.isNotEmpty(null) = false 50 * StringUtils.isNotEmpty("") = false 51 * StringUtils.isNotEmpty(" ") = true 52 * StringUtils.isNotEmpty("bob") = true 53 * StringUtils.isNotEmpty(" bob ") = true 54 * </pre> 55 * 56 * <p>Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isNotEmpty(CharSequence)</p> 57 * 58 * @param cs the CharSequence to check, may be null 59 * @return {@code true} if the CharSequence is not empty and not null 60 * @since 3.0 Changed signature from isNotEmpty(String) to isNotEmpty(CharSequence) 61 */ 62 public static boolean isNotEmpty(final CharSequence cs) { 63 return !isEmpty(cs); 64 } 65 66 }