List of usage examples for java.util List listIterator
ListIterator<E> listIterator(int index);
From source file:com.projity.grouping.core.hierarchy.AbstractMutableNodeHierarchy.java
private Node getPrevious(Node current, boolean doChildren) { if (current == null) // null parent has no parent return null; List children; Node parent = getParent(current); children = getChildren(parent);//from www .ja v a2s. c om if (doChildren) { // if haven't visited children yet ListIterator i = children.listIterator(children.size()); // reverse iterator while (i.hasPrevious()) { // get next element after this one. If it is the last then try its parent if (i.previous() == current) { if (i.hasPrevious()) return getPrevious((Node) i.previous(), false); else return parent; } } } children = getChildren(current); if (children != null && children.size() > 0) // if parent, previous is last child return getPrevious((Node) children.get(children.size() - 1), doChildren); return current; }
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); }/*from ww w . ja v a 2s. 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:de.hofuniversity.iisys.neo4j.websock.util.JSONList.java
@Override public ListIterator<Object> listIterator(int arg0) { final List<Object> itList = new LinkedList<Object>(); final int size = fArray.length(); for (int i = 0; i < size; ++i) { try {/*from w w w . j av a2s . c om*/ itList.add(fromInternal(fArray.get(i))); } catch (JSONException e) { e.printStackTrace(); } } return itList.listIterator(arg0); }
From source file:org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun.java
/** * Inserts paragraph break before all close group marks. * * @throws IOException for I/O problems * @return The paragraph break element/*from w w w .j a v a 2 s . c o m*/ */ public RtfParagraphBreak addParagraphBreak() throws IOException { // get copy of children list List children = getChildren(); Stack tmp = new Stack(); RtfParagraphBreak par = null; // delete all previous CloseGroupMark int deletedCloseGroupCount = 0; ListIterator lit = children.listIterator(children.size()); while (lit.hasPrevious() && (lit.previous() instanceof RtfCloseGroupMark)) { tmp.push(Integer.valueOf(((RtfCloseGroupMark) lit.next()).getBreakType())); lit.remove(); deletedCloseGroupCount++; } if (children.size() != 0) { // add paragraph break and restore all deleted close group marks setChildren(children); par = new RtfParagraphBreak(this, writer); for (int i = 0; i < deletedCloseGroupCount; i++) { addCloseGroupMark(((Integer) tmp.pop()).intValue()); } } return par; }
From source file:org.commonjava.maven.ext.common.model.Project.java
private void resolvePlugins(MavenSessionHandler session, List<Plugin> plugins, HashMap<ProjectVersionRef, Plugin> resolvedPlugins) throws ManipulationException { ListIterator<Plugin> iterator = plugins.listIterator(plugins.size()); // Iterate in reverse order so later plugins take precedence while (iterator.hasPrevious()) { Plugin p = iterator.previous();/*from w w w . j av a2 s . c om*/ String g = PropertyResolver.resolveInheritedProperties(session, this, "${project.groupId}".equals(p.getGroupId()) ? getGroupId() : p.getGroupId()); String a = PropertyResolver.resolveInheritedProperties(session, this, "${project.artifactId}".equals(p.getArtifactId()) ? getArtifactId() : p.getArtifactId()); String v = PropertyResolver.resolveInheritedProperties(session, this, p.getVersion()); // Its possible the internal plugin list is either abbreviated or empty. Attempt to fill in default values for // comparison purposes. if (isEmpty(g)) { g = PLUGIN_DEFAULTS.getDefaultGroupId(a); } // Theoretically we could default an empty v via PLUGIN_DEFAULTS.getDefaultVersion( g, a ) but // this means managed plugins would be included which confuses things. if (isNotEmpty(g) && isNotEmpty(a) && isNotEmpty(v)) { SimpleProjectVersionRef spv = new SimpleProjectVersionRef(g, a, v); // If the GAV already exists within the map it means we have a duplicate entry. While Maven // technically allows this it does warn that this leads to unstable models. In PME case this breaks // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate. if (resolvedPlugins.containsKey(spv)) { logger.error("Found duplicate entry within plugin list. Key of {} and plugin {}", spv, p); iterator.remove(); } else { Plugin old = resolvedPlugins.put(spv, p); if (old != null) { logger.error("Internal project plugin resolution failure ; replaced {} in store by {}.", old, spv); throw new ManipulationException( "Internal project plugin resolution failure ; replaced " + old + " by " + spv); } } } } }
From source file:org.commonjava.maven.ext.common.model.Project.java
private void resolveDeps(MavenSessionHandler session, List<Dependency> deps, boolean includeManagedDependencies, HashMap<ArtifactRef, Dependency> resolvedDependencies) throws ManipulationException { ListIterator<Dependency> iterator = deps.listIterator(deps.size()); // Iterate in reverse order so later deps take precedence while (iterator.hasPrevious()) { Dependency d = iterator.previous(); String g = PropertyResolver.resolveInheritedProperties(session, this, "${project.groupId}".equals(d.getGroupId()) ? getGroupId() : d.getGroupId()); String a = PropertyResolver.resolveInheritedProperties(session, this, "${project.artifactId}".equals(d.getArtifactId()) ? getArtifactId() : d.getArtifactId()); String v = PropertyResolver.resolveInheritedProperties(session, this, d.getVersion()); if (includeManagedDependencies && isEmpty(v)) { v = "*"; }/*from ww w . j a v a2s .com*/ if (isNotEmpty(g) && isNotEmpty(a) && isNotEmpty(v)) { SimpleArtifactRef sar = new SimpleArtifactRef(g, a, v, d.getType(), d.getClassifier()); // If the GAVTC already exists within the map it means we have a duplicate entry. While Maven // technically allows this it does warn that this leads to unstable models. In PME case this breaks // the indexing as we don't have duplicate entries. Given they are exact matches, remove older duplicate. if (resolvedDependencies.containsKey(sar)) { logger.error("Found duplicate entry within dependency list. Key of {} and dependency {}", sar, d); iterator.remove(); } else { Dependency old = resolvedDependencies.put(sar, d); if (old != null) { logger.error( "Internal project dependency resolution failure ; replaced {} in store by {}:{}:{}.", old, g, a, v); throw new ManipulationException( "Internal project dependency resolution failure ; replaced " + old + " by " + d); } } } } }
From source file:org.apache.atlas.model.typedef.AtlasEnumDef.java
public void setElementDefs(List<AtlasEnumElementDef> elementDefs) { if (elementDefs != null && this.elementDefs == elementDefs) { return;//from www .ja va 2s. c o m } if (CollectionUtils.isEmpty(elementDefs)) { this.elementDefs = new ArrayList<>(); } else { // if multiple elements with same value are present, keep only the last entry List<AtlasEnumElementDef> tmpList = new ArrayList<>(elementDefs.size()); Set<String> elementValues = new HashSet<>(); ListIterator<AtlasEnumElementDef> iter = elementDefs.listIterator(elementDefs.size()); while (iter.hasPrevious()) { AtlasEnumElementDef elementDef = iter.previous(); String elementValue = elementDef != null ? elementDef.getValue() : null; if (elementValue != null) { elementValue = elementValue.toLowerCase(); if (!elementValues.contains(elementValue)) { tmpList.add(new AtlasEnumElementDef(elementDef)); elementValues.add(elementValue); } } } Collections.reverse(tmpList); this.elementDefs = tmpList; } }
From source file:org.commonjava.maven.ext.manip.impl.DependencyManipulator.java
/** * This will load the remote overrides. It will first try to load any overrides that might have * been prepopulated by the REST scanner, failing that it will load from a remote POM file. * * @param state the dependency state// w w w . j ava 2 s. c om * @return the loaded overrides * @throws ManipulationException if an error occurs. */ private Map<ArtifactRef, String> loadRemoteOverrides(final DependencyState state) throws ManipulationException { Map<ArtifactRef, String> overrides = state.getRemoteRESTOverrides(); if (overrides == null) { overrides = new LinkedHashMap<>(); final List<ProjectVersionRef> gavs = state.getRemoteBOMDepMgmt(); if (gavs == null || gavs.isEmpty()) { return overrides; } final ListIterator<ProjectVersionRef> iter = gavs.listIterator(gavs.size()); // Iterate in reverse order so that the first GAV in the list overwrites the last while (iter.hasPrevious()) { final ProjectVersionRef ref = iter.previous(); overrides.putAll(effectiveModelBuilder.getRemoteDependencyVersionOverrides(ref)); } } return overrides; }
From source file:net.sf.jasperreports.engine.export.JRGridLayout.java
protected void setGridElements(PrintElementIndex parentIndex, List<JRPrintElement> elements, int elementOffsetX, int elementOffsetY, int startRow, int startCol, int endRow, int endCol) { for (ListIterator<JRPrintElement> it = elements.listIterator(elements.size()); it.hasPrevious();) { JRPrintElement element = it.previous(); int elementIndex = it.nextIndex(); if (nature.isToExport(element)) { int x = element.getX() + elementOffsetX; int y = element.getY() + elementOffsetY; int col1 = xCuts.indexOfCutOffset(x); int row1 = yCuts.indexOfCutOffset(y); int col2 = xCuts.indexOfCutOffset(x + element.getWidth()); int row2 = yCuts.indexOfCutOffset(y + element.getHeight()); if (!isOverlap(row1, col1, row2, col2)) { JRPrintFrame frame = element instanceof JRPrintFrame ? (JRPrintFrame) element : null; if (frame != null && nature.isDeep(frame)) { PrintElementIndex frameIndex = new PrintElementIndex(parentIndex, elementIndex); setGridElements(frameIndex, frame.getElements(), x + frame.getLineBox().getLeftPadding(), y + frame.getLineBox().getTopPadding(), row1, col1, row2, col2); setFrameCellsStyle(frame, row1, col1, row2, col2); } else { setGridElement(element, parentIndex, elementIndex, row1, col1, row2, col2); }/*from ww w.jav a2 s .c o m*/ } } } if (nature.isHorizontallyMergeEmptyCells()) { horizontallyMergeEmptyCells(startRow, startCol, endRow, endCol); } }
From source file:edu.umn.msi.tropix.persistence.dao.hibernate.TropixObjectDaoImpl.java
public TropixObject getGroupDirectoryPath(final String userId, final List<String> pathParts) { final StringBuilder joins = new StringBuilder(), wheres = new StringBuilder(); final ListIterator<String> pathPartsIter = pathParts.listIterator(pathParts.size()); final LinkedList<String> parameters = Lists.newLinkedList(); while (pathPartsIter.hasPrevious()) { int index = pathPartsIter.previousIndex(); final String pathPart = pathPartsIter.previous(); wheres.append(String.format(" and o%d.deletedTime is null", index)); wheres.append(String.format(" and o%d.committed is true", index)); addConstraintForPathPart(pathPart, index, wheres, parameters); if (pathPartsIter.hasPrevious()) { int nextObjectBackIndex = pathPartsIter.previousIndex(); joins.append(/* w ww .j a v a 2 s . c o m*/ String.format(" inner join o%d.permissionParents as o%d ", index, nextObjectBackIndex)); } } final int lastIndex = pathParts.size() - 1; final String objectType = lastIndex == 0 ? "Folder" : "TropixObject"; final String queryString = String.format( "%s o%d %s inner join o0.permissions p left join p.users u left join p.groups g left join g.users gu where (u.cagridId = :userId or gu.cagridId = :userId) and o0.parentFolder is null %s and o0.class is Folder", objectType, lastIndex, joins.toString(), wheres.toString()); return executePathQuery(userId, String.format("o%d", lastIndex), queryString, 0, parameters); }