Java Code Examples for com.google.common.primitives.UnsignedLongs#parseUnsignedLong()

The following examples show how to use com.google.common.primitives.UnsignedLongs#parseUnsignedLong() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CastUtils.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
public static long parseUnsignedLong(String st, TExecutionContext context)
{
    Object truncated = CastUtils.truncateNonDigits(st, context);

    if (truncated instanceof String)
        st = (String)truncated;
    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;
}
 
Example 2
Source File: SpanContextFactory.java    From cloud-trace-java with Apache License 2.0 5 votes vote down vote up
private SpanId parseSpanId(String input) {
  try {
    return new SpanId(UnsignedLongs.parseUnsignedLong(input));
  } catch (NumberFormatException ex) {
    return SpanId.invalid();
  }
}
 
Example 3
Source File: TableUuidFormat.java    From emodb with Apache License 2.0 4 votes vote down vote up
public static long decode(String uuid) {
    return UnsignedLongs.parseUnsignedLong(uuid, 16);
}
 
Example 4
Source File: MNumeric.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void readCollating(ValueSource in, TInstance typeInstance, ValueTarget out) {
    BigInteger asBigint = (BigInteger) in.getObject();
    long asLong = UnsignedLongs.parseUnsignedLong(asBigint.toString());
    out.putInt64(asLong);
}
 
Example 5
Source File: UUIDs.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public UUID parse(String uuid) {
    checkArgument(uuid.length() == 32, "Not an UUID: " + uuid);
    return new UUID(UnsignedLongs.parseUnsignedLong(uuid.substring(0, 16), 16),
            UnsignedLongs.parseUnsignedLong(uuid.substring(16), 16));
}
 
Example 6
Source File: AtriumTools.java    From atrium-odl with Apache License 2.0 2 votes vote down vote up
/**
 * Converts a string from hex to long.
 *
 * @param string
 *            hex number in string form; sans 0x
 * @return long value
 */
public static long fromHex(String string) {
	return UnsignedLongs.parseUnsignedLong(string, 16);
}
 
Example 7
Source File: Tools.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Converts a string from hex to long.
 *
 * @param string hex number in string form; sans 0x
 * @return long value
 */
public static long fromHex(String string) {
    return UnsignedLongs.parseUnsignedLong(string, 16);
}