Java Object to Float objectToInt(Object obj)

Here you can find the source of objectToInt(Object obj)

Description

object To Int

License

Apache License

Declaration

public static int objectToInt(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static int objectToInt(Object obj) {
        return objectToInt(obj, 0);
    }// w w w. j  a  va  2s  . co  m

    public static int objectToInt(Object obj, int added) {
        if (obj instanceof Integer) {
            return (Integer) obj;
        } else if (obj instanceof Float) {
            return ((Float) obj).intValue();
        } else if (obj instanceof Double) {
            return ((Double) obj).intValue();
        }
        return stringToInt(objectToString(obj), added);
    }

    public static int stringToInt(String string) {
        return stringToInt(string, 0);
    }

    public static int stringToInt(String string, int added) {
        int result = 0;
        try {
            result = Integer.parseInt(string);
        } catch (Exception e) {
            result = added;
        }
        return result;
    }

    public static String objectToString(Object obj) {
        return objectToString(obj, null);
    }

    public static String objectToString(Object obj, String added) {
        String result = added;
        if (obj != null) {
            result = String.valueOf(obj);
        }
        return result;
    }
}

Related

  1. objectToFloat(Object obj)
  2. objectToInt(Object o)
  3. objectToInt(Object o)
  4. objectToInt(Object obj)
  5. objectToInt(Object Obj)
  6. objectToInt(Object p1)
  7. objectToInt(Object val)