Example usage for java.lang Long valueOf

List of usage examples for java.lang Long valueOf

Introduction

In this page you can find the example usage for java.lang Long valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Long valueOf(long l) 

Source Link

Document

Returns a Long instance representing the specified long value.

Usage

From source file:Main.java

public static String getFormatTime(String format, String time) {
    if (TextUtils.isEmpty(format) || TextUtils.isEmpty(time))
        return null;

    return getFormatTime(format, Long.valueOf(time));
}

From source file:Main.java

public static boolean isDue(byte[] data) {

    String[] strs = getDateInfoFromDate(data);
    if (strs != null && strs.length == 2) {
        String saveTimeStr = strs[0];
        while (saveTimeStr.startsWith("0")) {
            saveTimeStr = saveTimeStr.substring(1, saveTimeStr.length());
        }//from w  ww. ja  va  2  s .  com
        long saveTime = Long.valueOf(saveTimeStr);
        long deleteAfter = Long.valueOf(strs[1]);
        if (System.currentTimeMillis() > saveTime + deleteAfter * 1000) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static ArrayList<long[]> getRanking(Activity activity, String mode2) {
    ArrayList<long[]> rankList = new ArrayList<long[]>();

    String rankRecord = getStoredVar(activity, "ranking_" + mode2);
    if (rankRecord.equals("") == false) {
        String[] records = rankRecord.split(",");
        for (int i = 0; i < records.length; i += 2) {
            long[] l = { Long.valueOf(records[i]), Long.valueOf(records[i + 1]), 0 };
            rankList.add(l);/*from w  w  w .ja  v  a2  s . co m*/
        }
    }

    return rankList;
}

From source file:Main.java

public static long combinedTwoNumber(long a, long b) {
    return Long.valueOf(String.valueOf(a) + String.valueOf(b));
}

From source file:com.bryan.crud.helper.TypesUtil.java

public static Long getDefaultLong(Object objValue) {
    if (objValue instanceof Long) {
        return (Long) objValue;
    }/*w ww .jav a2s . c  o m*/
    try {
        if (objValue != null && StringUtils.isNotBlank(objValue.toString())
                && !objValue.toString().equals("null")) {
            return Long.valueOf(objValue.toString());
        }
    } catch (Exception e) {
        return null;
    }
    return null;
}

From source file:Main.java

/**
 * <p>Extract long values from an array of strings into an array of int.</p>
 *
 * <p>Exceptions in the format of the string are trapped and 0 value(s) returned.</p>
 *
 * @param   src   an array of strings, each of which should be an long numeric value
 * @return      an array of long/*w w  w  . j a v a 2s  .com*/
 */
static public long[] copyStringToLongArray(String[] src) {
    if (src == null)
        return null;
    int n = src.length;
    long[] dst = new long[n];
    for (int j = 0; j < n; ++j) {
        long value = 0;
        try {
            value = Long.valueOf(src[j]).longValue();
        } catch (NumberFormatException e) {
        } catch (NullPointerException e) {
        }
        dst[j] = value;
    }
    return dst;
}

From source file:Main.java

private static Object[] toArrayByString(String str) {
    List<Object> result = new ArrayList<Object>();
    str = str.substring(1, str.length() - 1);
    String type = str.substring(0, str.indexOf("@"));
    String[] values = str.substring(str.indexOf("@") + 1).split(",");
    for (int i = 0; i < values.length; i++) {
        String value = unesc(values[i]);
        if (LONG.equals(type)) {
            result.add(Long.valueOf(value));
        } else if (INTEGER.equals(type)) {
            result.add(Integer.valueOf(value));
        } else {/*from  w w w . ja  v a 2s. com*/
            result.add(value);
        }
    }
    return result.toArray();
}

From source file:Main.java

public static Long stringToLong(String str) {
    if (str == null) {
        return null;
    } else {//from ww  w . j  a v a2s.  c o  m
        try {
            return Long.parseLong(str);
        } catch (NumberFormatException e) {
            try {
                Double d = Double.valueOf(str);
                if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) {
                    Log.w(TAG, "Value " + d + " too large for long");
                    return null;
                }
                return Long.valueOf(d.longValue());
            } catch (NumberFormatException nfe2) {
                Log.w(TAG,
                        "Unable to interpret value " + str + " in field being "
                                + "converted to long, caught NumberFormatException <" + nfe2.getMessage()
                                + "> field discarded");
                return null;
            }
        }
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T parse(Class<T> type, String stringValue) throws IllegalArgumentException {
    if (type.equals(String.class)) {
        return (T) stringValue;
    }// ww  w  .  ja  v a 2  s . co  m

    if (type.equals(Boolean.class) || type.equals(boolean.class)) {
        return (T) Boolean.valueOf(stringValue);
    }
    try {
        if (type.equals(Integer.class) || type.equals(int.class)) {
            return (T) Integer.valueOf(stringValue);
        }
        if (type.equals(Long.class) || type.equals(long.class)) {
            return (T) Long.valueOf(stringValue);
        }
        if (type.equals(Short.class) || type.equals(short.class)) {
            return (T) Short.valueOf(stringValue);
        }
        if (type.equals(Byte.class) || type.equals(byte.class)) {
            return (T) Byte.valueOf(stringValue);
        }
        if (type.equals(Double.class) || type.equals(double.class)) {
            return (T) Double.valueOf(stringValue);
        }
        if (type.equals(Float.class) || type.equals(float.class)) {
            return (T) Float.valueOf(stringValue);
        }
        if (type.equals(File.class)) {
            return (T) new File(stringValue);
        }
    } catch (final NumberFormatException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    if (type.isEnum()) {
        @SuppressWarnings("rawtypes")
        final Class enumType = type;
        return (T) Enum.valueOf(enumType, stringValue);
    }
    throw new IllegalArgumentException("Can't handle type " + type);

}

From source file:Main.java

public static Object getObject(String type, String value) throws Exception {

    type = type.toLowerCase();/*from  w  w  w.ja  v a 2  s .c o m*/
    if ("boolean".equals(type))
        return Boolean.valueOf(value);
    if ("byte".equals(type))
        return Byte.valueOf(value);
    if ("short".equals(type))
        return Short.valueOf(value);
    if ("char".equals(type))
        if (value.length() != 1)
            throw new NumberFormatException("Argument is not a character!");
        else
            return Character.valueOf(value.toCharArray()[0]);
    if ("int".equals(type))
        return Integer.valueOf(value);
    if ("long".equals(type))
        return Long.valueOf(value);
    if ("float".equals(type))
        return Float.valueOf(value);
    if ("double".equals(type))
        return Double.valueOf(value);
    if ("string".equals(type))
        return value;
    else {
        Object objs[] = new String[] { value };
        return Class.forName(type).getConstructor(new Class[] { java.lang.String.class }).newInstance(objs);
    }
}