Example usage for java.lang Long parseLong

List of usage examples for java.lang Long parseLong

Introduction

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

Prototype

public static long parseLong(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal long .

Usage

From source file:org.instagram4j.entity.Caption.java

@JsonIgnore
public Date getCreatedTimeAsDate() {
    if (createdTime == null)
        return null;
    return new Date(Long.parseLong(createdTime) * 1000);
}

From source file:org.shredzone.cilla.web.converter.StringToHeader.java

@Override
public Header convert(String string) {
    try {//  w  w w. ja  v a2  s.  c o m
        return headerDao.fetch(Long.parseLong(string));
    } catch (NumberFormatException ex) {
        return headerDao.fetchByName(string);
    }
}

From source file:org.shredzone.cilla.web.converter.StringToPicture.java

@Override
public Picture convert(String string) {
    try {/*from   w ww  .  ja va  2 s .  c  o  m*/
        return pictureDao.fetch(Long.parseLong(string));
    } catch (NumberFormatException ex) {
        return null;
    }
}

From source file:ar.com.zauber.commons.web.utils.impl.IdSEOIdStrategy.java

/** @see SEOIdStrategy#getIdFromSEOFriendly(String) */
public final Serializable getIdFromSEOFriendly(final String l) {
    return StringUtils.isBlank(l) ? null : l.equals(allMark) ? null : Long.parseLong(l);
}

From source file:org.shredzone.cilla.web.converter.StringToCategory.java

@Override
public Category convert(String string) {
    try {/*from w w  w .  j  a  va  2 s. c om*/
        return categoryDao.fetch(Long.parseLong(string));
    } catch (NumberFormatException ex) {
        return null;
    }
}

From source file:com.googlecode.msidor.springframework.integration.history.MessageHistoryParser.java

/**
 * Parse message history generated by spring integration and produce output with components names and components processing times
 * /*w  w w .  ja v  a2s  .  com*/
 * @param mh message headers to be parsed
 * @return output with components names and components processing times
 */
public static String parse(MessageHeaders mh) {
    StringBuilder sb = new StringBuilder();

    //get message history
    MessageHistory history = mh.get(MessageHistory.HEADER_NAME, MessageHistory.class);
    String[] names = new String[history.size()];
    long[] times = new long[history.size()];

    //go thought all history entries
    Iterator<Properties> historyIterator = history.iterator();
    int i = 0;
    while (historyIterator.hasNext()) {
        Properties gatewayHistory = historyIterator.next();
        String name = gatewayHistory.getProperty("name");
        String historyTimestampStr = gatewayHistory.getProperty("timestamp");
        Long historyTimestamp = Long.parseLong(historyTimestampStr);

        names[i] = name;
        times[i++] = historyTimestamp;
    }

    //calculates the time deltas between components 
    final long lastTimestamp = mh.getTimestamp();
    for (int j = 0; j < names.length; j++) {
        if (j > 0) {
            sb.append("; ");
        }

        if (j + 1 < names.length)
            sb.append(names[j]).append("=").append(times[j + 1] - times[j]);
        else
            sb.append(names[j]).append("=").append(lastTimestamp - times[j]);
    }

    if (sb.length() > 0) {
        sb.append("; ");
    }

    sb.append("total=").append(lastTimestamp - times[0]);

    return sb.toString();
}

From source file:cn.bidaround.ytcore.util.HttpHeaderParser.java

/**
 * Extracts a {@link Cache.Entry} from a {@link NetworkResponse}.
 *
 * @param response The network response to parse headers from
 * @return a cache entry for the given response, or null if the response is not cacheable.
 *//*from w  w  w  .  j av  a2  s .  c o m*/
public static Cache.Entry parseCacheHeaders(NetworkResponse response) {
    long now = System.currentTimeMillis();

    Map<String, String> headers = response.headers;

    long serverDate = 0;
    long serverExpires = 0;
    long softExpire = 0;
    long maxAge = 0;
    boolean hasCacheControl = false;

    String serverEtag = null;
    String headerValue;

    headerValue = headers.get("Date");
    if (headerValue != null) {
        serverDate = parseDateAsEpoch(headerValue);
    }

    headerValue = headers.get("Cache-Control");
    if (headerValue != null) {
        hasCacheControl = true;
        String[] tokens = headerValue.split(",");
        for (int i = 0; i < tokens.length; i++) {
            String token = tokens[i].trim();
            if (token.equals("no-cache") || token.equals("no-store")) {
                return null;
            } else if (token.startsWith("max-age=")) {
                try {
                    maxAge = Long.parseLong(token.substring(8));
                } catch (Exception e) {
                }
            } else if (token.equals("must-revalidate") || token.equals("proxy-revalidate")) {
                maxAge = 0;
            }
        }
    }

    headerValue = headers.get("Expires");
    if (headerValue != null) {
        serverExpires = parseDateAsEpoch(headerValue);
    }

    serverEtag = headers.get("ETag");

    // Cache-Control takes precedence over an Expires header, even if both exist and Expires
    // is more restrictive.
    if (hasCacheControl) {
        softExpire = now + maxAge * 1000;
    } else if (serverDate > 0 && serverExpires >= serverDate) {
        // Default semantic for Expire header in HTTP specification is softExpire.
        softExpire = now + (serverExpires - serverDate);
    }

    Cache.Entry entry = new Cache.Entry();
    entry.data = response.data;
    entry.etag = serverEtag;
    entry.softTtl = softExpire;
    entry.ttl = entry.softTtl;
    entry.serverDate = serverDate;
    entry.responseHeaders = headers;

    return entry;
}

From source file:com.github.dfa.diaspora_android.data.PodAspect.java

public PodAspect(String shareabletext) {
    // fromShareAbleText
    String[] str = shareabletext.split("%");
    selected = Integer.parseInt(str[0]) == 1;
    id = Long.parseLong(str[1]);
    name = shareabletext.substring(shareabletext.indexOf(str[1]) + str[1].length() + 1);
}

From source file:de.topobyte.utilities.apache.commons.cli.parsing.ArgumentHelper.java

public static long parseLong(String value) throws ArgumentParseException {
    try {/*from  w w w. ja  va2  s . c  o  m*/
        return Long.parseLong(value);
    } catch (NumberFormatException e) {
        throw new ArgumentParseException("unable to parse long: '" + value + "'");
    }
}

From source file:org.shredzone.cilla.web.converter.StringToTextSection.java

@Override
public TextSection convert(String string) {
    try {/*from   w  w w . j a  v  a2s  . c  om*/
        return (TextSection) sectionDao.fetch(Long.parseLong(string));
    } catch (NumberFormatException | ClassCastException ex) {
        return null;
    }
}