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

com.microsoft.sqlserver.jdbc.StringUtils Maven / Gradle / Ivy

There is a newer version: 12.8.1.jre11
Show newest version
/*
 * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
 * available under the terms of the MIT License. See the LICENSE file in the project root for more information.
 */

package com.microsoft.sqlserver.jdbc;

/**
 * Provides a utility class for Strings.
 * 
 * @since 6.1.2
 */
public class StringUtils {

    /**
     * string containing a space
     */
    public static final String SPACE = " ";

    /**
     * empty string
     */
    public static final String EMPTY = "";

    /**
     * Developer should not create {@code StringUtils} instance in standard programming. Instead, the class should be
     * used as {@code StringUtils.isEmpty("String")}
     */
    private StringUtils() {
        // Hiding constructor.
    }

    /**
     * Returns if String is null
     * 
     * @param charSequence
     *        {@link CharSequence} Can provide null
     * @return {@link Boolean} if provided char sequence is null or empty / blank
     * @since 6.1.2
     */
    public static boolean isEmpty(final CharSequence charSequence) {
        return charSequence == null || charSequence.length() == 0;
    }

    /**
     * Returns if String is numeric or not.
     * 
     * @param str
     *        {@link String}
     * @return {@link Boolean} if provided String is numeric or not.
     */
    public static boolean isNumeric(final String str) {
        return !isEmpty(str) && str.matches("\\d+(\\.\\d+)?");
    }

    /**
     * Returns if string is integer or not
     * 
     * @param str
     *        {@link String}
     * @return {@link Boolean} if provided String is Integer or not.
     */
    public static boolean isInteger(final String str) {
        try {
            Integer.parseInt(str);
            return true;
        } catch (NumberFormatException e) {
            // Nothing. this is not integer.
        }
        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy