Example usage for java.lang Long longValue

List of usage examples for java.lang Long longValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public long longValue() 

Source Link

Document

Returns the value of this Long as a long value.

Usage

From source file:Main.java

public static List<String> getSortedGPXFilenamesByDate(File dir, boolean absolutePath) {
    final Map<String, Long> mp = new HashMap<String, Long>();
    readGpxDirectory(dir, mp, "", absolutePath);
    ArrayList<String> list = new ArrayList<String>(mp.keySet());
    Collections.sort(list, new Comparator<String>() {
        @Override//from  w  w w . jav  a  2  s  .c o m
        public int compare(String object1, String object2) {
            Long l1 = mp.get(object1);
            Long l2 = mp.get(object2);
            long lhs = l1 == null ? 0 : l1.longValue();
            long rhs = l2 == null ? 0 : l2.longValue();
            return lhs < rhs ? 1 : (lhs == rhs ? 0 : -1);
        }
    });
    return list;
}

From source file:Main.java

public static long[] toLongArray(List<Long> list, long defaultValue) {
    if (isEmpty(list)) {
        return new long[0];
    }//from   ww  w .  ja  va 2 s  .  co  m
    long[] array = new long[list.size()];
    for (int I = 0; I < list.size(); I++) {
        Long v = list.get(I);
        if (v == null) {
            array[I] = defaultValue;
        } else {
            array[I] = v.longValue();
        }
    }
    return array;
}

From source file:Main.java

/**
 * Converts to primitive array.//w ww .  j a  v a  2  s.  c  o  m
 */
public static long[] values(Long[] array) {
    long[] dest = new long[array.length];
    for (int i = 0; i < array.length; i++) {
        Long v = array[i];
        if (v != null) {
            dest[i] = v.longValue();
        }
    }
    return dest;
}

From source file:Main.java

public static long[] toPrimitive(final Long[] array, final long valueForNull) {
    if (array == null) {
        return null;
    } else if (array.length == 0) {
        return EMPTY_LONG_ARRAY;
    }//from   w w w  .j  av a2 s.com
    final long[] result = new long[array.length];
    for (int i = 0; i < array.length; i++) {
        final Long b = array[i];
        result[i] = (b == null ? valueForNull : b.longValue());
    }
    return result;
}

From source file:Main.java

public static boolean isBrithdayAvable(Long d) {
    if (d == null) {
        return false;
    }/* w ww . j  a va  2 s . c o  m*/
    boolean back = false;
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(d.longValue());
    Calendar current = Calendar.getInstance();
    if (c.get(Calendar.YEAR) > 1801 && c.before(current)
            && c.get(Calendar.YEAR) <= current.get(Calendar.YEAR)) {
        return true;
    }
    return back;
}

From source file:gov.nih.nci.ncicb.cadsr.common.util.SessionUtils.java

private static void clearStaleObject() {
    synchronized (sessionObjectCacheTimeout) {
        log.error("SessionUtil.clearStaleObject start :" + TimeUtils.getEasternTime());
        Set keys = sessionObjectCacheTimeout.keySet();
        Collection copyKeys = new ArrayList();
        keys.addAll(copyKeys); // done to avoid java.util.ConcurrentModificationException
        if (keys != null) {
            Iterator it = copyKeys.iterator();
            while (it.hasNext()) {
                String key = (String) it.next();
                Long storedTime = (Long) sessionObjectCacheTimeout.get(key);
                if (new Long(new Date().getTime()).longValue() > storedTime.longValue() + CACHE_TIMEOUT_VALUE) {
                    sessionObjectCache.remove(key);
                    sessionObjectCacheTimeout.remove(key);
                }//from   w w  w. j  a v a2 s.c o  m
            }
        }
        log.error("SessionUtil.clearStaleObject( start :" + TimeUtils.getEasternTime());
    }
}

From source file:AIR.Common.Configuration.AppSettingsHelper.java

