URIReferencesUtils { String convertURI(CrawleableUri uri) { String ret = uri.getUri().toString(); switch (uriShortcutMode) { case TOTAL_URI: return ret; case NAMESPACE: int lastCross = ret.lastIndexOf('#'); int lastQuestionMark = ret.lastIndexOf('?'); int lastSlash = ret.lastIndexOf('/'); boolean protocolSlash = ret.contains(" if (lastCross == -1 && lastQuestionMark == -1) { if (protocolSlash && lastSlash <= 8) { return (lastSlash == ret.length() - 1) ? ret.substring(0, ret.length() - 1) : ret; } else { return ret.substring(0, lastSlash); } } int endPosition = Math.min(lastQuestionMark, lastCross); endPosition = (endPosition == -1 && lastQuestionMark == -1) ? lastCross : lastQuestionMark; endPosition = (endPosition - 1 == lastSlash) ? endPosition - 1 : endPosition; return ret.substring(0, endPosition); case ONLY_DOMAIN: int protocolSlashPosition = ret.indexOf(" int firstSlash = ret.indexOf('/', protocolSlashPosition + 2); return ret.substring(protocolSlashPosition + 2, (firstSlash <= protocolSlashPosition + 2) ? ret.length() - 1 : firstSlash); default: throw new IllegalArgumentException("For " + uriShortcutMode + " there is no handling defined in convertURI() until yet!"); } } URIReferencesUtils();   URIReferencesUtils(URIShortcutMode uriShortcutMode);   }
@Test public void convertURI() { URIReferencesUtils utils; utils = new URIReferencesUtils(URIShortcutMode.TOTAL_URI); assertEquals("TOTAL_URI_TEST", "https: utils = new URIReferencesUtils(URIShortcutMode.NAMESPACE); assertEquals("NAMESPACE_TEST", "https: assertEquals("NAMESPACE_TEST", "https: utils = new URIReferencesUtils(URIShortcutMode.ONLY_DOMAIN); assertEquals("ONLY_DOMAIN_TEST", "www.philippheinisch.de", utils.convertURI(mainURI1)); assertEquals("ONLY_DOMAIN_TEST", "www.philippheinisch.de", utils.convertURI(mainURI2)); assertEquals("ONLY_DOMAIN_TEST", "www.philippheinisch.de", utils.convertURI(mainURI2_extend)); }