List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException(String s)
From source file:de.codesourcery.jasm16.compiler.CompilationUnit.java
@Override public Line getLineForOffset(int offset) throws NoSuchElementException { if (offset < 0) { throw new IllegalArgumentException("offset must not be negative"); }/*from w ww.j a va 2 s . co m*/ Line previousLine = null; for (Iterator<Line> it = lines.values().iterator(); it.hasNext();) { final Line l = it.next(); if (l.getLineStartingOffset() == offset) { return l; } if (previousLine != null && previousLine.getLineStartingOffset() < offset && l.getLineStartingOffset() > offset) { return previousLine; } previousLine = l; } if (previousLine != null && previousLine.getLineStartingOffset() <= offset) { return previousLine; } throw new NoSuchElementException("Found no line with offset " + offset); }
From source file:com.xpn.xwiki.internal.plugin.rightsmanager.UserIterator.java
@Override public T next() { T currentValue = this.lookaheadValue; if (currentValue != null) { this.lookaheadValue = null; } else {// w w w . ja v a 2 s . com currentValue = getNext(); if (currentValue == null) { throw new NoSuchElementException( String.format("No more users to extract from the passed references [%s]", serializeUserAndGroupReferences())); } } return currentValue; }
From source file:org.dcache.chimera.FsSqlDriver.java
/** * the same as listDir, but array of {@HimeraDirectoryEntry} is returned, which contains * file attributes as well.//w w w . jav a 2 s. c om * * @param dir * @return */ DirectoryStreamB<HimeraDirectoryEntry> newDirectoryStream(FsInode dir) { return new DirectoryStreamB<HimeraDirectoryEntry>() { final DirectoryStreamImpl stream = new DirectoryStreamImpl(dir, _jdbc); @Override public Iterator<HimeraDirectoryEntry> iterator() { return new Iterator<HimeraDirectoryEntry>() { private HimeraDirectoryEntry current = innerNext(); @Override public boolean hasNext() { return current != null; } @Override public HimeraDirectoryEntry next() { if (current == null) { throw new NoSuchElementException("No more entries"); } HimeraDirectoryEntry entry = current; current = innerNext(); return entry; } protected HimeraDirectoryEntry innerNext() { try { ResultSet rs = stream.next(); if (rs == null) { return null; } Stat stat = toStat(rs); FsInode inode = new FsInode(dir.getFs(), rs.getLong("inumber"), FsInodeType.INODE, 0, stat); inode.setParent(dir); return new HimeraDirectoryEntry(rs.getString("iname"), inode, stat); } catch (SQLException e) { _log.error("failed to fetch next entry: {}", e.getMessage()); return null; } } }; } @Override public void close() throws IOException { stream.close(); } }; }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private void serveRequest(RequestMethod method, HttpServletRequest req, HttpServletResponse rsp) throws IOException, ServletException { if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]"); }//from ww w . java 2 s . co m if ((loopRetryTimeout > 0L) && (!loopDetected)) { long now = System.currentTimeMillis(), diff = now - initTimestamp; if ((diff > 0L) && (diff < loopRetryTimeout)) { try { MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(new ObjectName( "net.community.chest.gitcloud.facade.backend.git:name=BackendRepositoryResolver")); if (mbeanInfo != null) { logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " detected loop: " + mbeanInfo.getClassName() + "[" + mbeanInfo.getDescription() + "]"); loopDetected = true; } } catch (JMException e) { if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " failed " + e.getClass().getSimpleName() + " to detect loop: " + e.getMessage()); } } } } ResolvedRepositoryData repoData = resolveTargetRepository(method, req); if (repoData == null) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]", new NoSuchElementException("Failed to resolve repository")); } String username = authenticate(req); // TODO check if the user is allowed to access the repository via the resolve operation (push/pull) if at all (e.g., private repo) logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "] user=" + username); /* * NOTE: this feature requires enabling cross-context forwarding. * In Tomcat, the 'crossContext' attribute in 'Context' element of * 'TOMCAT_HOME\conf\context.xml' must be set to true, to enable cross-context */ if (loopDetected) { // TODO see if can find a more efficient way than splitting and re-constructing URI uri = repoData.getRepoLocation(); ServletContext curContext = req.getServletContext(); String urlPath = uri.getPath(), urlQuery = uri.getQuery(); String[] comps = StringUtils.split(urlPath, '/'); String appName = comps[0]; ServletContext loopContext = Validate.notNull(curContext.getContext("/" + appName), "No cross-context for %s", appName); // build the relative path in the re-directed context StringBuilder sb = new StringBuilder( urlPath.length() + 1 + (StringUtils.isEmpty(urlQuery) ? 0 : urlQuery.length())); for (int index = 1; index < comps.length; index++) { sb.append('/').append(comps[index]); } if (!StringUtils.isEmpty(urlQuery)) { sb.append('?').append(urlQuery); } String redirectPath = sb.toString(); RequestDispatcher dispatcher = Validate.notNull(loopContext.getRequestDispatcher(redirectPath), "No dispatcher for %s", redirectPath); dispatcher.forward(req, rsp); if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " forwarded to " + loopContext.getContextPath() + "/" + redirectPath); } } else { executeRemoteRequest(method, repoData.getRepoLocation(), req, rsp); } }
From source file:chat.viska.commons.pipelines.Pipeline.java
public void addTowardsInboundEnd(final String previous, final String name, final Pipe pipe) { Validate.notBlank(previous);/*from w w w.j a va 2 s . c o m*/ Completable.fromAction(() -> { pipeLock.writeLock().lockInterruptibly(); try { if (getIteratorOf(name) != null) { throw new IllegalArgumentException("Name collision: " + name); } ListIterator<Map.Entry<String, Pipe>> iterator = getIteratorOf(previous); if (iterator == null) { throw new NoSuchElementException(previous); } iterator.next(); iterator.add(new AbstractMap.SimpleImmutableEntry<>(name, pipe)); pipe.onAddedToPipeline(this); } finally { pipeLock.writeLock().unlock(); } }).onErrorComplete().subscribeOn(Schedulers.io()).subscribe(); }
From source file:dk.netarkivet.harvester.scheduler.jobgen.FixedDomainConfigurationCountJobGenerator.java
private synchronized HarvestJobGenerationState getStateForHarvest(final HarvestDefinition harvest, final boolean failIfNotExists) { long harvestId = harvest.getOid(); HarvestJobGenerationState harvestState = this.state.get(harvestId); if (harvestState == null) { if (failIfNotExists) { throw new NoSuchElementException("No job generation state for harvest " + harvestId); }/*from w w w. j a v a2s. c om*/ harvestState = new HarvestJobGenerationState(); this.state.put(harvestId, harvestState); } return harvestState; }
From source file:com.continuent.tungsten.common.security.KeystoreManagerCtrl.java
/** * Reads user input from stdin//from www . j a v a2 s . c o m * * @param listPrompts list of prompts to display, asking for user input * @return a list containing user inputs */ private List<String> getUserInputFromStdin(List<String> listPrompts) { List<String> listUserInput = new ArrayList<String>(); Scanner console = new Scanner(System.in); Scanner lineTokenizer = null; for (String prompt : listPrompts) { System.out.println(prompt); try { lineTokenizer = new Scanner(console.nextLine()); } catch (NoSuchElementException nse) { console.close(); throw new NoSuchElementException(MessageFormat.format("Missing user input= {0}", prompt)); } if (lineTokenizer.hasNext()) { String userInput = lineTokenizer.next(); listUserInput.add(userInput); } } console.close(); return listUserInput; }
From source file:com.eucalyptus.entities.EntityWrapper.java
@SuppressWarnings("unchecked") public <T> T getUnique(final T example) throws EucalyptusCloudException { try {//from ww w . j a v a 2 s . c o m Object id = null; try { id = this.getEntityManager().getEntityManagerFactory().getPersistenceUnitUtil() .getIdentifier(example); } catch (final Exception ex) { } if (id != null) { final T res = (T) this.getEntityManager().find(example.getClass(), id); if (res == null) { throw new NoSuchElementException("@Id: " + id); } else { return res; } } else if ((example instanceof HasNaturalId) && (((HasNaturalId) example).getNaturalId() != null)) { final String natId = ((HasNaturalId) example).getNaturalId(); final T ret = (T) this.createCriteria(example.getClass()).setLockMode(LockMode.NONE) .setCacheable(true).setMaxResults(1).setFetchSize(1).setFirstResult(0) .add(Restrictions.naturalId().set("naturalId", natId)).uniqueResult(); if (ret == null) { throw new NoSuchElementException("@NaturalId: " + natId); } return ret; } else { final T ret = (T) this.createCriteria(example.getClass()).setLockMode(LockMode.NONE) .setCacheable(true).setMaxResults(1).setFetchSize(1).setFirstResult(0) .add(Example.create(example).enableLike(MatchMode.EXACT)).uniqueResult(); if (ret == null) { throw new NoSuchElementException("example: " + LogUtil.dumpObject(example)); } return ret; } } catch (final NonUniqueResultException ex) { throw new EucalyptusCloudException( "Get unique failed for " + example.getClass().getSimpleName() + " because " + ex.getMessage(), ex); } catch (final NoSuchElementException ex) { throw new EucalyptusCloudException( "Get unique failed for " + example.getClass().getSimpleName() + " using " + ex.getMessage(), ex); } catch (final Exception ex) { final Exception newEx = PersistenceExceptions.throwFiltered(ex); throw new EucalyptusCloudException("Get unique failed for " + example.getClass().getSimpleName() + " because " + newEx.getMessage(), newEx); } }
From source file:eu.crisis_economics.configuration.FromFileConfigurationContext.java
public DoublePrimitiveExpression hasPrimitiveDoubleValueExpression(String literalName) { if (!knownDoublePrimitiveDefinitions.containsKey(literalName)) throw new NoSuchElementException( "'" + literalName + "' does not have a primitive" + "double definition."); return knownDoublePrimitiveDefinitions.get(literalName); }
From source file:com.devicehive.service.UserService.java
/** * Allows user access to given network/*from www.ja va2s. co m*/ * * @param userId id of user * @param networkId id of network */ @Transactional(propagation = Propagation.REQUIRED) public void assignNetwork(@NotNull long userId, @NotNull long networkId) { UserVO existingUser = userDao.find(userId); if (existingUser == null) { logger.error("Can't assign network with id {}: user {} not found", networkId, userId); throw new NoSuchElementException(Messages.USER_NOT_FOUND); } NetworkWithUsersAndDevicesVO existingNetwork = networkDao.findWithUsers(networkId).orElseThrow( () -> new NoSuchElementException(String.format(Messages.NETWORK_NOT_FOUND, networkId))); networkDao.assignToNetwork(existingNetwork, existingUser); }