mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-10 22:56:11 +02:00
Add fromString method to connect point
Change-Id: If90b7582b554896250571b9290fd639dfb7057d5
This commit is contained in:
parent
55965c6aae
commit
b0bc9da0b5
@ -144,6 +144,23 @@ public class ConnectPoint implements Comparable<ConnectPoint> {
|
||||
PortNumber.portNumber(string.substring(lastSlash + 1, string.length())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a device connect point from a string.
|
||||
* The connect point should be in the same format as toString output.
|
||||
*
|
||||
* @param string string to parse
|
||||
* @return a ConnectPoint based on the information in the string.
|
||||
*/
|
||||
public static ConnectPoint fromString(String string) {
|
||||
checkNotNull(string);
|
||||
String[] splitted = string.split("/");
|
||||
checkArgument(splitted.length == 2,
|
||||
"Connect point must be in \"deviceUri/portNumber\" format");
|
||||
|
||||
return new ConnectPoint(DeviceId.deviceId(splitted[0]),
|
||||
PortNumber.fromString(splitted[1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(elementId, portNumber);
|
||||
|
||||
@ -71,6 +71,17 @@ public class ConnectPointTest {
|
||||
expectDeviceParseException("of:0011223344556677/word");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseFromString() {
|
||||
String cp = "netconf:127.0.0.1/[TYPE](1)";
|
||||
|
||||
ConnectPoint connectPoint = ConnectPoint.fromString(cp);
|
||||
assertEquals("netconf:127.0.0.1", connectPoint.deviceId().toString());
|
||||
assertEquals("[TYPE](1)", connectPoint.port().toString());
|
||||
assertEquals(connectPoint, ConnectPoint.fromString(connectPoint.toString()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a device connect point and expect an exception to be thrown.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user