public void testDecodeLong() { assertEquals(0xffffffffffffffffL, UnsignedLongs.decode("0xffffffffffffffff")); assertEquals(01234567, UnsignedLongs.decode("01234567")); // octal assertEquals(0x1234567890abcdefL, UnsignedLongs.decode("#1234567890abcdef")); assertEquals(987654321012345678L, UnsignedLongs.decode("987654321012345678")); assertEquals(0x135791357913579L, UnsignedLongs.decode("0x135791357913579")); assertEquals(0x135791357913579L, UnsignedLongs.decode("0X135791357913579")); assertEquals(0L, UnsignedLongs.decode("0")); }
public void testDecodeLongFails() { try { // One more than maximum value UnsignedLongs.decode("0xfffffffffffffffff"); fail(); } catch (NumberFormatException expected) { } try { UnsignedLongs.decode("-5"); fail(); } catch (NumberFormatException expected) { } try { UnsignedLongs.decode("-0x5"); fail(); } catch (NumberFormatException expected) { } try { UnsignedLongs.decode("-05"); fail(); } catch (NumberFormatException expected) { } }
@Override public Long deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { String sValue = jp.getValueAsString(); return UnsignedLongs.decode(sValue); } }
/** * Returns the LabelId representing the specified string value. * * @param string identifier as string value * @return LabelId */ public static OpticalLogicId logicId(String string) { return new OpticalLogicId(UnsignedLongs.decode(string)); }
/** * Deserialize circuit id from byte string. * * @param circuitId the circuit id byte string * @return a Circuit Id */ public static CircuitId deserialize(byte[] circuitId) { String cIdString = new String(circuitId, StandardCharsets.US_ASCII); List<String> splittedCircuitId = Lists.newArrayList(cIdString.split(SEPARATOR)); checkArgument(splittedCircuitId.size() > 1, "Illegal circuit id."); // remove last element (vlan id) String vlanId = splittedCircuitId.remove(splittedCircuitId.size() - 1); // Reconstruct device Id String connectPoint = String.join(SEPARATOR, splittedCircuitId); String[] splittedConnectPoint = connectPoint.split(DEVICE_PORT_SEPARATOR); // Check connect point is valid or not checkArgument(splittedConnectPoint.length == 2, "Connect point must be in \"deviceUri/portNumber\" format"); // Check the port number is a number or not UnsignedLongs.decode(splittedConnectPoint[1]); return new CircuitId(connectPoint, VlanId.vlanId(vlanId)); }
public void testDecodeLong() { assertEquals(0xffffffffffffffffL, UnsignedLongs.decode("0xffffffffffffffff")); assertEquals(01234567, UnsignedLongs.decode("01234567")); // octal assertEquals(0x1234567890abcdefL, UnsignedLongs.decode("#1234567890abcdef")); assertEquals(987654321012345678L, UnsignedLongs.decode("987654321012345678")); assertEquals(0x135791357913579L, UnsignedLongs.decode("0x135791357913579")); assertEquals(0x135791357913579L, UnsignedLongs.decode("0X135791357913579")); assertEquals(0L, UnsignedLongs.decode("0")); }
@Benchmark long parseDecode10(int reps) { long tmp = 0; for (int i = 0; i < reps; i++) { int j = i & ARRAY_MASK; tmp += UnsignedLongs.decode(decimalStrings[j]); } return tmp; }
@Benchmark long parseDecode16(int reps) { long tmp = 0; for (int i = 0; i < reps; i++) { int j = i & ARRAY_MASK; tmp += UnsignedLongs.decode(prefixedHexStrings[j]); } return tmp; }
public void testDecodeLongFails() { try { // One more than maximum value UnsignedLongs.decode("0xfffffffffffffffff"); fail(); } catch (NumberFormatException expected) { } try { UnsignedLongs.decode("-5"); fail(); } catch (NumberFormatException expected) { } try { UnsignedLongs.decode("-0x5"); fail(); } catch (NumberFormatException expected) { } try { UnsignedLongs.decode("-05"); fail(); } catch (NumberFormatException expected) { } }