List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException(String s)
From source file:localdomain.localhost.CasInitializer.java
@ManagedOperation public void deleteUser(@NotNull String username) { Connection cnn = null;//from www . j a v a2 s. com PreparedStatement stmt = null; try { cnn = dataSource.getConnection(); cnn.setAutoCommit(false); stmt = cnn.prepareStatement("delete from `" + tableUsers + "` where `" + fieldUser + "` like ?"); stmt.setString(1, username); int rowCount = stmt.executeUpdate(); if (rowCount == 0) { throw new NoSuchElementException("No user '" + username + "' found"); } else if (rowCount == 1) { logger.info("User '" + username + "' was deleted"); } else { new IllegalArgumentException( "More (" + rowCount + ") than 1 row deleted for username '" + username + "', rollback"); } logger.info("User '" + username + "' deleted"); cnn.commit(); } catch (RuntimeException e) { rollbackQuietly(cnn); String msg = "Exception deleting user '" + username + "': " + e; logger.warn(msg, e); throw new RuntimeException(msg); } catch (SQLException e) { rollbackQuietly(cnn); String msg = "Exception deleting user '" + username + "': " + e; logger.warn(msg, e); throw new RuntimeException(msg); } finally { closeQuietly(cnn, stmt); } }
From source file:com.github.veqryn.collect.TestPatriciaTrieWithApacheCommonsCollections.java
private static <K, V> K getLastKey(final Map<K, V> map) { // Temporary implementation until we support SortedMap K key = null;/*from w w w . ja va 2 s. c o m*/ for (final K k : map.keySet()) { key = k; } if (key != null) { return key; } throw new NoSuchElementException("Empty Map"); }
From source file:mvm.rya.indexing.external.tupleSet.AccumuloIndexSet.java
private String prefixToOrder(String order) { Map<String, String> invMap = HashBiMap.create(this.getTableVarMap()).inverse(); String[] temp = order.split("\u0000"); for (int i = 0; i < temp.length; i++) { temp[i] = this.getTableVarMap().get(temp[i]); }/*from w ww .j a va2 s.co m*/ order = Joiner.on("\u0000").join(temp); for (String s : varOrder) { if (s.startsWith(order)) { temp = s.split("\u0000"); for (int i = 0; i < temp.length; i++) { temp[i] = invMap.get(temp[i]); } return Joiner.on("\u0000").join(temp); } } throw new NoSuchElementException("Order is not a prefix of any locality group value!"); }
From source file:dk.netarkivet.harvester.scheduler.jobgen.FixedDomainConfigurationCountJobGenerator.java
private synchronized void dropStateForHarvest(final HarvestDefinition harvest) { long harvestId = harvest.getOid(); HarvestJobGenerationState harvestState = this.state.remove(harvestId); if (harvestState == null) { throw new NoSuchElementException("No job generation state for harvest " + harvestId); }//www. j a v a2 s .c o m }
From source file:dk.statsbiblioteket.doms.integration.summa.DOMSReadableStorage.java
public List<Record> next(long iteratorKey, int maxRecords) throws IOException, IllegalArgumentException, NoSuchElementException { if (log.isTraceEnabled()) { log.trace("next(long, int): Called with iteratorKey = " + iteratorKey + " maxRecords = " + maxRecords); }/*from w ww . ja v a 2 s. c o m*/ try { final SummaRecordIterator recordIterator = recordIterators.get(iteratorKey); if (recordIterator.hasNext() == false) { // The iterator has reached the end and thus it is obsolete. Let // the wolves have it... recordIterators.remove(iteratorKey); final String errorMessage = "The iterator is out of records " + "(iterator key = " + iteratorKey + ")"; log.warn("next(long, int): " + errorMessage); throw new NoSuchElementException(errorMessage); } final List<Record> resultList = new LinkedList<Record>(); int recordCounter = 0; int size = 0; while (recordIterator.hasNext() && recordCounter < maxRecords && size < baseConfigurations .get(recordIterator.getCurrentBaseRecordDescription().getSummaBaseID()) .getMaxSizePerRetrieval()) { Record record = recordIterator.next(); resultList.add(record); recordCounter++; size += record.getContent().length; if (log.isTraceEnabled()) { log.trace("Size: " + size + ", maxSize: " + baseConfigurations .get(recordIterator.getCurrentBaseRecordDescription().getSummaBaseID()) .getMaxSizePerRetrieval()); } } if (log.isDebugEnabled()) { log.debug("next(long, int): Returning " + resultList.size() + " records."); } return resultList; } catch (UnknownKeyException unknownKeyException) { // The iterator key is unknown to the registry. It may be because it // has expired. final String errorMessage = "Unknown iterator (iterator key = " + iteratorKey + "). Failed retrieving up to " + maxRecords + " records. Has the key expired?"; log.warn("next(long, int): " + errorMessage); throw new IllegalArgumentException(errorMessage, unknownKeyException); } catch (DOMSCommunicationError domsCommunicationError) { // Translate communication/server errors to IOExceptions! final String errorMessage = "next() operation on this iterator " + "(iterator key = " + iteratorKey + ") failed due to a " + "server or communication error. Failed retrieving up to " + maxRecords + " records."; log.warn("next(long, int): " + errorMessage); throw new IOException(errorMessage, domsCommunicationError); } }
From source file:de.mpg.escidoc.pubman.multipleimport.processor.ZfNProcessor.java
public String next() throws NoSuchElementException { if (!init) {/* w w w. j a va 2 s . com*/ initialize(); } if (this.items != null && this.counter < this.items.length) { this.counter++; return items[counter - 1]; } else { throw new NoSuchElementException("No more entries left"); } }
From source file:org.zenoss.app.consumer.metric.impl.OpenTsdbWriter.java
private OpenTsdbClient getOpenTsdbClient() throws InterruptedException { OpenTsdbClient client = null;// w w w.j a va 2 s .c o m try { client = (OpenTsdbClient) clientPool.borrowObject(); if (null == client) { log.warn("got null client from pool."); } else { log.debug(String.format("Got client from pool. isAlive = %s. isClosed = %s", String.valueOf(client.isAlive()), String.valueOf(client.isClosed()))); } return client; } catch (InterruptedException | NoSuchElementException e) { if (client != null) { try { clientPool.invalidateObject(client); } catch (Exception releaseException) { log.warn("Error while releasing TSDB client", releaseException); } } log.warn("Caught exception getting OpenTsdbClient - rethrowing.", e); // don't swallow These exceptions throw e; } catch (Exception e) { // Exception required due to GenericObjectPool.borrowObject log.warn("Caught exception getting OpenTsdbClient - wrapping and rethrowing.", e); if (client != null) { try { clientPool.invalidateObject(client); } catch (Exception releaseException) { log.warn("Error while releasing TSDB client", releaseException); } } throw new NoSuchElementException(e.toString()); } }
From source file:chat.viska.commons.pipelines.Pipeline.java
public void addTowardsOutboundEnd(final String next, final String name, final Pipe pipe) { Validate.notBlank(next);/* ww w. j ava 2s . co m*/ Completable.fromAction(() -> { pipeLock.writeLock().lockInterruptibly(); try { if (getIteratorOf(name) != null) { throw new IllegalArgumentException("Name collision: " + name); } ListIterator<Map.Entry<String, Pipe>> iterator = getIteratorOf(next); if (iterator == null) { throw new NoSuchElementException(next); } iterator.add(new AbstractMap.SimpleImmutableEntry<>(name, pipe)); pipe.onAddedToPipeline(this); } finally { pipeLock.writeLock().unlock(); } }).onErrorComplete().subscribeOn(Schedulers.io()).subscribe(); }
From source file:de.codesourcery.jasm16.ide.AssemblyProject.java
@Override public IResource lookupResource(String identifier) { for (IResource r : getAllResources()) { if (r.getIdentifier().equals(identifier)) { return r; }/*from ww w . j av a 2s . com*/ } throw new NoSuchElementException("Unable to find resource '" + identifier + " in project " + this); }
From source file:com.devicehive.service.UserService.java
/** * Revokes user access to given network/*ww w . j a v a2 s. c om*/ * * @param userId id of user * @param networkId id of network */ @Transactional(propagation = Propagation.REQUIRED) public void unassignNetwork(@NotNull long userId, @NotNull long networkId) { UserVO existingUser = userDao.find(userId); if (existingUser == null) { logger.error("Can't unassign network with id {}: user {} not found", networkId, userId); throw new NoSuchElementException(Messages.USER_NOT_FOUND); } userDao.unassignNetwork(existingUser, networkId); }