List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:com.offbynull.voip.kademlia.model.NodeLeastRecentSet.java
public ActivityChangeSet touch(Instant time, Node node, boolean allowLinkMismatch) { Validate.notNull(time);//from ww w .ja va2 s.co m Validate.notNull(node); Id nodeId = node.getId(); InternalValidate.matchesLength(baseId.getBitLength(), nodeId); // Validate.isTrue(!nodeId.equals(baseId)); // Don't reject adding self // TODO: You can make this way more efficient if you used something like MultiTreeSet (guava) and sorted based on entry time // Remove existing entry Activity oldEntry = null; ListIterator<Activity> it = entries.listIterator(); while (it.hasNext()) { Activity entry = it.next(); Id entryId = entry.getNode().getId(); if (entryId.equals(nodeId)) { if (!allowLinkMismatch) { InternalValidate.matchesLink(entry.getNode(), node); } // remove it.remove(); oldEntry = entry; break; } } // Add entry Activity newEntry = new Activity(node, time); it = entries.listIterator(); boolean added = false; while (it.hasNext()) { Activity entry = it.next(); if (entry.getTime().isAfter(time)) { it.previous(); // move back 1 space, we want to add to element just before entry it.add(newEntry); added = true; break; } } if (!added) { // special case where newEntry needs to be added at the end of entries, not handled by loop above entries.addLast(newEntry); } // Set has become too large, remove the item with the latest time Activity discardedEntry = null; if (entries.size() > maxSize) { // if the node removed with the latest time is the one we just added, then report that node couldn't be added discardedEntry = entries.removeLast(); if (discardedEntry.equals(newEntry)) { return ActivityChangeSet.NO_CHANGE; } } // Add successful if (oldEntry != null) { Validate.validState(discardedEntry == null); // sanity check, must not have discarded anything // updated existing node return ActivityChangeSet.updated(newEntry); } else { // if block above ensures oldEntry is null if we're in this else block, so sanity check below isn't nessecary // Validate.validState(oldEntry == null); // sanity check, node being touched must not have already existed // added new node Collection<Activity> addedEntries = singletonList(newEntry); Collection<Activity> removedEntries = discardedEntry == null ? emptyList() : singletonList(discardedEntry); Collection<Activity> updatedEntries = emptyList(); return new ActivityChangeSet(addedEntries, removedEntries, updatedEntries); } }
From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java
protected void processFileItemList(List<FileItem> fileItems, String media, String type) throws FileNotFoundException, IOException { File typeDir = getTypeDir(media, type, true); ListIterator<FileItem> fileItemIterator = fileItems.listIterator(); while (fileItemIterator.hasNext()) { FileItem item = fileItemIterator.next(); if (item.isFormField()) { fileItemIterator.remove();/* ww w. java 2s . c om*/ } else { File f = createFile(typeDir, item); } } }
From source file:br.com.ingenieux.mojo.beanstalk.version.RollbackVersionMojo.java
@Override protected Object executeInternal() throws MojoExecutionException, MojoFailureException { // TODO: Deal with withVersionLabels DescribeApplicationVersionsRequest describeApplicationVersionsRequest = new DescribeApplicationVersionsRequest() .withApplicationName(applicationName); DescribeApplicationVersionsResult appVersions = getService() .describeApplicationVersions(describeApplicationVersionsRequest); DescribeEnvironmentsRequest describeEnvironmentsRequest = new DescribeEnvironmentsRequest() .withApplicationName(applicationName).withEnvironmentIds(curEnv.getEnvironmentId()) .withEnvironmentNames(curEnv.getEnvironmentName()).withIncludeDeleted(false); DescribeEnvironmentsResult environments = getService().describeEnvironments(describeEnvironmentsRequest); List<ApplicationVersionDescription> appVersionList = new ArrayList<ApplicationVersionDescription>( appVersions.getApplicationVersions()); List<EnvironmentDescription> environmentList = environments.getEnvironments(); if (environmentList.isEmpty()) { throw new MojoFailureException("No environments were found"); }// w ww .j a v a 2 s .co m EnvironmentDescription d = environmentList.get(0); Collections.sort(appVersionList, new Comparator<ApplicationVersionDescription>() { @Override public int compare(ApplicationVersionDescription o1, ApplicationVersionDescription o2) { return new CompareToBuilder().append(o1.getDateUpdated(), o2.getDateUpdated()).toComparison(); } }); Collections.reverse(appVersionList); if (latestVersionInstead) { ApplicationVersionDescription latestVersionDescription = appVersionList.get(0); return changeToVersion(d, latestVersionDescription); } ListIterator<ApplicationVersionDescription> versionIterator = appVersionList.listIterator(); String curVersionLabel = d.getVersionLabel(); while (versionIterator.hasNext()) { ApplicationVersionDescription versionDescription = versionIterator.next(); String versionLabel = versionDescription.getVersionLabel(); if (curVersionLabel.equals(versionLabel) && versionIterator.hasNext()) { return changeToVersion(d, versionIterator.next()); } } throw new MojoFailureException("No previous version was found (current version: " + curVersionLabel); }
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);//from w w w . j a v a 2s . c om } }
From source file:com.edgenius.wiki.render.macro.BaseMacro.java
/** * Reset all inside node to blank text node. * !!! Here changes ListIterator cursor position!!! * @param node/* w ww . j a v a2 s . co m*/ * @param iter */ protected void resetInsideNode(HTMLNode node, ListIterator<HTMLNode> iter) { HTMLNode subnode; for (; iter.hasNext();) { subnode = iter.next(); if (subnode == node.getPair()) break; if (!subnode.isTextNode()) { subnode.reset("", true); if (subnode.getPair() != null) subnode.getPair().reset("", true); } else { subnode.reset("", true); } } }
From source file:com.braffdev.server.core.container.resourceloader.ResourceLoader.java
/** * Removes the given stream from the list of currently open streams. * * @param in the stream./*w w w .j av a 2 s .c o m*/ */ public void removeStream(ResourceInputStream in) { synchronized (this.streams) { ListIterator<ResourceInputStream> iter = this.streams.listIterator(); while (iter.hasNext()) { if (in == iter.next()) { iter.remove(); break; } } } }
From source file:org.opensha.sha.calc.IM_EventSet.v03.test.IM_EventSetHazardCurveTest.java
public IM_EventSetHazardCurveTest() { outputDir = IM_EventSetTest.getTempDir(); erf = new Frankel96_AdjustableEqkRupForecast(); erf.getAdjustableParameterList().getParameter(Frankel96_AdjustableEqkRupForecast.BACK_SEIS_NAME) .setValue(Frankel96_AdjustableEqkRupForecast.BACK_SEIS_EXCLUDE); erf.updateForecast();//from w w w .ja v a 2 s . c o m imr = new CB_2008_AttenRel(null); imr.setParamDefaults(); IM_EventSetOutputWriter.setIMTFromString(imt, imr); site = new Site(new Location(34d, -118d)); ListIterator<ParameterAPI<?>> it = imr.getSiteParamsIterator(); while (it.hasNext()) { ParameterAPI<?> param = it.next(); site.addParameter(param); } sites = new ArrayList<Site>(); sites.add(site); sitesData = new ArrayList<ArrayList<SiteDataValue<?>>>(); sitesData.add(new ArrayList<SiteDataValue<?>>()); gp = new GraphPanel(this); }
From source file:org.openinfinity.tagcloud.domain.service.TargetServiceImpl.java
private List<Result> nearbySearch(List<Target> allTargets, List<Result> results, List<Tag> nearbyTags) { for (Target target : allTargets) { List<Tag> foundNearbyTags = new ArrayList<Tag>(); for (Tag tag : nearbyTags) { if (target.getTags().contains(tag)) foundNearbyTags.add(tag); }/* ww w .j a va 2 s . c o m*/ if (foundNearbyTags.size() == 0) continue; ListIterator<Result> resultIterator = results.listIterator(0); while (resultIterator.hasNext()) { Result result = resultIterator.next(); for (Tag tag : foundNearbyTags) { NearbyTarget nearbyTarget = result.getNearbyTargetsMap().get(tag.getText()); double distance = calcRelativeDistance(result.getTarget(), target); if (distance < nearbyTarget.getDistance()) { nearbyTarget.setTarget(target); nearbyTarget.setDistance(distance); } } result.updateNearbyTargetList(); } } // update correct absolute distances and remove ones too far away ListIterator<Result> resultIterator = results.listIterator(0); while (resultIterator.hasNext()) { Result result = resultIterator.next(); for (NearbyTarget nearbyTarget : result.getNearbyTargetsList()) { nearbyTarget.setDistance(calcDistance(result.getTarget(), nearbyTarget.getTarget())); if (nearbyTarget.getDistance() > NearbyTarget.MAX_DISTANCE) { resultIterator.remove(); break; } } } return results; }
From source file:com.braffdev.server.core.container.resourceloader.ResourceLoader.java
/** * Frees all resource that may are being used (Closes all open InputStreams and prevents the server from opening new ones); *//* w w w . j a va 2 s. co m*/ @Override public void shutdown() { this.enabled = false; // close all streams synchronized (this.streams) { ListIterator<ResourceInputStream> iter = this.streams.listIterator(); while (iter.hasNext()) { InputStream in = iter.next(); IOUtils.closeQuietly(in); iter.remove(); } } }
From source file:edu.harvard.mcz.imagecapture.TemplatePickerDialog.java
protected boolean setupForImage(ICImage image) throws UnreadableFileException { boolean result = false; imageToTemplate = image;// ww w .ja va2s .com StringBuffer heading = new StringBuffer(); heading.append("Current Template:"); heading.append(" ").append(image.getTemplateId()); StringBuffer filename = new StringBuffer(); filename.append(image.getPath()).append(File.pathSeparator).append(image.getFilename()); this.lblFileName.setText(filename.toString()); lblTemplate.setText(heading.toString()); comboBoxTemplatePicker.addItem(image.getTemplateId()); File imageFile = new File( ImageCaptureProperties.assemblePathWithBase(image.getPath(), image.getFilename())); BufferedImage bufImage = null; int imageWidth = 0; try { bufImage = ImageIO.read(imageFile); imageWidth = bufImage.getWidth(); } catch (IOException e) { throw new UnreadableFileException("IOException trying to read " + imageFile.getName()); } if (imageFile.exists()) { List<PositionTemplate> templates = PositionTemplate.getTemplates(); ListIterator<PositionTemplate> i = templates.listIterator(); while (i.hasNext()) { PositionTemplate template = i.next(); if (!template.getTemplateId().equals(PositionTemplate.TEMPLATE_NO_COMPONENT_PARTS)) { int templateWidth = -1; try { templateWidth = (int) template.getImageSize().getWidth(); } catch (NullPointerException e) { log.debug(e.getMessage()); } if (imageWidth == templateWidth) { comboBoxTemplatePicker.addItem(template.getTemplateId()); } } } } return result; }