@Test public void testGetFreeIncludedNamespaceIdWithExistingNamespaces() { final Map<String, String> nsContext = new HashMap<>(); nsContext.put("dmn", "some_uri"); nsContext.put("other", "some_another"); nsContext.put(NamespaceHandler.INCLUDED_NAMESPACE + "1", "uri_1"); nsContext.put(NamespaceHandler.INCLUDED_NAMESPACE + "2", "uri_2"); nsContext.put(NamespaceHandler.INCLUDED_NAMESPACE + "3", "uri_2"); final String expected = NamespaceHandler.INCLUDED_NAMESPACE + "4"; final String actual = NamespaceHandler.getFreeIncludedNamespaceId(nsContext); assertEquals(expected, actual); }
static String getFreeIncludedNamespaceId(final Map<String, String> nsContext) { final int includedNamespaces = (int) nsContext.keySet().stream().filter(k -> k.startsWith(INCLUDED_NAMESPACE)).count(); String freeAliasCandidate = INCLUDED_NAMESPACE + 1; for (int i = 1; i <= includedNamespaces; i++) { if (!nsContext.containsKey(freeAliasCandidate)) { return freeAliasCandidate; } freeAliasCandidate = INCLUDED_NAMESPACE + (i + 1); } return freeAliasCandidate; }
NamespaceHandler { static String getFreeIncludedNamespaceId(final Map<String, String> nsContext) { final int includedNamespaces = (int) nsContext.keySet().stream().filter(k -> k.startsWith(INCLUDED_NAMESPACE)).count(); String freeAliasCandidate = INCLUDED_NAMESPACE + 1; for (int i = 1; i <= includedNamespaces; i++) { if (!nsContext.containsKey(freeAliasCandidate)) { return freeAliasCandidate; } freeAliasCandidate = INCLUDED_NAMESPACE + (i + 1); } return freeAliasCandidate; } }
NamespaceHandler { static String getFreeIncludedNamespaceId(final Map<String, String> nsContext) { final int includedNamespaces = (int) nsContext.keySet().stream().filter(k -> k.startsWith(INCLUDED_NAMESPACE)).count(); String freeAliasCandidate = INCLUDED_NAMESPACE + 1; for (int i = 1; i <= includedNamespaces; i++) { if (!nsContext.containsKey(freeAliasCandidate)) { return freeAliasCandidate; } freeAliasCandidate = INCLUDED_NAMESPACE + (i + 1); } return freeAliasCandidate; }  }
NamespaceHandler { static String getFreeIncludedNamespaceId(final Map<String, String> nsContext) { final int includedNamespaces = (int) nsContext.keySet().stream().filter(k -> k.startsWith(INCLUDED_NAMESPACE)).count(); String freeAliasCandidate = INCLUDED_NAMESPACE + 1; for (int i = 1; i <= includedNamespaces; i++) { if (!nsContext.containsKey(freeAliasCandidate)) { return freeAliasCandidate; } freeAliasCandidate = INCLUDED_NAMESPACE + (i + 1); } return freeAliasCandidate; }  static String addIncludedNamespace(final Map<String, String> nsContext,
                                              final String namespace); static Optional<Map.Entry<String, String>> getAlias(final Map<String, String> nsContext,
                                                               final String namespace); }
NamespaceHandler { static String getFreeIncludedNamespaceId(final Map<String, String> nsContext) { final int includedNamespaces = (int) nsContext.keySet().stream().filter(k -> k.startsWith(INCLUDED_NAMESPACE)).count(); String freeAliasCandidate = INCLUDED_NAMESPACE + 1; for (int i = 1; i <= includedNamespaces; i++) { if (!nsContext.containsKey(freeAliasCandidate)) { return freeAliasCandidate; } freeAliasCandidate = INCLUDED_NAMESPACE + (i + 1); } return freeAliasCandidate; }  static String addIncludedNamespace(final Map<String, String> nsContext,
                                              final String namespace); static Optional<Map.Entry<String, String>> getAlias(final Map<String, String> nsContext,
                                                               final String namespace);  }