UserAndHostAndPort implements Serializable { public static UserAndHostAndPort fromString(String str) { int userEnd = str.indexOf("@"); if (userEnd < 0) throw new IllegalArgumentException("User missing (no '@' in "+str); return new UserAndHostAndPort(str.substring(0, userEnd).trim(), HostAndPort.fromString(str.substring(userEnd+1).trim())); } protected  UserAndHostAndPort(String user, HostAndPort hostAndPort); static UserAndHostAndPort fromParts(String user, String host, int port); static UserAndHostAndPort fromParts(String user, String host, Optional<Integer> port); static UserAndHostAndPort fromParts(String user, HostAndPort hostAndPort); static UserAndHostAndPort fromString(String str); String getUser(); HostAndPort getHostAndPort(); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testFromString() throws Exception { assertIt(UserAndHostAndPort.fromString("myuser@myhost:1234"), "myuser", HostAndPort.fromParts("myhost", 1234)); assertIt(UserAndHostAndPort.fromString("myuser @ myhost:1234"), "myuser", HostAndPort.fromParts("myhost", 1234)); assertIt(UserAndHostAndPort.fromString("myuser @ myhost"), "myuser", HostAndPort.fromString("myhost")); }