Java Null Value Convert null2void(String str)

Here you can find the source of null2void(String str)

Description

nullvoid

License

Apache License

Parameter

Parameter Description
str a parameter

Declaration

public static String null2void(String str) 

Method Source Code

//package com.java2s;
/*/*from  www  .ja v a2 s .  c  o m*/
 * Copyright 2008-2009 MOPAS(Ministry of Public Administration and Security).
 *
 * 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.
 */

public class Main {
    /**
     * @param str
     * @return
     */
    public static String null2void(String str) {

        if (isNull(str)) {
            str = "";
        }

        return str;
    }

    /**
     * @param str
     * @return
     */
    public static boolean isNull(String str) {

        if (str != null) {
            str = str.trim();
        }

        return (str == null || "".equals(str));
    }

    /**
     * @param str
     * @return
     */
    public static String trim(String str) {
        return str.trim();
    }

    /**
     * If original String has a specific String, remove
     * specific Strings from original String.
     * 
     * <pre>
     * StringUtil.trim('pass*word', '*') = 'password'
     * </pre>
     * @param origString
     *        original String
     * @param trimString
     *        String to be trimmed
     * @return converting result
     */
    public static String trim(String origString, String trimString) {
        int startPosit = origString.indexOf(trimString);
        if (startPosit != -1) {
            int endPosit = trimString.length() + startPosit;
            return origString.substring(0, startPosit)
                    + origString.substring(endPosit);
        }
        return origString;
    }

    /**
     * @param source
     * @param target
     * @return
     */
    public static boolean equals(String source, String target) {

        return null2void(source).equals(null2void(target));

    }
}

Related

  1. null2Str(Object obj)
  2. null2Str(String str)
  3. null2String(Object obj)
  4. null2String(String str)
  5. null2String(String string)