@Test public void testFindUriType() { final Map<String, HostParser.URITypes> tests = ImmutableMap.<String, HostParser.URITypes>builder() .put("/path", HostParser.URITypes.Absolute) .put("user@domain/path", HostParser.URITypes.Rootless) .put(" .put("", HostParser.URITypes.Undefined).build(); for(Map.Entry<String, HostParser.URITypes> entry : tests.entrySet()) { final HostParser.StringReader reader = new HostParser.StringReader(entry.getKey()); assertEquals(HostParser.findURIType(reader), entry.getValue()); } }
static URITypes findURIType(final StringReader reader) { final StringReader copy = reader.copy(); if(!copy.endOfString()) { char c = (char) copy.read(); if(c == '/') { reader.skip(1); if(!copy.endOfString()) { c = (char) copy.read(); if(c == '/') { reader.skip(1); return URITypes.Authority; } reader.skip(-1); } return URITypes.Absolute; } return URITypes.Rootless; } return URITypes.Undefined; }
HostParser { static URITypes findURIType(final StringReader reader) { final StringReader copy = reader.copy(); if(!copy.endOfString()) { char c = (char) copy.read(); if(c == '/') { reader.skip(1); if(!copy.endOfString()) { c = (char) copy.read(); if(c == '/') { reader.skip(1); return URITypes.Authority; } reader.skip(-1); } return URITypes.Absolute; } return URITypes.Rootless; } return URITypes.Undefined; } }
HostParser { static URITypes findURIType(final StringReader reader) { final StringReader copy = reader.copy(); if(!copy.endOfString()) { char c = (char) copy.read(); if(c == '/') { reader.skip(1); if(!copy.endOfString()) { c = (char) copy.read(); if(c == '/') { reader.skip(1); return URITypes.Authority; } reader.skip(-1); } return URITypes.Absolute; } return URITypes.Rootless; } return URITypes.Undefined; } HostParser();  HostParser(final ProtocolFactory factory);  HostParser(final ProtocolFactory factory, final Protocol defaultScheme); }
HostParser { static URITypes findURIType(final StringReader reader) { final StringReader copy = reader.copy(); if(!copy.endOfString()) { char c = (char) copy.read(); if(c == '/') { reader.skip(1); if(!copy.endOfString()) { c = (char) copy.read(); if(c == '/') { reader.skip(1); return URITypes.Authority; } reader.skip(-1); } return URITypes.Absolute; } return URITypes.Rootless; } return URITypes.Undefined; } HostParser();  HostParser(final ProtocolFactory factory);  HostParser(final ProtocolFactory factory, final Protocol defaultScheme); Host get(final String url); static Host parse(final String url); }
HostParser { static URITypes findURIType(final StringReader reader) { final StringReader copy = reader.copy(); if(!copy.endOfString()) { char c = (char) copy.read(); if(c == '/') { reader.skip(1); if(!copy.endOfString()) { c = (char) copy.read(); if(c == '/') { reader.skip(1); return URITypes.Authority; } reader.skip(-1); } return URITypes.Absolute; } return URITypes.Rootless; } return URITypes.Undefined; } HostParser();  HostParser(final ProtocolFactory factory);  HostParser(final ProtocolFactory factory, final Protocol defaultScheme); Host get(final String url); static Host parse(final String url);  }