Java Object to Long castToLong(Object value)

Here you can find the source of castToLong(Object value)

Description

cast To Long

License

Apache License

Declaration

public static final Long castToLong(Object value) 

Method Source Code

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

public class Main {
    public static final Long castToLong(Object value) {
        if (value == null) {
            return null;
        }/*w  w  w . j a  v a2  s .  c om*/

        if (value instanceof Number) {
            return ((Number) value).longValue();
        }

        if (value instanceof String) {
            String strVal = (String) value;
            if (strVal.length() == 0) {
                return null;
            }

            if ("null".equals(strVal) || "NULL".equals(strVal)) {
                return null;
            }

            return Long.parseLong(strVal);
        }
        throw new NumberFormatException("can not cast to long, value : " + value);
    }
}

Related

  1. castLong(Object val)
  2. castLong2Int(long x)
  3. castLongtoUInt(long x)
  4. castToLong(final String uid)
  5. castToLong(Object object)
  6. castToLong(Object value)
  7. castToLongArray(Object[] array)
  8. objectToLong(Object obj)
  9. objectToPostiveLong(Object object)