001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.helpers;
018
019public class Strings {
020
021    /**
022     * <p>Checks if a CharSequence is empty ("") or null.</p>
023     *
024     * <pre>
025     * Strings.isEmpty(null)      = true
026     * Strings.isEmpty("")        = true
027     * Strings.isEmpty(" ")       = false
028     * Strings.isEmpty("bob")     = false
029     * Strings.isEmpty("  bob  ") = false
030     * </pre>
031     *
032     * <p>NOTE: This method changed in Lang version 2.0.
033     * It no longer trims the CharSequence.
034     * That functionality is available in isBlank().</p>
035     *
036     * <p>Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isEmpty(CharSequence)</p>
037     *
038     * @param cs  the CharSequence to check, may be null
039     * @return {@code true} if the CharSequence is empty or null
040     */
041    public static boolean isEmpty(final CharSequence cs) {
042        return cs == null || cs.length() == 0;
043    }
044
045    /**
046     * <p>Checks if a CharSequence is not empty ("") and not null.</p>
047     *
048     * <pre>
049     * StringUtils.isNotEmpty(null)      = false
050     * StringUtils.isNotEmpty("")        = false
051     * StringUtils.isNotEmpty(" ")       = true
052     * StringUtils.isNotEmpty("bob")     = true
053     * StringUtils.isNotEmpty("  bob  ") = true
054     * </pre>
055     *
056     * <p>Copied from Apache Commons Lang org.apache.commons.lang3.StringUtils.isNotEmpty(CharSequence)</p>
057     *
058     * @param cs  the CharSequence to check, may be null
059     * @return {@code true} if the CharSequence is not empty and not null
060     * @since 3.0 Changed signature from isNotEmpty(String) to isNotEmpty(CharSequence)
061     */
062    public static boolean isNotEmpty(final CharSequence cs) {
063        return !isEmpty(cs);
064    }
065
066}