convert.java

来自「j2me下的1套UI框架.包含j2me开发中会应用的各种低级组件」· Java 代码 · 共 62 行

JAVA
62
字号
package com.jmobilecore.support;

/**
 * This class contains convertions methods
 *
 * @author 	Greg Gridin
 */
public class Convert {

    /**
     * Converts object to the <code>String</code> value
     * @param  obj the object for convertion
     * @param  defValue the default value used if <code>obj</code> is null
     * @return the <code>String</code> representing <code>obj</code> parameter
     */
    static public String toString(Object obj, String defValue) {

        if (obj == null)
            return defValue;
        return (String) obj;
    }

    /**
     * Converts object to the <code>long</code> value
     * @param  obj the object for convertion
     * @param  defValue the default value used if <code>obj</code> is null
     * @return the <code>long</code> representing <code>obj</code> parameter
     */
    static public long toLong(Object obj, long defValue) {

        if (obj == null)
            return defValue;
        return ((Long)obj).longValue();
    }

    /**
     * Converts object to the <code>int</code> value
     * @param  obj the object for convertion
     * @param  defValue the default value used if <code>obj</code> is null
     * @return the <code>int</code> representing <code>obj</code> parameter
     */
    static public int toInteger(Object obj, int defValue) {

        if (obj == null)
            return defValue;
        return ((Integer)obj).intValue();
    }

    /**
     * Converts object to the <code>boolean</code> value
     * @param  obj the object for convertion
     * @param  defValue the default value used if <code>obj</code> is null
     * @return the <code>int</code> representing <code>obj</code> parameter
     */
    static public boolean toBoolean(Object obj, boolean defValue) {

        if (obj == null)
            return defValue;
        return ((Boolean)obj).booleanValue();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?