Example usage for com.google.common.primitives UnsignedLongs parseUnsignedLong

List of usage examples for com.google.common.primitives UnsignedLongs parseUnsignedLong

Introduction

In this page you can find the example usage for com.google.common.primitives UnsignedLongs parseUnsignedLong.

Prototype

public static long parseUnsignedLong(String s) 

Source Link

Document

Returns the unsigned long value represented by the given decimal string.

Usage

From source file:com.google.cloud.trace.util.TraceContextFactory.java

/**
 * Generates a new trace context based on the value of a trace context header.
 *
 * @param header a string that is the value of a trace context header.
 * @return the new trace context./* www .  ja va 2s  .c  o m*/
 */
public TraceContext fromHeader(String header) {
    int index = header.indexOf('/');
    if (index == -1) {
        TraceId traceId = new TraceId(new BigInteger(header, 16));
        return new TraceContext(traceId, spanIdFactory.invalid(), traceOptionsFactory.create());
    }

    TraceId traceId = new TraceId(new BigInteger(header.substring(0, index), 16));

    String[] afterTraceId = header.substring(index + 1).split(";");
    SpanId spanId = new SpanId(UnsignedLongs.parseUnsignedLong(afterTraceId[0]));
    TraceOptions traceOptions = null;
    for (int i = 1; i < afterTraceId.length; i++) {
        if (afterTraceId[i].startsWith("o=")) {
            String optionsString = afterTraceId[i].substring(2);
            int options = Integer.parseInt(optionsString);
            traceOptions = traceOptionsFactory.create(new TraceOptions(options));
        }
    }

    if (traceOptions == null) {
        traceOptions = traceOptionsFactory.create();
    }

    return new TraceContext(traceId, spanId, traceOptions);
}

From source file:com.google.cloud.trace.core.SpanContextFactory.java

private SpanId parseSpanId(String input) {
    try {//from   www . j av a 2s .  co m
        return new SpanId(UnsignedLongs.parseUnsignedLong(input));
    } catch (NumberFormatException ex) {
        return SpanId.invalid();
    }
}

From source file:com.foundationdb.server.types.mcompat.mcasts.CastUtils.java

public static long parseUnsignedLong(String st, TExecutionContext context) {
    Object truncated = CastUtils.truncateNonDigits(st, context);

    if (truncated instanceof String)
        st = (String) truncated;/*from  w w  w .  j  a  v  a2 s. c o m*/
    else
        st = CastUtils.truncateNonDigitPlainString(((BigDecimal) truncated).toPlainString(), context);

    long value;
    try {
        value = UnsignedLongs.parseUnsignedLong(st);
    } catch (NumberFormatException e) { // overflow error
        context.reportOverflow(e.getMessage());

        // check wether the value is too big or too small
        if (st.charAt(0) == '-')
            value = 0;
        else
            value = UnsignedLongs.MAX_VALUE;
    }
    return value;
}