Java Long Number Create toLong(Object obj)

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

Description

to Long

License

Apache License

Declaration

public static Long toLong(Object obj) 

Method Source Code

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

public class Main {
    private static final Object NULL = null;

    public static Long toLong(Object obj) {
        if (isNull(obj)) {
            return getNull();
        }//from  w  ww  .  j a  va  2 s .  c o  m
        if (obj instanceof Long) {
            return (Long) obj;
        }
        if (obj instanceof Integer || obj instanceof Short || obj instanceof Byte) {
            return Long.parseLong(obj.toString());
        }
        String objStr = obj.toString();
        if (objStr.matches("[-+]?[0-9]+")) {
            return Long.parseLong(objStr);
        }
        return getNull();
    }

    public static boolean isNull(Object obj) {
        return obj == NULL;
    }

    @SuppressWarnings("unchecked")
    public static <T> T getNull() {
        return (T) NULL;
    }
}

Related

  1. toLong(Object obj)
  2. toLong(Object obj)
  3. toLong(Object obj)
  4. toLong(Object obj)
  5. toLong(Object obj)
  6. toLong(Object obj)
  7. toLong(Object obj, String pattern)
  8. toLong(Object object)
  9. toLong(Object object)