@Test public void testGetUniqueTitle() throws Exception { WindowUtilities.tcProvider = () -> Arrays.asList(createTC("A"), createMyTC("B"), createTC("C")); assertEquals("A (2)", WindowUtilities.getUniqueTitle("A", TopComponent.class)); assertEquals("B (2)", WindowUtilities.getUniqueTitle("B", TopComponent.class)); assertEquals("C (2)", WindowUtilities.getUniqueTitle("C", TopComponent.class)); assertEquals("D", WindowUtilities.getUniqueTitle("D", TopComponent.class)); assertEquals("A", WindowUtilities.getUniqueTitle("A", MyTopComponent.class)); assertEquals("B (2)", WindowUtilities.getUniqueTitle("B", MyTopComponent.class)); assertEquals("C", WindowUtilities.getUniqueTitle("C", MyTopComponent.class)); assertEquals("D", WindowUtilities.getUniqueTitle("D", MyTopComponent.class)); }
public static String getUniqueTitle(String titleBase, Class<? extends TopComponent> windowType) { List<String> titles = getOpened(windowType).map(TopComponent::getDisplayName).collect(Collectors.toList()); if (titles.isEmpty()) { return titleBase; } if (!titles.contains(titleBase)) { return titleBase; } for (int i = 2; ; i++) { final String title = String.format("%s (%d)", titleBase, i); if (!titles.contains(title)) { return title; } } }
WindowUtilities { public static String getUniqueTitle(String titleBase, Class<? extends TopComponent> windowType) { List<String> titles = getOpened(windowType).map(TopComponent::getDisplayName).collect(Collectors.toList()); if (titles.isEmpty()) { return titleBase; } if (!titles.contains(titleBase)) { return titleBase; } for (int i = 2; ; i++) { final String title = String.format("%s (%d)", titleBase, i); if (!titles.contains(title)) { return title; } } } }
WindowUtilities { public static String getUniqueTitle(String titleBase, Class<? extends TopComponent> windowType) { List<String> titles = getOpened(windowType).map(TopComponent::getDisplayName).collect(Collectors.toList()); if (titles.isEmpty()) { return titleBase; } if (!titles.contains(titleBase)) { return titleBase; } for (int i = 2; ; i++) { final String title = String.format("%s (%d)", titleBase, i); if (!titles.contains(title)) { return title; } } }  }
WindowUtilities { public static String getUniqueTitle(String titleBase, Class<? extends TopComponent> windowType) { List<String> titles = getOpened(windowType).map(TopComponent::getDisplayName).collect(Collectors.toList()); if (titles.isEmpty()) { return titleBase; } if (!titles.contains(titleBase)) { return titleBase; } for (int i = 2; ; i++) { final String title = String.format("%s (%d)", titleBase, i); if (!titles.contains(title)) { return title; } } }  static String getUniqueTitle(String titleBase, Class<? extends TopComponent> windowType); static Stream<T> getOpened(final Class<T> type); }
WindowUtilities { public static String getUniqueTitle(String titleBase, Class<? extends TopComponent> windowType) { List<String> titles = getOpened(windowType).map(TopComponent::getDisplayName).collect(Collectors.toList()); if (titles.isEmpty()) { return titleBase; } if (!titles.contains(titleBase)) { return titleBase; } for (int i = 2; ; i++) { final String title = String.format("%s (%d)", titleBase, i); if (!titles.contains(title)) { return title; } } }  static String getUniqueTitle(String titleBase, Class<? extends TopComponent> windowType); static Stream<T> getOpened(final Class<T> type);  }