@Test(groups = "conn", dataProvider = "urls") public void iterator(final String actual, final LdapURL[] expected, final int count) { final RoundRobinConnectionStrategy strategy = new RoundRobinConnectionStrategy(); strategy.initialize(actual, ldapURL -> true); for (int i = 0; i < count; i++) { strategy.iterator(); } Assert.assertEquals( StreamSupport.stream(strategy.spliterator(), false).collect(Collectors.toList()), Arrays.asList(expected)); }
@Override public synchronized Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } final List<LdapURL> urls = new ArrayList<>(ldapURLSet.getActiveUrls()); if (urls.size() > 1) { for (int i = 0; i < counter.get(); i++) { urls.add(urls.remove(0)); } } urls.addAll(ldapURLSet.getInactiveUrls()); counter.incrementAndGet(); if (iterFunction != null) { return iterFunction.apply(ldapURLSet.getUrls()); } return new DefaultLdapURLIterator(urls); }
RoundRobinConnectionStrategy extends AbstractConnectionStrategy { @Override public synchronized Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } final List<LdapURL> urls = new ArrayList<>(ldapURLSet.getActiveUrls()); if (urls.size() > 1) { for (int i = 0; i < counter.get(); i++) { urls.add(urls.remove(0)); } } urls.addAll(ldapURLSet.getInactiveUrls()); counter.incrementAndGet(); if (iterFunction != null) { return iterFunction.apply(ldapURLSet.getUrls()); } return new DefaultLdapURLIterator(urls); } }
RoundRobinConnectionStrategy extends AbstractConnectionStrategy { @Override public synchronized Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } final List<LdapURL> urls = new ArrayList<>(ldapURLSet.getActiveUrls()); if (urls.size() > 1) { for (int i = 0; i < counter.get(); i++) { urls.add(urls.remove(0)); } } urls.addAll(ldapURLSet.getInactiveUrls()); counter.incrementAndGet(); if (iterFunction != null) { return iterFunction.apply(ldapURLSet.getUrls()); } return new DefaultLdapURLIterator(urls); } RoundRobinConnectionStrategy();  RoundRobinConnectionStrategy(final Function<List<LdapURL>, Iterator<LdapURL>> function); }
RoundRobinConnectionStrategy extends AbstractConnectionStrategy { @Override public synchronized Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } final List<LdapURL> urls = new ArrayList<>(ldapURLSet.getActiveUrls()); if (urls.size() > 1) { for (int i = 0; i < counter.get(); i++) { urls.add(urls.remove(0)); } } urls.addAll(ldapURLSet.getInactiveUrls()); counter.incrementAndGet(); if (iterFunction != null) { return iterFunction.apply(ldapURLSet.getUrls()); } return new DefaultLdapURLIterator(urls); } RoundRobinConnectionStrategy();  RoundRobinConnectionStrategy(final Function<List<LdapURL>, Iterator<LdapURL>> function); @Override synchronized Iterator<LdapURL> iterator(); }
RoundRobinConnectionStrategy extends AbstractConnectionStrategy { @Override public synchronized Iterator<LdapURL> iterator() { if (!isInitialized()) { throw new IllegalStateException("Strategy is not initialized"); } final List<LdapURL> urls = new ArrayList<>(ldapURLSet.getActiveUrls()); if (urls.size() > 1) { for (int i = 0; i < counter.get(); i++) { urls.add(urls.remove(0)); } } urls.addAll(ldapURLSet.getInactiveUrls()); counter.incrementAndGet(); if (iterFunction != null) { return iterFunction.apply(ldapURLSet.getUrls()); } return new DefaultLdapURLIterator(urls); } RoundRobinConnectionStrategy();  RoundRobinConnectionStrategy(final Function<List<LdapURL>, Iterator<LdapURL>> function); @Override synchronized Iterator<LdapURL> iterator();  }