use of java.util.ListIterator in project sonatype-aether by sonatype.
the class DefaultRemoteRepositoryManager method aggregateRepositories.
public List<RemoteRepository> aggregateRepositories(RepositorySystemSession session, List<RemoteRepository> dominantRepositories, List<RemoteRepository> recessiveRepositories, boolean recessiveIsRaw) {
if (recessiveRepositories.isEmpty()) {
return dominantRepositories;
}
MirrorSelector mirrorSelector = session.getMirrorSelector();
AuthenticationSelector authSelector = session.getAuthenticationSelector();
ProxySelector proxySelector = session.getProxySelector();
List<RemoteRepository> result = new ArrayList<RemoteRepository>(dominantRepositories);
next: for (RemoteRepository recessiveRepository : recessiveRepositories) {
RemoteRepository repository = recessiveRepository;
if (recessiveIsRaw) {
RemoteRepository mirrorRepository = mirrorSelector.getMirror(recessiveRepository);
if (mirrorRepository == null) {
repository = recessiveRepository;
} else {
logger.debug("Using mirror " + mirrorRepository.getId() + " (" + mirrorRepository.getUrl() + ") for " + recessiveRepository.getId() + " (" + recessiveRepository.getUrl() + ").");
repository = mirrorRepository;
}
}
String key = getKey(repository);
for (ListIterator<RemoteRepository> it = result.listIterator(); it.hasNext(); ) {
RemoteRepository dominantRepository = it.next();
if (key.equals(getKey(dominantRepository))) {
if (!dominantRepository.getMirroredRepositories().isEmpty() && !repository.getMirroredRepositories().isEmpty()) {
RemoteRepository mergedRepository = mergeMirrors(session, dominantRepository, repository);
if (mergedRepository != dominantRepository) {
it.set(mergedRepository);
}
}
continue next;
}
}
if (recessiveIsRaw) {
Authentication auth = authSelector.getAuthentication(repository);
if (auth != null) {
repository.setAuthentication(auth);
}
Proxy proxy = proxySelector.getProxy(repository);
if (proxy != null) {
repository.setProxy(proxy);
}
}
result.add(repository);
}
return result;
}
use of java.util.ListIterator in project hazelcast by hazelcast.
the class ClientListTest method testIterator.
@Test
public void testIterator() {
assertTrue(list.add("item1"));
assertTrue(list.add("item2"));
assertTrue(list.add("item1"));
assertTrue(list.add("item4"));
Iterator iter = list.iterator();
assertEquals("item1", iter.next());
assertEquals("item2", iter.next());
assertEquals("item1", iter.next());
assertEquals("item4", iter.next());
assertFalse(iter.hasNext());
ListIterator listIterator = list.listIterator(2);
assertEquals("item1", listIterator.next());
assertEquals("item4", listIterator.next());
assertFalse(listIterator.hasNext());
List l = list.subList(1, 3);
assertEquals(2, l.size());
assertEquals("item2", l.get(0));
assertEquals("item1", l.get(1));
}
use of java.util.ListIterator in project j2objc by google.
the class AbstractListTest method test_subList_addAll.
/**
* @tests java.util.AbstractList#subList(int, int)
*/
public void test_subList_addAll() {
// Regression for HARMONY-390
List mainList = new ArrayList();
Object[] mainObjects = { "a", "b", "c" };
mainList.addAll(Arrays.asList(mainObjects));
List subList = mainList.subList(1, 2);
assertFalse("subList should not contain \"a\"", subList.contains("a"));
assertFalse("subList should not contain \"c\"", subList.contains("c"));
assertTrue("subList should contain \"b\"", subList.contains("b"));
Object[] subObjects = { "one", "two", "three" };
subList.addAll(Arrays.asList(subObjects));
assertFalse("subList should not contain \"a\"", subList.contains("a"));
assertFalse("subList should not contain \"c\"", subList.contains("c"));
Object[] expected = { "b", "one", "two", "three" };
ListIterator iter = subList.listIterator();
for (int i = 0; i < expected.length; i++) {
assertTrue("subList should contain " + expected[i], subList.contains(expected[i]));
assertTrue("should be more elements", iter.hasNext());
assertEquals("element in incorrect position", expected[i], iter.next());
}
}
use of java.util.ListIterator in project j2objc by google.
the class LinkedListTest method test_listIteratorI.
/**
* @tests java.util.LinkedList#listIterator(int)
*/
public void test_listIteratorI() {
// Test for method java.util.ListIterator
// java.util.LinkedList.listIterator(int)
ListIterator i = ll.listIterator();
Object elm;
int n = 0;
while (i.hasNext()) {
if (n == 0 || n == objArray.length - 1) {
if (n == 0)
assertTrue("First element claimed to have a previous", !i.hasPrevious());
if (n == objArray.length)
assertTrue("Last element claimed to have next", !i.hasNext());
}
elm = i.next();
assertTrue("Iterator returned elements in wrong order", elm == objArray[n]);
if (n > 0 && n < objArray.length - 1) {
assertTrue("Next index returned incorrect value", i.nextIndex() == n + 1);
assertTrue("previousIndex returned incorrect value : " + i.previousIndex() + ", n val: " + n, i.previousIndex() == n);
}
++n;
}
List myList = new LinkedList();
myList.add(null);
myList.add("Blah");
myList.add(null);
myList.add("Booga");
myList.add(null);
ListIterator li = myList.listIterator();
assertTrue("li.hasPrevious() should be false", !li.hasPrevious());
assertNull("li.next() should be null", li.next());
assertTrue("li.hasPrevious() should be true", li.hasPrevious());
assertNull("li.prev() should be null", li.previous());
assertNull("li.next() should be null", li.next());
assertEquals("li.next() should be Blah", "Blah", li.next());
assertNull("li.next() should be null", li.next());
assertEquals("li.next() should be Booga", "Booga", li.next());
assertTrue("li.hasNext() should be true", li.hasNext());
assertNull("li.next() should be null", li.next());
assertTrue("li.hasNext() should be false", !li.hasNext());
}
use of java.util.ListIterator in project gradle by gradle.
the class DefaultTaskDependency method visitDependencies.
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
if (values.isEmpty()) {
return;
}
Deque<Object> queue = new ArrayDeque<Object>(values);
while (!queue.isEmpty()) {
Object dependency = queue.removeFirst();
if (dependency instanceof Buildable) {
context.add(dependency);
} else if (dependency instanceof Task) {
context.add(dependency);
} else if (dependency instanceof TaskDependency) {
context.add(dependency);
} else if (dependency instanceof Closure) {
Closure closure = (Closure) dependency;
Object closureResult = closure.call(context.getTask());
if (closureResult != null) {
queue.addFirst(closureResult);
}
} else if (dependency instanceof RealizableTaskCollection) {
RealizableTaskCollection realizableTaskCollection = (RealizableTaskCollection) dependency;
realizableTaskCollection.realizeRuleTaskTypes();
addAllFirst(queue, realizableTaskCollection.toArray());
} else if (dependency instanceof List) {
List<?> list = (List) dependency;
if (list instanceof RandomAccess) {
for (int i = list.size() - 1; i >= 0; i--) {
queue.addFirst(list.get(i));
}
} else {
ListIterator<?> iterator = list.listIterator(list.size());
while (iterator.hasPrevious()) {
Object item = iterator.previous();
queue.addFirst(item);
}
}
} else if (dependency instanceof Iterable) {
Iterable<?> iterable = (Iterable) dependency;
addAllFirst(queue, toArray(iterable, Object.class));
} else if (dependency instanceof Map) {
Map<?, ?> map = (Map) dependency;
addAllFirst(queue, map.values().toArray());
} else if (dependency instanceof Object[]) {
Object[] array = (Object[]) dependency;
addAllFirst(queue, array);
} else if (dependency instanceof Callable) {
Callable callable = (Callable) dependency;
Object callableResult = uncheckedCall(callable);
if (callableResult != null) {
queue.addFirst(callableResult);
}
} else if (resolver != null && dependency instanceof TaskReference) {
context.add(resolver.resolveTask((TaskReference) dependency));
} else if (resolver != null && dependency instanceof CharSequence) {
context.add(resolver.resolveTask(dependency.toString()));
} else {
List<String> formats = new ArrayList<String>();
if (resolver != null) {
formats.add("A String or CharSequence task name or path");
formats.add("A TaskReference instance");
}
formats.add("A Task instance");
formats.add("A Buildable instance");
formats.add("A TaskDependency instance");
formats.add("A Closure instance that returns any of the above types");
formats.add("A Callable instance that returns any of the above types");
formats.add("An Iterable, Collection, Map or array instance that contains any of the above types");
throw new UnsupportedNotationException(dependency, String.format("Cannot convert %s to a task.", dependency), null, formats);
}
}
}
Aggregations