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
}
}
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);
}
};
}
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);
}
}
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);
}
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());
}
Aggregations