List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException(String s)
From source file:de.codesourcery.jasm16.emulator.EmulationOptions.java
public DefaultKeyboard getKeyboard(IEmulator emulator) { List<IDevice> result = emulator.getDevicesByDescriptor(DefaultKeyboard.DESC); if (result.isEmpty()) { throw new NoSuchElementException("Internal error, found no default keyboard ?"); }/*www.j ava2 s . c om*/ if (result.size() > 1) { throw new RuntimeException("Internal error, found more than one default keyboard ?"); } return (DefaultKeyboard) result.get(0); }
From source file:de.codesourcery.jasm16.ide.DefaultWorkspace.java
@Override public IAssemblyProject getProjectByName(String name) { assertWorkspaceOpen();// w w w. jav a 2 s . c o m for (IAssemblyProject p : projects) { if (p.getName().equals(name)) { return p; } } throw new NoSuchElementException("Found no project named '" + name + "'"); }
From source file:com.cloudera.livy.rsc.driver.RSCDriver.java
public BypassJobStatus handle(ChannelHandlerContext ctx, GetBypassJobStatus msg) { for (Iterator<BypassJobWrapper> it = bypassJobs.iterator(); it.hasNext();) { BypassJobWrapper job = it.next(); if (job.jobId.equals(msg.id)) { BypassJobStatus status = job.getStatus(); switch (status.state) { case CANCELLED: case FAILED: case SUCCEEDED: it.remove();/*from ww w .ja v a 2 s. c om*/ break; default: // No-op. } return status; } } throw new NoSuchElementException(msg.id); }
From source file:com.netflix.spinnaker.clouddriver.ecs.provider.view.EcsServerClusterProvider.java
private AmazonCredentials getEcsCredentials(String account) { try {/*from www .j ava 2s .c om*/ return getEcsCredentials().stream().filter(credentials -> credentials.getName().equals(account)) .findFirst().get(); } catch (NoSuchElementException exception) { throw new NoSuchElementException(String.format("There is no ECS account by the name of '%s'", account)); } }
From source file:de.codesourcery.jasm16.compiler.Compiler.java
@Override public void removeCompilerPhase(String name) { for (Iterator<ICompilerPhase> it = compilerPhases.iterator(); it.hasNext();) { final ICompilerPhase type = it.next(); if (type.getName().equals(name)) { it.remove();/*from w ww . j av a2 s. c o m*/ return; } } throw new NoSuchElementException("Failed to remove phase '" + name + "'"); }
From source file:de.uniba.wiai.kinf.pw.projects.lillytab.reasoner.tbox.AssertedRBox.java
@Override public Set<R> getEquivalentRoles(R role) { Set<R> eqRoles = (Set<R>) _equivalentRoles.get(role); if (eqRoles == null) { throw new NoSuchElementException("Unknown role:" + role); }/*from w ww . j a v a 2s.c o m*/ assert eqRoles != null; return Collections.unmodifiableSet(eqRoles); }
From source file:de.suse.swamp.core.container.WorkflowManager.java
/** * @return Workflow-object with the given (db-)id. * Will try to get it from the cache at first. * If not found, a NoSuchElementException is thrown. *///w w w .j a v a 2 s. co m public Workflow getWorkflow(int id) throws NoSuchElementException { Integer idObj = new Integer(id); synchronized (workflowCache) { if (workflowCache.containsKey(idObj)) { return (Workflow) workflowCache.get(idObj); } else { Workflow wf; try { wf = WorkflowStorage.loadWorkflow(id); } catch (StorageException e) { throw new NoSuchElementException(e.getMessage()); } workflowCache.put(idObj, wf); return wf; } } }
From source file:chat.viska.commons.pipelines.Pipeline.java
@SchedulerSupport(SchedulerSupport.IO) public Maybe<Pipe> replace(final String name, final Pipe newPipe) { Validate.notBlank(name);/*ww w. ja v a 2 s . c om*/ return Maybe.fromCallable(() -> { pipeLock.writeLock().lockInterruptibly(); final Pipe oldPipe; try { final ListIterator<Map.Entry<String, Pipe>> iterator = getIteratorOf(name); if (iterator == null) { throw new NoSuchElementException(name); } oldPipe = iterator.next().getValue(); iterator.set(new AbstractMap.SimpleImmutableEntry<>(name, newPipe)); oldPipe.onRemovedFromPipeline(this); newPipe.onAddedToPipeline(this); } finally { pipeLock.writeLock().unlock(); } return oldPipe; }).subscribeOn(Schedulers.io()); }
From source file:com.manh.pool.impl.GenericObjectPool.java
/** * Borrow an object from the pool using the specific waiting time which only * applies if {@link #getBlockWhenExhausted()} is true. * <p>/*from w w w . j ava 2s . c o m*/ * If there is one or more idle instance available in the pool, then an * idle instance will be selected based on the value of {@link #getLifo()}, * activated and returned. If activation fails, or {@link #getTestOnBorrow() * testOnBorrow} is set to <code>true</code> and validation fails, the * instance is destroyed and the next available instance is examined. This * continues until either a valid instance is returned or there are no more * idle instances available. * <p> * If there are no idle instances available in the pool, behavior depends on * the {@link #getMaxTotal() maxTotal}, (if applicable) * {@link #getBlockWhenExhausted()} and the value passed in to the * <code>borrowMaxWaitMillis</code> parameter. If the number of instances * checked out from the pool is less than <code>maxTotal,</code> a new * instance is created, activated and (if applicable) validated and returned * to the caller. If validation fails, a <code>NoSuchElementException</code> * is thrown. * <p> * If the pool is exhausted (no available idle instances and no capacity to * create new ones), this method will either block (if * {@link #getBlockWhenExhausted()} is true) or throw a * <code>NoSuchElementException</code> (if * {@link #getBlockWhenExhausted()} is false). The length of time that this * method will block when {@link #getBlockWhenExhausted()} is true is * determined by the value passed in to the <code>borrowMaxWaitMillis</code> * parameter. * <p> * When the pool is exhausted, multiple calling threads may be * simultaneously blocked waiting for instances to become available. A * "fairness" algorithm has been implemented to ensure that threads receive * available instances in request arrival order. * * @param borrowMaxWaitMillis The time to wait in milliseconds for an object * to become available * * @return object instance from the pool * * @throws NoSuchElementException if an instance cannot be returned * * @throws Exception if an object instance cannot be returned due to an * error */ public T borrowObject(long borrowMaxWaitMillis) throws Exception { assertOpen(); AbandonedConfig ac = this.abandonedConfig; if (ac != null && ac.getRemoveAbandonedOnBorrow() && (getNumIdle() < 2) && (getNumActive() > getMaxTotal() - 3)) { removeAbandoned(ac); } PooledObject<T> p = null; // Get local copy of current config so it is consistent for entire // method execution boolean blockWhenExhausted = getBlockWhenExhausted(); boolean create; long waitTime = System.currentTimeMillis(); while (p == null) { create = false; if (blockWhenExhausted) { p = idleObjects.pollFirst(); if (p == null) { p = create(); if (p != null) { create = true; } } if (p == null) { if (borrowMaxWaitMillis < 0) { p = idleObjects.takeFirst(); } else { p = idleObjects.pollFirst(borrowMaxWaitMillis, TimeUnit.MILLISECONDS); } } if (p == null) { throw new NoSuchElementException("Timeout waiting for idle object"); } if (!p.allocate()) { p = null; } } else { p = idleObjects.pollFirst(); if (p == null) { p = create(); if (p != null) { create = true; } } if (p == null) { throw new NoSuchElementException("Pool exhausted"); } if (!p.allocate()) { p = null; } } if (p != null) { try { factory.activateObject(p); } catch (Exception e) { try { destroy(p); } catch (Exception e1) { // Ignore - activation failure is more important } p = null; if (create) { NoSuchElementException nsee = new NoSuchElementException("Unable to activate object"); nsee.initCause(e); throw nsee; } } if (p != null && (getTestOnBorrow() || create && getTestOnCreate())) { boolean validate = false; Throwable validationThrowable = null; try { validate = factory.validateObject(p); } catch (Throwable t) { PoolUtils.checkRethrow(t); validationThrowable = t; } if (!validate) { try { destroy(p); destroyedByBorrowValidationCount.incrementAndGet(); } catch (Exception e) { // Ignore - validation failure is more important } p = null; if (create) { NoSuchElementException nsee = new NoSuchElementException("Unable to validate object"); nsee.initCause(validationThrowable); throw nsee; } } } } } updateStatsBorrow(p, System.currentTimeMillis() - waitTime); return p.getObject(); }
From source file:com.github.helenusdriver.commons.collections.graph.ConcurrentHashDirectedGraph.java
/** * {@inheritDoc}//www. jav a 2s. c o m * * @author paouelle * * @see com.github.helenusdriver.commons.collections.DirectedGraph#addEdge(java.lang.Object, java.lang.Object) */ @Override public void addEdge(T start, T dest) { final HashNode sn = graph.get(start); if (sn == null) { throw new NoSuchElementException("unknown starting node"); } sn.addEdge(dest); }