List of usage examples for java.util NoSuchElementException NoSuchElementException
public NoSuchElementException(String s)
From source file:com.largecode.interview.rustem.service.UsersServiceImpl.java
@Override public void deleteUser(Long id) { LOGGER.debug("Delete user by id ={}", id); Optional<User> userInDb = Optional.ofNullable(userRepository.findOne(id)); userInDb.ifPresent((user) -> {//www. j av a 2 s . com userRepository.delete(user); }); userInDb.orElseThrow( () -> new NoSuchElementException(String.format("User=%s not found for deleting.", id))); }
From source file:de.iew.raspimotion.controllers.MotionJpegController.java
@RequestMapping(value = "stream/{imagename:.+}") public void streamAction(HttpServletResponse response, @PathVariable String imagename) throws Exception { Assert.isTrue(validateImagename(imagename)); OutputStream out = response.getOutputStream(); try {// ww w. ja v a 2 s .c om FileDescriptor file = this.fileDao.getFileLastCreated(imagename); if (file == null) { throw new NoSuchElementException("Image was not found"); } sendCachingHeaders(response); response.setStatus(HttpServletResponse.SC_OK); response.setContentType("multipart/x-mixed-replace;boundary=BOUNDARY"); writeFrameBoundary(out); writeFrame(out, file); long processingTime; long startTs; double fpsTime = 1000 / this.fps; long sleepTime; while (true) { startTs = System.currentTimeMillis(); file = this.fileDao.getFileLastCreated(imagename); writeFrame(out, file); processingTime = System.currentTimeMillis() - startTs; if (log.isDebugEnabled()) { log.debug("Zeitdauer fr gesamten Vorgang: " + processingTime); } sleepTime = (long) (fpsTime - processingTime); if (log.isDebugEnabled()) { log.debug("Schlafe " + sleepTime); } if (sleepTime > 0) { Thread.sleep(sleepTime); } } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Motion JPEG handling aborted", e); } try { out.flush(); out.close(); } catch (Exception ex) { if (log.isDebugEnabled()) { log.debug("Closing failed", ex); } } } }
From source file:com.kolich.common.util.io.JumpToLine.java
/** * Seeks to a given line number in the stream/file. * @param line the line number to seek to */// w w w . ja v a 2 s . co m public long seek(final long line) { long lineCount = 1L; while ((it_ != null) && (it_.hasNext()) && (lineCount < line)) { it_.nextLine(); lineCount += 1L; } // If we got to the end of the file, but haven't read as many // lines as we should have, then the requested line number is // out of range. if (lineCount < line) { throw new NoSuchElementException("Invalid line number; " + "out of range."); } lastLineRead_ = lineCount; return lineCount; }
From source file:com.graphhopper.apache.commons.collections.IntDoubleBinaryHeap.java
public float peek_key() { if (isEmpty()) throw new NoSuchElementException("Heap is empty. Cannot peek key."); else/*from w ww . ja v a 2s .com*/ return keys[1]; }
From source file:org.openregistry.core.service.DefaultActivationService.java
@Transactional public void invalidateActivationKey(final Person person, final String activationKey, final String lock) throws PersonNotFoundException, IllegalArgumentException, IllegalStateException { Assert.notNull(person, "person cannot be null."); Assert.notNull(activationKey, "activationKey cannot be null."); Assert.notNull(lock, "lock cannot be null."); final ActivationKey currentKey = person.getCurrentActivationKey(); if (currentKey == null || !currentKey.asString().equals(activationKey)) { throw new NoSuchElementException( "No Activation Key matching [" + activationKey + "] found for that Person."); }// w w w .j a va 2 s . com if (!currentKey.isValid()) { throw new IllegalStateException( "No valid activationKey found for activation key matching [" + activationKey + "]"); } if (currentKey.hasLock(lock)) { person.removeCurrentActivationKey(); this.personRepository.savePerson(person); } else { throw new LockingException("You do not hold the lock for this key."); } }
From source file:com.liferay.faces.generator.Generator.java
private void addExtensionAttributes(Tag tag, Map<String, Tag> tagMap, Document document) { List<String> extendsTagsNames = tag.getExtendsTags(); for (String extendedTagName : extendsTagsNames) { Tag extendedTag = tagMap.get(extendedTagName); if ((extendedTag == null) && extendedTagName.endsWith("Inherited")) { int extendedTagNameLength = extendedTagName.length(); int inheritedLength = "Inherited".length(); String inheritedExtendedTagName = extendedTagName.substring(0, extendedTagNameLength - inheritedLength); extendedTag = tagMap.get(inheritedExtendedTagName); }/*from www .ja v a 2 s . c o m*/ if (extendedTag == null) { String tagName = tag.getTagName(); throw new NoSuchElementException(tagName + " extends non-existent tag " + extendedTagName); } addExtensionAttributes(extendedTag, tagMap, document); tag.addExtendedComponentAttributes(extendedTag, document, extendedTagName.endsWith("Inherited")); } }
From source file:com.aba.industry.fetch.client.impl.StaticDataExportBlueprintYamlService.java
@Override public BlueprintData getBlueprintData(final Integer typeId) { BlueprintData result = new BlueprintData(); Blueprint productionBp = null;/*from ww w .j ava 2s . com*/ Blueprint inventionBp = null; //<editor-fold desc="Production BP Lambda"> Optional<Map.Entry<Long, Blueprint>> possibleMatch = blueprints.getBlueprints().entrySet().stream() .filter(entry -> { if (entry.getValue().getActivities().containsKey(BlueprintActivities.manufacturing) && entry.getValue().getActivities().get(BlueprintActivities.manufacturing) .getProducts() != null) { return entry.getValue().getActivities().get(BlueprintActivities.manufacturing).getProducts() .stream().filter(products -> products.getTypeID().equals(typeId)).findFirst() .isPresent(); } return false; }).findFirst(); //</editor-fold> if (!possibleMatch.isPresent()) { throw new NoSuchElementException("Type with type id: " + typeId + " has no blueprint."); } else { productionBp = possibleMatch.get().getValue(); } final int manuBpTypeId = productionBp.getBlueprintTypeID(); //<editor-fold desc="Possible base bp lambda"> possibleMatch = blueprints.getBlueprints().entrySet().stream().filter(entry -> { if (entry.getValue().getActivities().containsKey(BlueprintActivities.invention) && entry.getValue().getActivities().get(BlueprintActivities.invention).getProducts() != null) { return entry.getValue().getActivities().get(BlueprintActivities.invention).getProducts().stream() .filter(products -> products.getTypeID().equals(manuBpTypeId)).findFirst().isPresent(); } return false; }).findFirst(); //</editor-fold> if (possibleMatch.isPresent()) { inventionBp = possibleMatch.get().getValue(); } result.setRequestedId(typeId); result.setBlueprintSkills(new HashMap<>()); //<editor-fold desc="BlueprintDetails buildup"> BlueprintDetails bpDetails = new BlueprintDetails(); bpDetails.setMaxProductionLimit(productionBp.getMaxProductionLimit()); bpDetails.setProductTypeId(productionBp.getActivities().get(BlueprintActivities.manufacturing).getProducts() .get(0).getTypeID()); bpDetails.setProductQuantity(productionBp.getActivities().get(BlueprintActivities.manufacturing) .getProducts().get(0).getQuantity()); //<editor-fold desc="Times"> bpDetails.setTimesInSeconds(new HashMap<>()); bpDetails.getTimesInSeconds().put(BlueprintActivities.copying.getIndustryActivity().getActivityId(), productionBp.getActivities().get(BlueprintActivities.copying).getTime()); bpDetails.getTimesInSeconds().put( BlueprintActivities.research_material.getIndustryActivity().getActivityId(), productionBp.getActivities().get(BlueprintActivities.research_material).getTime()); bpDetails.getTimesInSeconds().put(BlueprintActivities.research_time.getIndustryActivity().getActivityId(), productionBp.getActivities().get(BlueprintActivities.research_time).getTime()); bpDetails.getTimesInSeconds().put(BlueprintActivities.manufacturing.getIndustryActivity().getActivityId(), productionBp.getActivities().get(BlueprintActivities.manufacturing).getTime()); //</editor-fold> if (inventionBp != null) { bpDetails.getTimesInSeconds().put(BlueprintActivities.invention.getIndustryActivity().getActivityId(), inventionBp.getActivities().get(BlueprintActivities.invention).getTime()); bpDetails.setTechLevel(TechLevel.ADVANCED.getNumerical()); bpDetails.setPrecursorTypeId(inventionBp.getActivities().get(BlueprintActivities.manufacturing) .getProducts().get(0).getTypeID()); bpDetails.setBaseProbability(inventionBp.getActivities().get(BlueprintActivities.invention) .getProducts().get(0).getProbability()); } else { bpDetails.setTechLevel(TechLevel.TECH_ONE.getNumerical()); } result.setBlueprintDetails(bpDetails); //</editor-fold> //<editor-fold desc="Blueprint Skills buildup"> //TODO: Build up the skills in a later release //</editor-fold> //<editor-fold desc="ActivityMaterialsWithCost buildup"> result.setActivityMaterials(new HashMap<>()); result.getActivityMaterials().put(BlueprintActivities.manufacturing.getIndustryActivity().getActivityId(), new ArrayList<>()); for (BlueprintMaterial bpMaterial : productionBp.getActivities().get(BlueprintActivities.manufacturing) .getMaterials()) { ActivityMaterialWithCost activityMaterialWithCost = new ActivityMaterialWithCost(); //TODO: Set the materials blueprint type id in a later release // activityMaterialWithCost.setBlueprintTypeId( ); //TODO: Set the activity material name in a later release // activityMaterialWithCost.setName( ); activityMaterialWithCost.setQuantity(bpMaterial.getQuantity()); activityMaterialWithCost.setTypeId(bpMaterial.getTypeID()); result.getActivityMaterials() .get(BlueprintActivities.manufacturing.getIndustryActivity().getActivityId()) .add(activityMaterialWithCost); } if (inventionBp != null) { result.getActivityMaterials().put(BlueprintActivities.invention.getIndustryActivity().getActivityId(), new ArrayList<>()); for (BlueprintMaterial bpMaterial : inventionBp.getActivities().get(BlueprintActivities.invention) .getMaterials()) { ActivityMaterialWithCost activityMaterialWithCost = new ActivityMaterialWithCost(); //TODO: Set the materials blueprint type id in a later release // activityMaterialWithCost.setBlueprintTypeId( ); //TODO: Set the activity material name in a later release // activityMaterialWithCost.setName( ); activityMaterialWithCost.setQuantity(bpMaterial.getQuantity()); activityMaterialWithCost.setTypeId(bpMaterial.getTypeID()); result.getActivityMaterials() .get(BlueprintActivities.invention.getIndustryActivity().getActivityId()) .add(activityMaterialWithCost); } } //</editor-fold> try { result.setDecryptors(this.getDecryptors()); } catch (IOException e) { //TODO: Handle decryptors not deserializing properly in a later release //This is a bit annoying, but I'm ignoring it for now. } return result; }
From source file:com.msopentech.odatajclient.engine.communication.request.batch.ODataBatchResponseManager.java
/** * {@inheritDoc }//from w w w.j a v a 2s . co m */ @Override public ODataBatchResponseItem next() { if (current != null) { current.close(); } if (!hasNext()) { throw new NoSuchElementException("No item found"); } current = expectedItemsIterator.next(); final Map<String, Collection<String>> nextItemHeaders = ODataBatchUtilities .nextItemHeaders(batchLineIterator, batchBoundary); switch (ODataBatchUtilities.getItemType(nextItemHeaders)) { case CHANGESET: if (!current.isChangeset()) { throw new IllegalStateException("Unexpected batch item"); } current.initFromBatch(batchLineIterator, ODataBatchUtilities .getBoundaryFromHeader(nextItemHeaders.get(ODataHeaders.HeaderName.contentType.toString()))); break; case RETRIEVE: if (current.isChangeset()) { throw new IllegalStateException("Unexpected batch item"); } current.initFromBatch(batchLineIterator, batchBoundary); break; default: throw new IllegalStateException("Expected item not found"); } return current; }
From source file:com.kurento.kmf.repository.internal.repoimpl.filesystem.FileSystemRepository.java
@Override public RepositoryItem findRepositoryItemById(String id) { File file = getFileForId(id); if (!file.exists()) { throw new NoSuchElementException("The repository item with id \"" + id + "\" does not exist"); }/*from w w w . j av a2s . c om*/ return new FileRepositoryItem(this, file, id, metadata.loadMetadata(id)); }
From source file:net.darkmist.alib.io.LineIterator.java
/** {@link java.util.Iterator#next()} implementation. * @return Next line of the source stream. * @throws NoSuchElementException in the case of a end of file or a {@link java.io.IOException} * by the underlying {@link java.io.InputStream InputStream}. In the latter case the exception can * be retrieved via {@link #getIOException()}. *///from www. j av a 2 s . c o m @Override public String next() throws NoSuchElementException { String ret; if (previousException != null) throw new NoSuchElementException("Previous IOException reading from stream"); if (line == null) { try { if ((line = in.readLine()) == null) throw new NoSuchElementException("No more lines available"); } catch (IOException e) { previousException = e; throw new NoSuchElementException("IOException reading next line."); } } ret = line; line = null; return ret; }