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

The following examples show how to use com.google.common.primitives.UnsignedLongs#decode() . 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: CircuitId.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example 2
Source File: NoteCoordinate.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static byte[] getBytesFromUnid(final CharSequence unid) {
	if (unid == null)
		return null;
	if (DominoUtils.isUnid(unid)) {
		String first = "0x" + unid.subSequence(0, 16);
		long flong = UnsignedLongs.decode(first);
		byte[] fbytes = Longs.toByteArray(flong);
		String last = "0x" + unid.subSequence(16, 32);
		long llong = UnsignedLongs.decode(last);
		byte[] lbytes = Longs.toByteArray(llong);
		return Bytes.concat(fbytes, lbytes);
	} else {
		throw new IllegalArgumentException("Cannot convert a String of length " + unid.length() + ": " + unid);
	}
}
 
Example 3
Source File: NoteCoordinate.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static long getLongFromReplid(final CharSequence replid) throws IllegalArgumentException {
	if (replid == null)
		throw new IllegalArgumentException("null is not a valid replica id");
	if (DominoUtils.isReplicaId(replid)) {
		String decode = "0x" + replid.toString();
		long result = UnsignedLongs.decode(decode);
		return result;
	} else {
		throw new IllegalArgumentException("Cannot convert a String of length " + replid.length() + ": " + replid);
	}
}
 
Example 4
Source File: NoteCoordinate.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static long[] getLongsFromUnid(final CharSequence unid) throws IllegalArgumentException {
	if (unid == null)
		throw new IllegalArgumentException("null is not a valid unid");
	if (DominoUtils.isUnid(unid)) {
		long[] result = new long[2];
		String first = "0x" + unid.subSequence(0, 16);
		result[0] = UnsignedLongs.decode(first);
		String last = "0x" + unid.subSequence(16, 32);
		result[1] = UnsignedLongs.decode(last);
		return result;
	} else {
		throw new IllegalArgumentException("Cannot convert a String of length " + unid.length() + ": " + unid);
	}
}
 
Example 5
Source File: OpticalLogicId.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * 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));
}
 
Example 6
Source File: PortNumber.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the port number representing the specified string value.
 *
 * @param string port number as decimal, hexadecimal, or octal number string
 * @return port number
 */
public static PortNumber portNumber(String string) {
    return new PortNumber(UnsignedLongs.decode(string));
}