List of usage examples for java.util ListIterator next
E next();
From source file:org.powertac.officecomplexcustomer.persons.Person.java
/** * This function fills out the vector containing the days that the person is * going to be sick. When a person is sick he stays in bed. * // w w w . ja va2s.com * @param mean * @param dev * @param gen * @return */ Vector<Integer> createSicknessVector(double mean, double dev) { // Create auxiliary variables int days = (int) (dev * gen.nextGaussian() + mean); Vector<Integer> v = new Vector<Integer>(days); for (int i = 0; i < days; i++) { int x = gen.nextInt( OfficeComplexConstants.DAYS_OF_COMPETITION + OfficeComplexConstants.DAYS_OF_BOOTSTRAP) + 1; ListIterator<Integer> iter = v.listIterator(); while (iter.hasNext()) { int temp = (int) iter.next(); if (x == temp) { x = x + 1; iter = v.listIterator(); } } v.add(x); } java.util.Collections.sort(v); return v; }
From source file:eu.dime.ps.storage.datastore.impl.DataStoreImpl.java
@Override public void deleteAll() { ListIterator<PersistentDimeObject> listIt = getAll(); while (listIt.hasNext()) { PersistentDimeObject persistentDimeObject = (PersistentDimeObject) listIt.next(); delete(persistentDimeObject);/* w w w. ja va 2 s .co m*/ } }
From source file:edu.harvard.mcz.imagecapture.ConfiguredBarcodePositionTemplateDetector.java
protected String detectTemplateForImage(File anImageFile, CandidateImageFile scannableFile, boolean quickCheck) throws UnreadableFileException { // Set default response if no template is found. String result = PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS; // Read the image file, if possible, otherwise throw exception. if (!anImageFile.canRead()) { throw new UnreadableFileException("Unable to read " + anImageFile.getName()); }//from w w w .java 2 s . co m BufferedImage image = null; try { image = ImageIO.read(anImageFile); } catch (IOException e) { throw new UnreadableFileException("IOException trying to read " + anImageFile.getName()); } // iterate through templates and check until the first template where a barcode is found List<String> templates = PositionTemplate.getTemplateIds(); ListIterator<String> i = templates.listIterator(); boolean found = false; while (i.hasNext() && !found) { try { // get the next template from the list PositionTemplate template = new PositionTemplate((String) i.next()); log.debug("Testing template: " + template.getTemplateId()); if (template.getTemplateId().equals(PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS)) { // skip, this is the default result if no other is found. } else { if (image.getWidth() == template.getImageSize().getWidth()) { // Check to see if the barcode is in the part of the template // defined by getBarcodeULPosition and getBarcodeSize. String text; if (scannableFile == null) { text = CandidateImageFile.getBarcodeTextFromImage(image, template, quickCheck); } else { text = scannableFile.getBarcodeText(template); } log.debug("Found:[" + text + "] "); if (text.length() > 0) { // a barcode was scanned // Check to see if it matches the expected pattern. // Use the configured barcode matcher. if (Singleton.getSingletonInstance().getBarcodeMatcher().matchesPattern(text)) { found = true; log.debug("Match to:" + template.getTemplateId()); result = template.getTemplateId(); } } } else { log.debug("Skipping as template " + template.getTemplateId() + " is not same size as image. "); } } } catch (NoSuchTemplateException e) { // Ending up here means a serious error in PositionTemplate // as the list of position templates returned by getTemplates() includes // an entry that isn't recognized as a valid template. log.fatal( "Fatal error. PositionTemplate.getTemplates() includes an item that isn't a valid template."); log.trace(e); ImageCaptureApp.exit(ImageCaptureApp.EXIT_ERROR); } } return result; }
From source file:name.livitski.tools.springlet.Launcher.java
/** * Configures the manager using command-line arguments. * The arguments are checked in their command line sequence. * If an argument begins with {@link Command#COMMAND_PREFIX}, * its part that follows it is treated as a (long) command's name. * If an argument begins with {@link Command#SWITCH_PREFIX}, * the following character(s) are treated as a switch. * The name or switch extracted this way, prepended with * a bean name prefix for a {@link #BEAN_NAME_PREFIX_COMMAND command} * or a {@link #BEAN_NAME_PREFIX_SWITCH switch}, becomes the name * of a bean to look up in the framework's * {@link #MAIN_BEAN_CONFIG_FILE configuration file(s)}. * The bean that handles a command must extend the * {@link Command} class. Once a suitable bean is found, * it is called to act upon the command or switch and process * any additional arguments associated with it. * If no bean can be found or the argument is not prefixed * properly, it is considered unclaimed. You may configure a * special subclass of {@link Command} to process such arguments * by placing a bean named {@link #BEAN_NAME_DEFAULT_HANDLER} on * the configuration. If there is no such bean configured, or when * any {@link Command} bean throws an exception while processing * a command, a command line error is reported and the application * quits.// www . ja v a2 s . co m * @param args the command line * @return this manager object */ public Launcher withArguments(String[] args) { configureDefaultLogging(); final Log log = log(); ListIterator<String> iargs = Arrays.asList(args).listIterator(); while (iargs.hasNext()) { String arg = iargs.next(); String prefix = null; String beanPrefix = null; Command cmd = null; if (arg.startsWith(Command.COMMAND_PREFIX)) prefix = Command.COMMAND_PREFIX; else if (arg.startsWith(Command.SWITCH_PREFIX)) prefix = Command.SWITCH_PREFIX; if (null != prefix) { arg = arg.substring(prefix.length()); beanPrefix = Command.SWITCH_PREFIX == prefix ? BEAN_NAME_PREFIX_SWITCH : BEAN_NAME_PREFIX_COMMAND; try { cmd = getBeanFactory().getBean(beanPrefix + arg, Command.class); } catch (NoSuchBeanDefinitionException noBean) { log.debug("Could not find a handler for command-line argument " + prefix + arg, noBean); } } if (null == cmd) { iargs.previous(); try { cmd = getBeanFactory().getBean(BEAN_NAME_DEFAULT_HANDLER, Command.class); } catch (RuntimeException ex) { log.error("Unknown command line argument: " + (null != prefix ? prefix : "") + arg, ex); status = STATUS_COMMAND_PARSING_FAILURE; break; } } try { cmd.process(iargs); } catch (SkipApplicationRunRequest skip) { if (log.isTraceEnabled()) log.trace("Handler for argument " + (null != prefix ? prefix : "") + arg + " requested to skip the application run", skip); status = STATUS_RUN_SKIPPED; break; } catch (RuntimeException err) { log.error("Invalid command line argument(s) near " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); status = STATUS_COMMAND_PARSING_FAILURE; break; } catch (ApplicationBeanException err) { log.error("Error processing command line argument " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); try { err.updateBeanStatus(); } catch (RuntimeException noStatus) { final ApplicationBean appBean = err.getApplicationBean(); log.warn("Could not obtain status code" + (null != appBean ? " from " + appBean : ""), noStatus); status = STATUS_INTERNAL_ERROR; } break; } } return this; }
From source file:org.socraticgrid.codeconversion.matchers.MapMatch.java
/** * Initialize the map from the inputstream. * * @param is/*www . j a v a 2s . co m*/ * * @throws InitializationException */ protected void load(InputStream is) throws InitializationException { try { JAXBContext jaxbContext = JAXBContext .newInstance(org.socraticgrid.codeconversion.matchers.xml.ObjectFactory.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); org.socraticgrid.codeconversion.matchers.xml.MapMatch xmlMap = (org.socraticgrid.codeconversion.matchers.xml.MapMatch) jaxbUnmarshaller .unmarshal(is); Iterator<TargetSystem> itr = xmlMap.getTargetSystem().iterator(); while (itr.hasNext()) { TargetSystem ts = itr.next(); // Update contract.addTargetSystem(ts.getTargetSystemCode()); TargetSystemCodeMap tsm = new TargetSystemCodeMap(); tsMap.put(ts.getTargetSystemCode(), tsm); ListIterator<SourceCoding> sItr = ts.getSourceCoding().listIterator(); while (sItr.hasNext()) { SourceCoding sc = sItr.next(); CodeReference cd = new CodeReference(ts.getTargetSystemCode(), sc.getTargetCode(), sc.getTargetName()); SearchMapping sm = new SearchMapping(sc.getSystem(), sc.getCode()); tsm.SrchMap.put(sm, cd); } } } catch (JAXBException exp) { throw new InitializationException("MapMap, Error parsing code map", exp); } }
From source file:com.platum.restflow.RestflowModel.java
/** * // ww w .j av a 2s . c o m * @param name * @return */ public RestflowModel removeResource(String name) { if (resources != null) { ListIterator<Resource> iterator = resources.listIterator(); while (iterator.hasNext()) { if (iterator.next().getName().equals(name)) { iterator.remove(); return this; } } } throw new RestflowNotExistsException("Resource does not exists."); }
From source file:com.qualogy.qafe.presentation.EventHandlerImpl.java
private Collection<BuiltInFunction> handleEventItems(List<EventItem> eventItems, ApplicationContext context, Event event, DataIdentifier dataId, EventData eventData) throws ExternalException { Collection<BuiltInFunction> builtInList = new ArrayList<BuiltInFunction>(); if (eventItems != null) { ListIterator<EventItem> itrEventItem = eventItems.listIterator(); while (itrEventItem.hasNext()) { EventItem eventItem = itrEventItem.next(); try { boolean stopProcessing = EventItemExecutor.getInstance().execute(eventItem, context, event, eventData, builtInList, this, dataId); if (stopProcessing) { break; }// www . java 2 s. c om } catch (ReturnBuiltInException e) { break; } catch (ExternalException e) { ErrorResult errorResult = EventErrorProcessor.processError(itrEventItem, eventItem, context, dataId, e, eventData); boolean rethrow = (errorResult.getExternalException() != null); if (rethrow) { throw errorResult.getExternalException(); } else if (errorResult.hasItems()) { List<EventItem> exceptionHandlingEventItems = new ArrayList<EventItem>(); for (Item item : errorResult.getItems()) { if (item instanceof EventItem) { exceptionHandlingEventItems.add((EventItem) item); } } Collection<BuiltInFunction> exceptionHandlingBuiltInList = handleEventItems( exceptionHandlingEventItems, context, event, dataId, eventData); builtInList.addAll(exceptionHandlingBuiltInList); } } } } return builtInList; }
From source file:es.tid.fiware.rss.expenditureLimit.server.service.ExpenditureLimitDataChecker.java
/** * //w w w. j a v a2 s .c o m * @param maxAmount * @param defaultProvThresholds */ private void checkNotificationLimits(Long maxAmount, List<Long> sNotifAmounts) throws RSSException { if ((maxAmount > 0) && (sNotifAmounts != null) && (sNotifAmounts.size() > 0)) { ListIterator<Long> litr = sNotifAmounts.listIterator(); while (litr.hasNext()) { long notifAmount = litr.next().longValue(); if (notifAmount > maxAmount) { String[] args = { "Amount notification (" + notifAmount + ") is greather than total limit (" + maxAmount + ")" }; throw new RSSException(UNICAExceptionType.INVALID_INPUT_VALUE, args); } } } }
From source file:mediathek.controller.IoXmlSchreiben.java
private void xmlSchreibenErsetzungstabelle() { ListIterator<String[]> iterator; iterator = Daten.mVReplaceList.liste.listIterator(); while (iterator.hasNext()) { String[] sa = iterator.next(); xmlSchreibenDaten(MVReplaceList.REPLACELIST, MVReplaceList.COLUMN_NAMES, sa, false); }// www . j a v a 2 s .c om }
From source file:com.platum.restflow.RestflowModel.java
/** * /*from w ww . j a v a 2 s.c o m*/ * @param resource * @return */ public RestflowModel updateResource(Resource resource) { Validate.notNull(resource, "Cannot update a null resource."); Validate.notEmpty(resource.getName(), "Resource name cannot be null or empty."); if (resources != null) { ListIterator<Resource> iterator = resources.listIterator(); while (iterator.hasNext()) { if (iterator.next().getName().equals(resource.getName())) { iterator.set(resource); return this; } } } throw new RestflowNotExistsException("Resource does not exists."); }