@Test public void testLength() throws Exception { assertEquals(0, new Text(new StructuredAuthority(new Precoded(""))).length()); assertEquals(4, new Text(new StructuredAuthority(new Precoded("host"))).length()); assertEquals(8, new Text(new StructuredAuthority(new Precoded("host"), 123)).length()); assertEquals(9, new Text(new StructuredAuthority(new Precoded("user"), new Precoded("host"))).length()); assertEquals(13, new Text(new StructuredAuthority(new Precoded("user"), new Precoded("host"), 123)).length()); assertEquals(5, new Text(new StructuredAuthority(new Precoded("user"), new Precoded(""))).length()); assertEquals(4, new Text(new StructuredAuthority(new Precoded(""), 123)).length()); assertEquals(9, new Text(new StructuredAuthority(new Precoded("user"), new Precoded(""), 123)).length()); }
@Override public int length() { if (mText == null) { int len = mDelegate.host().length(); if (mDelegate.userInfo().isPresent()) { len += mDelegate.userInfo().value().length() + 1; } Optional<Integer> optionalPort = mDelegate.port(); if (optionalPort.isPresent()) { int port = optionalPort.value(); if (port < 10) { len += 2; } else if (port < 100) { len += 3; } else if (port < 1000) { len += 4; } else if (port < 10000) { len += 5; } else if (port < 100000) { len += 6; } else { throw new IllegalArgumentException(String.format("Port number %d out of range (<100000)", port)); } } return len; } return mText.length(); }
Text implements UriEncoded { @Override public int length() { if (mText == null) { int len = mDelegate.host().length(); if (mDelegate.userInfo().isPresent()) { len += mDelegate.userInfo().value().length() + 1; } Optional<Integer> optionalPort = mDelegate.port(); if (optionalPort.isPresent()) { int port = optionalPort.value(); if (port < 10) { len += 2; } else if (port < 100) { len += 3; } else if (port < 1000) { len += 4; } else if (port < 10000) { len += 5; } else if (port < 100000) { len += 6; } else { throw new IllegalArgumentException(String.format("Port number %d out of range (<100000)", port)); } } return len; } return mText.length(); } }
Text implements UriEncoded { @Override public int length() { if (mText == null) { int len = mDelegate.host().length(); if (mDelegate.userInfo().isPresent()) { len += mDelegate.userInfo().value().length() + 1; } Optional<Integer> optionalPort = mDelegate.port(); if (optionalPort.isPresent()) { int port = optionalPort.value(); if (port < 10) { len += 2; } else if (port < 100) { len += 3; } else if (port < 1000) { len += 4; } else if (port < 10000) { len += 5; } else if (port < 100000) { len += 6; } else { throw new IllegalArgumentException(String.format("Port number %d out of range (<100000)", port)); } } return len; } return mText.length(); } Text(Authority delegate); }
Text implements UriEncoded { @Override public int length() { if (mText == null) { int len = mDelegate.host().length(); if (mDelegate.userInfo().isPresent()) { len += mDelegate.userInfo().value().length() + 1; } Optional<Integer> optionalPort = mDelegate.port(); if (optionalPort.isPresent()) { int port = optionalPort.value(); if (port < 10) { len += 2; } else if (port < 100) { len += 3; } else if (port < 1000) { len += 4; } else if (port < 10000) { len += 5; } else if (port < 100000) { len += 6; } else { throw new IllegalArgumentException(String.format("Port number %d out of range (<100000)", port)); } } return len; } return mText.length(); } Text(Authority delegate); @Override int length(); @Override char charAt(int i); @Override UriEncoded subSequence(int startIndex, int endIndex); @Override String toString(); @Override UriEncoded normalized(); @Override CharSequence decoded(String charset); @Override CharSequence decoded(); }
Text implements UriEncoded { @Override public int length() { if (mText == null) { int len = mDelegate.host().length(); if (mDelegate.userInfo().isPresent()) { len += mDelegate.userInfo().value().length() + 1; } Optional<Integer> optionalPort = mDelegate.port(); if (optionalPort.isPresent()) { int port = optionalPort.value(); if (port < 10) { len += 2; } else if (port < 100) { len += 3; } else if (port < 1000) { len += 4; } else if (port < 10000) { len += 5; } else if (port < 100000) { len += 6; } else { throw new IllegalArgumentException(String.format("Port number %d out of range (<100000)", port)); } } return len; } return mText.length(); } Text(Authority delegate); @Override int length(); @Override char charAt(int i); @Override UriEncoded subSequence(int startIndex, int endIndex); @Override String toString(); @Override UriEncoded normalized(); @Override CharSequence decoded(String charset); @Override CharSequence decoded();  }