private static long getInt64(String key, Long defaultValue) {
    String rawValue = get(key);//w  ww . j av a 2s .com

    if (!StringUtils.isEmpty(rawValue)) {
        long value = Long.parseLong(rawValue);
        return value;

    }

    return defaultValue != null ? defaultValue.longValue() : 0;
}

From source file:com.aimdek.ccm.util.CommonUtil.java

/**
 * Checks if is null.//from  w  w w . j  a v  a  2  s .  c om
 *
 * @param l
 *            the l
 * @return true, if is null
 */
public static boolean isNull(Long l) {
    if ((l == null) || (l.longValue() == 0)) {
        return true;
    } else {
        return false;
    }
}

From source file:de.pribluda.android.jsonmarshaller.JSONMarshaller.java

/**
 * recursively marshall to JSON/*from   ww w. j av a2s.c o  m*/
 *
 * @param sink
 * @param object
 */
static void marshallRecursive(JSONObject sink, Object object)
        throws JSONException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
    // nothing to marshall
    if (object == null)
        return;
    // primitive object is a field and does not interes us here
    if (object.getClass().isPrimitive())
        return;
    // object not null,  and is not primitive - iterate through getters
    for (Method method : object.getClass().getMethods()) {
        // our getters are parameterless and start with "get"
        if ((method.getName().startsWith(GETTER_PREFIX) && method.getName().length() > BEGIN_INDEX
                || method.getName().startsWith(IS_PREFIX) && method.getName().length() > IS_LENGTH)
                && (method.getModifiers() & Modifier.PUBLIC) != 0 && method.getParameterTypes().length == 0
                && method.getReturnType() != void.class) {
            // is return value primitive?
            Class<?> type = method.getReturnType();
            if (type.isPrimitive() || String.class.equals(type)) {
                // it is, marshall it
                Object val = method.invoke(object);
                if (val != null) {
                    sink.put(propertize(method.getName()), val);
                }
                continue;
            } else if (type.isArray()) {
                Object val = marshallArray(method.invoke(object));
                if (val != null) {
                    sink.put(propertize(method.getName()), val);
                }
                continue;
            } else if (type.isAssignableFrom(Date.class)) {
                Date date = (Date) method.invoke(object);
                if (date != null) {
                    sink.put(propertize(method.getName()), date.getTime());
                }
                continue;
            } else if (type.isAssignableFrom(Boolean.class)) {
                Boolean b = (Boolean) method.invoke(object);
                if (b != null) {
                    sink.put(propertize(method.getName()), b.booleanValue());
                }
                continue;
            } else if (type.isAssignableFrom(Integer.class)) {
                Integer i = (Integer) method.invoke(object);
                if (i != null) {
                    sink.put(propertize(method.getName()), i.intValue());
                }
                continue;
            } else if (type.isAssignableFrom(Long.class)) {
                Long l = (Long) method.invoke(object);
                if (l != null) {
                    sink.put(propertize(method.getName()), l.longValue());
                }
                continue;
            } else {
                // does it have default constructor?
                try {
                    if (method.getReturnType().getConstructor() != null) {
                        Object val = marshall(method.invoke(object));
                        if (val != null) {
                            sink.put(propertize(method.getName()), val);
                        }
                        continue;
                    }
                } catch (NoSuchMethodException ex) {
                    // just ignore it here, it means no such constructor was found
                }
            }
        }
    }
}

From source file:com.redhat.rhn.domain.common.CommonFactory.java

/**
 * Lookup a FileList from the DB.//  w w  w  .j  av a 2 s  . c o  m
 * @param idIn to lookup
 * @param org to lookup in
 * @return FileList if found.
 */
public static FileList lookupFileList(Long idIn, Org org) {
    Session session = null;
    //look for Kickstart data by id
    session = HibernateFactory.getSession();
    return (FileList) session.getNamedQuery("FileList.findByIdAndOrg").setLong("id", idIn.longValue())
            .setLong("org_id", org.getId().longValue()).uniqueResult();
}