Search in sources :

Example 76 with NoSuchElementException

use of java.util.NoSuchElementException in project sling by apache.

the class JcrNodeResourceIteratorTest method testMulti.

public void testMulti() throws RepositoryException {
    int numNodes = 10;
    String pathBase = "/parent/path/node/";
    Node[] nodes = new Node[numNodes];
    for (int i = 0; i < nodes.length; i++) {
        nodes[i] = new MockNode(pathBase + i, "some:type" + i);
    }
    NodeIterator ni = new MockNodeIterator(nodes);
    JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, null, null, ni, getHelperData(), null);
    for (int i = 0; i < nodes.length; i++) {
        assertTrue(ri.hasNext());
        Resource res = ri.next();
        assertEquals(pathBase + i, res.getPath());
        assertEquals(nodes[i].getPrimaryNodeType().getName(), res.getResourceType());
    }
    assertFalse(ri.hasNext());
    try {
        ri.next();
        fail("Expected no element in the iterator");
    } catch (NoSuchElementException nsee) {
    // expected
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNodeIterator(org.apache.sling.commons.testing.jcr.MockNodeIterator) MockNode(org.apache.sling.commons.testing.jcr.MockNode) Node(javax.jcr.Node) Resource(org.apache.sling.api.resource.Resource) MockNode(org.apache.sling.commons.testing.jcr.MockNode) JcrNodeResourceIterator(org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator) NoSuchElementException(java.util.NoSuchElementException)

Example 77 with NoSuchElementException

use of java.util.NoSuchElementException in project intellij-community by JetBrains.

the class PsiLocation method getAncestors.

@Override
@NotNull
public <T extends PsiElement> Iterator<Location<T>> getAncestors(@NotNull final Class<T> ancestorClass, final boolean strict) {
    final T first = strict || !ancestorClass.isInstance(myPsiElement) ? findNext(myPsiElement, ancestorClass) : (T) myPsiElement;
    return new Iterator<Location<T>>() {

        private T myCurrent = first;

        @Override
        public boolean hasNext() {
            return myCurrent != null;
        }

        @Override
        public Location<T> next() {
            if (myCurrent == null)
                throw new NoSuchElementException();
            final PsiLocation<T> psiLocation = new PsiLocation<>(myProject, myCurrent);
            myCurrent = findNext(myCurrent, ancestorClass);
            return psiLocation;
        }

        @Override
        public void remove() {
            LOG.assertTrue(false);
        }
    };
}
Also used : Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException) NotNull(org.jetbrains.annotations.NotNull)

Example 78 with NoSuchElementException

use of java.util.NoSuchElementException in project sling by apache.

the class QuartzScheduler method removeJob.

/**
     * @see org.apache.sling.commons.scheduler.Scheduler#removeJob(java.lang.String)
     */
public void removeJob(final Long bundleId, final String jobName) throws NoSuchElementException {
    // as this method might be called from unbind and during
    // unbind a deactivate could happen, we check the scheduler first
    final Map<String, SchedulerProxy> proxies;
    synchronized (this.schedulers) {
        if (this.active) {
            proxies = new HashMap<>(this.schedulers);
        } else {
            proxies = Collections.emptyMap();
        }
    }
    for (final SchedulerProxy proxy : proxies.values()) {
        synchronized (proxy) {
            try {
                final JobKey key = JobKey.jobKey(jobName);
                final JobDetail jobdetail = proxy.getScheduler().getJobDetail(key);
                if (jobdetail != null) {
                    proxy.getScheduler().deleteJob(key);
                    this.logger.debug("Unscheduling job with name {}", jobName);
                    return;
                }
            } catch (final SchedulerException ignored) {
            // ignore
            }
        }
    }
    if (this.active) {
        throw new NoSuchElementException("No job found with name " + jobName);
    }
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) NoSuchElementException(java.util.NoSuchElementException)

Example 79 with NoSuchElementException

use of java.util.NoSuchElementException in project sling by apache.

the class RepositoryClassLoader method findResources.

/**
     * Returns an Enumeration of URLs representing all of the resources
     * on the search path having the specified name.
     *
     * @param name the resource name
     *
     * @return an <code>Enumeration</code> of <code>URL</code>s. This is an
     *      empty enumeration if no resources are found by this class loader
     *      or if this class loader has already been destroyed.
     */
@Override
public Enumeration<URL> findResources(final String name) {
    if (!this.writer.isActivate()) {
        logger.warn("Destroyed class loader cannot find a resources: " + name, new IllegalStateException());
        return new Enumeration<URL>() {

            public boolean hasMoreElements() {
                return false;
            }

            public URL nextElement() {
                throw new NoSuchElementException("No Entries");
            }
        };
    }
    logger.debug("findResources: Try to find resources for {}", name);
    final URL url = this.findResource(name);
    final List<URL> list = Collections.singletonList(url);
    if (url != null) {
        list.add(url);
    }
    // return the enumeration on the list
    return Collections.enumeration(list);
}
Also used : Enumeration(java.util.Enumeration) NoSuchElementException(java.util.NoSuchElementException) URL(java.net.URL)

Example 80 with NoSuchElementException

use of java.util.NoSuchElementException in project geode by apache.

the class DistributionManager method getOldestMember.

/* implementation of DM.getOldestMember */
public DistributedMember getOldestMember(Collection c) throws NoSuchElementException {
    List<InternalDistributedMember> view = getViewMembers();
    for (int i = 0; i < view.size(); i++) {
        Object viewMbr = view.get(i);
        Iterator it = c.iterator();
        while (it.hasNext()) {
            Object nextMbr = it.next();
            if (viewMbr.equals(nextMbr)) {
                return (DistributedMember) nextMbr;
            }
        }
    }
    throw new NoSuchElementException(LocalizedStrings.DistributionManager_NONE_OF_THE_GIVEN_MANAGERS_IS_IN_THE_CURRENT_MEMBERSHIP_VIEW.toLocalizedString());
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

NoSuchElementException (java.util.NoSuchElementException)1629 Iterator (java.util.Iterator)234 ArrayList (java.util.ArrayList)138 IOException (java.io.IOException)137 Test (org.junit.Test)95 StringTokenizer (java.util.StringTokenizer)88 Scanner (java.util.Scanner)86 Map (java.util.Map)56 List (java.util.List)54 File (java.io.File)51 HashMap (java.util.HashMap)47 InputMismatchException (java.util.InputMismatchException)47 LinkedList (java.util.LinkedList)32 HashSet (java.util.HashSet)31 Set (java.util.Set)29 CorruptDataException (com.ibm.j9ddr.CorruptDataException)28 Locale (java.util.Locale)27 Collection (java.util.Collection)26 BufferedReader (java.io.BufferedReader)24 Enumeration (java.util.Enumeration)24