Java tutorial
/* * Copyright (c) 2013, FPX and/or its affiliates. All rights reserved. Use, Copy is subject to authorized license. */ package info.donsun.core.utils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.math.NumberUtils; /** * ??? * * @author Steven Deng * @version 1.0 * @since 1.0 * @date 2013-7-13 */ public final class Values { /** * */ private Values() { } /** * ?? * * @param obj * @param defaultValue * @return */ public static String getString(Object obj, String defaultValue) { return ObjectUtils.toString(obj, defaultValue); } /** * ?? * * @param obj * @return */ public static String getString(Object obj) { return getString(obj, ""); } /** * ?? * * @param obj * @param defaultValue ,null * @return */ public static boolean getBoolean(Object obj, boolean defaultValue) { Boolean bool = BooleanUtils.toBooleanObject(getString(obj)); return bool != null ? bool.booleanValue() : defaultValue; } /** * ?? * * @param obj * @return */ public static boolean getBoolean(Object obj) { return getBoolean(obj, false); } /** * ?? * * @param obj * @param defaultValue null * @return */ public static int getInt(Object key, int defaultValue) { return NumberUtils.toInt(getString(key), defaultValue); } /** * ?? * * @param obj * @return */ public static int getInt(Object obj) { return getInt(obj, 0); } /** * ?? * * @param obj * @param defaultValue null * @return */ public static long getLong(Object obj, long defaultValue) { return NumberUtils.toLong(getString(obj), defaultValue); } /** * ?? * * @param obj * @return */ public static long getLong(Object obj) { return getLong(obj, 0L); } /** * ???? * * @param obj * @param defaultValue null * @return ?? */ public static double getDouble(Object obj, double defaultValue) { return NumberUtils.toDouble(getString(obj), defaultValue); } /** * ???? * * @param obj * @return ?? */ public static double getDouble(Object obj) { return getDouble(obj, 0d); } /** * ??? * * @param obj * @param defaultValue null * @return ?? */ public static float getFloat(Object obj, float defaultValue) { return NumberUtils.toFloat(getString(obj), defaultValue); } /** * ??? * * @param obj * @return ?? */ public static float getFloat(Object obj) { return getFloat(obj, 0f); } }