All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.plantumldependency.common.utils.string.StringUtils Maven / Gradle / Ivy

/*
 StringUtils.java
 Creation date : 04/05/2010
 Copyright © Benjamin Croizet ([email protected])

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 or GNU Lesser General Public License as published by the
 Free Software Foundation; either version 3 of the License,
 or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received copies of the GNU General Public License
 and GNU Lesser General Public License along with this program;
 if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 http://www.fsf.org/licensing/licenses/gpl.html
 http://www.gnu.org/licenses/lgpl.html
 */

package net.sourceforge.plantumldependency.common.utils.string;

import java.util.Set;
import java.util.TreeSet;

/**
 * The class utilities simplifying some {@link String} tasks.
 *
 * @author Benjamin Croizet (true if the {@link String} is empty, false otherwise.
     * @since 1.3.0
     */
    public static boolean isEmpty(final String str) {
        return str == null || str.trim().length() == 0;
    }

    /**
     * Checks if a String is not empty ("") and not null.
     *
     * @param str
     *            the string to check.
     * @return true if the {@link String} isn't empty, false otherwise.
     * @since 1.3.0
     */
    public static boolean isNotEmpty(final String str) {
        return str != null && str.trim().length() != 0;
    }

    /**
     * Replaces all strings of the set in the original string by a unique replacement string.
     * Note : this method is case sensitive
     *
     * @param str
     *            the original string where to replace strings, mustn't be null.
     * @param setOfStringsToReplace
     *            the {@link Set} of string to be replaced, mustn't be null.
     * @param replacementString
     *            the replacement string, mustn't be null.
     * @return the new string after replacements.
     * @since 1.3.0
     */
    public static String replaceASetOfString(final String str, final Set < String > setOfStringsToReplace,
            final String replacementString) {
        String result = str;

        for (final String stringToReplace : setOfStringsToReplace) {
            result = result.replaceAll(stringToReplace, replacementString);
        }

        return result;
    }

    /**
     * Private constructor to prevent from instantiation.
     *
     * @since 1.3.0
     */
    private StringUtils() {
        super();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy