Search in sources :

Example 16 with ListIterator

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;
}
Also used : ProxySelector(org.sonatype.aether.repository.ProxySelector) Proxy(org.sonatype.aether.repository.Proxy) AuthenticationSelector(org.sonatype.aether.repository.AuthenticationSelector) MirrorSelector(org.sonatype.aether.repository.MirrorSelector) Authentication(org.sonatype.aether.repository.Authentication) ArrayList(java.util.ArrayList) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ListIterator(java.util.ListIterator)

Example 17 with ListIterator

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));
}
Also used : Iterator(java.util.Iterator) ListIterator(java.util.ListIterator) ArrayList(java.util.ArrayList) List(java.util.List) IList(com.hazelcast.core.IList) ListIterator(java.util.ListIterator) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with ListIterator

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());
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AbstractList(java.util.AbstractList) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator)

Example 19 with ListIterator

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());
}
Also used : List(java.util.List) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) LinkedList(java.util.LinkedList)

Example 20 with ListIterator

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);
        }
    }
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Closure(groovy.lang.Closure) RandomAccess(java.util.RandomAccess) ListIterator(java.util.ListIterator) ArrayDeque(java.util.ArrayDeque) Callable(java.util.concurrent.Callable) TaskReference(org.gradle.api.tasks.TaskReference) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Buildable(org.gradle.api.Buildable)

Aggregations

ListIterator (java.util.ListIterator)81 List (java.util.List)30 ArrayList (java.util.ArrayList)29 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)15 AbstractList (java.util.AbstractList)7 AbstractSequentialList (java.util.AbstractSequentialList)6 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 Map (java.util.Map)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4 File (java.io.File)3 IOException (java.io.IOException)3 SipException (javax.sip.SipException)3 ObjectType (org.apache.geode.cache.query.types.ObjectType)3 StructType (org.apache.geode.cache.query.types.StructType)3 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2