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

com.github.nosan.embedded.cassandra.util.StringUtils Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
/*
 * Copyright 2018-2018 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.nosan.embedded.cassandra.util;

import javax.annotation.Nullable;

/**
 * Utility methods for dealing with strings.
 *
 * @author Dmytro Nosan
 * @since 1.0.0
 */
public abstract class StringUtils {


	/**
	 * Check whether the given {@code String} is empty.
	 *
	 * @param source the candidate String
	 * @return {@code true} if the {@code String} is {@code null} or has no length
	 */
	public static boolean isEmpty(@Nullable CharSequence source) {
		return !hasLength(source);
	}

	/**
	 * Check that the given {@code String} is neither {@code null} nor of length 0.
	 *
	 * @param source the {@code String} to check
	 * @return {@code true} if the {@code String} is not {@code null} and has length
	 */
	public static boolean hasLength(@Nullable CharSequence source) {
		return (source != null && source.length() > 0);
	}

	/**
	 * Check whether the given {@code String} contains actual text.
	 *
	 * @param source the {@code String} to check (may be {@code null})
	 * @return {@code true} if the {@code String} is not {@code null}, its
	 * length is greater than 0, and it does not contain whitespace only
	 */
	public static boolean hasText(@Nullable CharSequence source) {
		if (source == null) {
			return false;
		}
		for (int i = 0; i < source.length(); i++) {
			if (!Character.isWhitespace(source.charAt(i))) {
				return true;
			}
		}
		return false;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy