Here you can find the source of toNullIfEmptyOrWhitespace(String string)
Parameter | Description |
---|---|
string | the string to test and possibly return |
public static String toNullIfEmptyOrWhitespace(String string)
/*/*w ww .j a v a 2 s. c om*/ * Copyright (C) 2000 Google Inc. * * 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. */ import static com.android.mail.lib.base.Preconditions.checkArgument; import com.google.common.base.Joiner; import com.google.common.base.Joiner.MapJoiner; import java.io.IOException; import java.io.InputStream; import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ /** * Returns the given string if it is nonempty and contains at least one * non-whitespace character; {@code null} otherwise. See comment in {@link * #isEmptyOrWhitespace} on the definition of whitespace. * * @param string the string to test and possibly return * @return {@code null} if {@code string} is null, empty, or contains only * whitespace characters; {@code string} itself otherwise */ public static String toNullIfEmptyOrWhitespace(String string) { return isEmptyOrWhitespace(string) ? null : string; } /** * Returns {@code true} if the given string is null, empty, or comprises only * whitespace characters, as defined by {@link CharMatcher#WHITESPACE}. * * <p><b>Warning:</b> there are many competing definitions of "whitespace"; * please see <a href="http://go/white+space">this spreadsheet</a> for * details. * * @param string the string reference to check * @return {@code true} if {@code string} is null, empty, or consists of * whitespace characters only */ public static boolean isEmptyOrWhitespace(String string) { return string == null || CharMatcher.WHITESPACE.matchesAllOf(string); } }