List of usage examples for java.util ListIterator hasPrevious
boolean hasPrevious();
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;//w w w.j a v a2 s. co m Node parent = getParent(current); children = getChildren(parent); 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.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 av a 2 s. com*/ */ 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:com.haulmont.cuba.core.sys.MetadataImpl.java
protected void invokePostConstructMethods(Entity entity) throws InvocationTargetException, IllegalAccessException { List<Method> postConstructMethods = new ArrayList<>(4); List<String> methodNames = new ArrayList<>(4); Class clazz = entity.getClass(); while (clazz != Object.class) { Method[] classMethods = clazz.getDeclaredMethods(); for (Method method : classMethods) { if (method.isAnnotationPresent(PostConstruct.class) && !methodNames.contains(method.getName())) { postConstructMethods.add(method); methodNames.add(method.getName()); }/*from w ww . ja va2 s . co m*/ } clazz = clazz.getSuperclass(); } ListIterator<Method> iterator = postConstructMethods.listIterator(postConstructMethods.size()); while (iterator.hasPrevious()) { Method method = iterator.previous(); if (!method.isAccessible()) { method.setAccessible(true); } method.invoke(entity); } }
From source file:com.galenframework.speclang2.pagespec.PageSectionProcessor.java
private Pair<PageRule, Map<String, String>> findAndProcessRule(String ruleText, StructNode ruleNode) { ListIterator<Pair<Rule, PageRule>> iterator = pageSpecHandler.getPageRules() .listIterator(pageSpecHandler.getPageRules().size()); /*//from w ww . ja va 2 s.c o m It is important to make a reversed iteration over all rules so that it is possible for the end user to override previously defined rules */ while (iterator.hasPrevious()) { Pair<Rule, PageRule> rulePair = iterator.previous(); Matcher matcher = rulePair.getKey().getPattern().matcher(ruleText); if (matcher.matches()) { int index = 1; Map<String, String> parameters = new HashMap<>(); for (String parameterName : rulePair.getKey().getParameters()) { String value = matcher.group(index); pageSpecHandler.setGlobalVariable(parameterName, value, ruleNode); parameters.put(parameterName, value); index += 1; } return new ImmutablePair<>(rulePair.getValue(), parameters); } } throw new SyntaxException(ruleNode, "Couldn't find rule matching: " + ruleText); }
From source file:com.bwc.ora.models.Lrp.java
public List<XYSeries> getFWHMForLRPPeaks(XYSeries lrpPeaks, XYSeries lrpSeries) { LinkedList<XYSeries> seriesList = new LinkedList<>(); List<XYDataItem> pointList = (List<XYDataItem>) lrpSeries.getItems(); List<XYDataItem> peakList = (List<XYDataItem>) lrpPeaks.getItems(); //iterate through the peaks, process FWHM for each peak for (XYDataItem peak : peakList) { //grab index of the closest point to the peak int peakIndex = -1; for (XYDataItem pnt : pointList) { peakIndex++;//from w w w. ja v a2 s . c o m if (Math.abs(pnt.getXValue() - peak.getXValue()) < 0.6D) { break; } } //calculate point with Y value of valley to the left of peak XYDataItem leftValleyPoint = null; ListIterator<XYDataItem> it = pointList.listIterator(peakIndex); double prevY = peak.getYValue(); while (it.hasPrevious()) { XYDataItem leftPoint = it.previous(); if (leftPoint.getYValue() <= prevY) { prevY = leftPoint.getYValue(); leftValleyPoint = leftPoint; } else { break; } } //calculate point with Y value of valley to the right of peak XYDataItem rightValleyPoint = null; it = pointList.listIterator(peakIndex); prevY = peak.getYValue(); while (it.hasNext()) { XYDataItem rightPoint = it.next(); if (rightPoint.getYValue() <= prevY) { prevY = rightPoint.getYValue(); rightValleyPoint = rightPoint; } else { break; } } //determine half max Y value double halfMaxYValue; if (rightValleyPoint.getYValue() == leftValleyPoint.getYValue()) { halfMaxYValue = peak.getYValue() - ((peak.getYValue() - leftValleyPoint.getYValue()) / 2D); } else if (rightValleyPoint.getYValue() > leftValleyPoint.getYValue()) { halfMaxYValue = peak.getYValue() - ((peak.getYValue() - rightValleyPoint.getYValue()) / 2D); } else { halfMaxYValue = peak.getYValue() - ((peak.getYValue() - leftValleyPoint.getYValue()) / 2D); } //determine the X value on both sides of the peak that corresponds to the half max Y value double leftX = pointList.get(0).getXValue(), rightX = pointList.get(pointList.size() - 1).getXValue(); XYDataItem prevPoint = pointList.get(peakIndex); it = pointList.listIterator(peakIndex); while (it.hasPrevious()) { XYDataItem leftPoint = it.previous(); if (leftPoint.getYValue() == halfMaxYValue) { leftX = leftPoint.getXValue(); break; } else { if (leftPoint.getYValue() < halfMaxYValue) { // System.out.println("Left X for peak (" + peak.getXValue() + "," + peak.getYValue() + "): "); leftX = calculateXFromYForLineWithTwoPoints(leftPoint, prevPoint, halfMaxYValue); // System.out.println(" Left X: (" + leftX + "," + halfMaxYValue + "): "); break; } else { prevPoint = leftPoint; } } } prevPoint = pointList.get(peakIndex); it = pointList.listIterator(peakIndex); while (it.hasNext()) { XYDataItem rightPoint = it.next(); if (rightPoint.getYValue() == halfMaxYValue) { rightX = rightPoint.getXValue(); break; } else { if (rightPoint.getYValue() < halfMaxYValue) { // System.out.println("Right X for peak (" + peak.getXValue() + "," + peak.getYValue() + "): "); rightX = calculateXFromYForLineWithTwoPoints(rightPoint, prevPoint, halfMaxYValue); // System.out.println(" Right X: (" + leftX + "," + halfMaxYValue + "): "); break; } else { prevPoint = rightPoint; } } } //store the two points for the half max full width line for this peak XYSeries peakSeries = new XYSeries("(" + peak.getXValue() + "," + peak.getYValue() + ")FWHM"); peakSeries.add(leftX, halfMaxYValue); peakSeries.add(rightX, halfMaxYValue); seriesList.add(peakSeries); } return seriesList; }
From source file:org.eclipse.jubula.client.core.businessprocess.CompNamesBP.java
/** * @param treePath//from w ww . j a va 2 s .co m * The tree path * @param compNameCache * The cache to use in order to resolve Component Name * references. * @param originalName * The GUID of the component name. * @param originalCompNameDefiner * The node that is using the component name * @return The result containing the component name and the responsible node */ private CompNameResult findCompName(List<INodePO> treePath, IComponentNameCache compNameCache, String originalName, INodePO originalCompNameDefiner) { String currentName = originalName; INodePO compNameDefiner = originalCompNameDefiner; IComponentNamePO currentNamePo; ListIterator<INodePO> it = treePath.listIterator(treePath.size()); while (it.hasPrevious()) { INodePO node = it.previous(); if (node instanceof IExecTestCasePO) { IExecTestCasePO execNode = (IExecTestCasePO) node; ICompNamesPairPO pair = null; if (!StringUtils.isEmpty(currentName)) { pair = execNode.getCompNamesPair(currentName); } if (pair != null) { currentName = pair.getSecondName(); currentNamePo = compNameCache.getCompNamePo(currentName); if (currentNamePo != null) { currentName = currentNamePo.getGuid(); } if (pair.isPropagated()) { int index = it.previousIndex(); if (index > -1) { compNameDefiner = treePath.get(index); } } else { compNameDefiner = execNode; break; } } } } return new CompNameResult(currentName, compNameDefiner); }
From source file:org.eclipse.jubula.rc.common.driver.KeyTyper.java
/** * @param options options/*from ww w. j av a2 s . c om*/ * @param alreadyDown alreadyDown * @param i i * @param interceptor The interceptor that will be used to wait for event * confirmation. * @param keyUpMatcher The event matcher to be used for key release event * confirmation. */ private void releaseKeys(InterceptorOptions options, Set alreadyDown, ListIterator i, IRobotEventInterceptor interceptor, IEventMatcher keyUpMatcher) { boolean waitForConfirm = interceptor != null && keyUpMatcher != null; // Release all keys in reverse order. Set alreadyUp = new HashSet(); while (i.hasPrevious()) { Integer keycode = (Integer) i.previous(); if (log.isDebugEnabled()) { log.debug("trying to release: " + keycode.intValue()); //$NON-NLS-1$ } if (!alreadyUp.contains(keycode) && alreadyDown.contains(keycode)) { try { IRobotEventConfirmer confirmer = null; if (waitForConfirm) { confirmer = interceptor.intercept(options); } if (log.isDebugEnabled()) { log.debug("releasing: " + keycode.intValue()); //$NON-NLS-1$ } alreadyUp.add(keycode); m_robot.keyRelease(keycode.intValue()); if (waitForConfirm) { confirmer.waitToConfirm(null, keyUpMatcher); } } catch (RobotException e) { log.error("error releasing keys", e); //$NON-NLS-1$ if (!i.hasPrevious()) { throw e; } } } } }
From source file:eu.scidipes.toolkits.pawebapp.web.ItemsController.java
public String editItemHelper(final List<Form> formSubset, final Form form, final Model model, final RedirectAttributes redirectAttrs) { final ListIterator<Form> formIterator = formSubset.listIterator(); while (formIterator.hasNext()) { final Form theForm = formIterator.next(); if (theForm.equals(form)) { /* Jump back: */ formIterator.previous();/* www.j a v a 2s . c o m*/ if (formIterator.hasPrevious()) { model.addAttribute("previous", Integer.valueOf(formSubset.get(formIterator.previousIndex()).getFormID().intValue())); } /* Jump forward: */ formIterator.next(); if (formIterator.hasNext()) { model.addAttribute("next", Integer.valueOf(formSubset.get(formIterator.nextIndex()).getFormID().intValue())); } } } model.addAttribute("saveAction", EDIT); final CurationPersistentIdentifier manifestCPID = form.getManifestCPID(); final Map<DatasetRIL, Set<CoreRIType>> rilMembership = new HashMap<>(); /* Fetch the current RIL membership for this form instance: */ for (final DatasetRIL dsRIL : form.getParentBundle().getRils()) { final RepresentationInformation[] repInfo = dsRIL.getRil().getRepresentationInformationChildren(); for (final RepresentationInformation coreRI : repInfo) { if (coreRI.getRepresentationInformation() instanceof RepInfoGroup) { final RepInfoGroup repInfoGroup = (RepInfoGroup) coreRI.getRepresentationInformation(); for (final RepresentationInformation ri : repInfoGroup.getRepresentationInformationChildren()) { if (ri.getCpid().equals(manifestCPID)) { if (!rilMembership.containsKey(dsRIL)) { rilMembership.put(dsRIL, new HashSet<CoreRIType>()); } rilMembership.get(dsRIL).add(CoreRIType.fromClass(coreRI.getClass())); } } } } } model.addAttribute("rilMembership", rilMembership); model.addAttribute("form", form); return "datasets/items/edit"; }
From source file:org.openconcerto.openoffice.ODSingleXMLDocument.java
static private int[] getLastNulls(final Map<Tuple2<Namespace, String>, ContentPart> parts, final List<Content> content, final int contentSize) { // start from the end until we leave the epilogue (quicker than traversing the main part as // prologue and epilogue sizes are bounded and small) ContentPart contentPart = null;/* w w w .ja v a 2s. co m*/ final ListIterator<Content> thisChildrenIter = content.listIterator(contentSize); int nullsStartIndex = -1; while ((contentPart == null || contentPart == ContentPart.EPILOGUE) && thisChildrenIter.hasPrevious()) { contentPart = getPart(parts, thisChildrenIter.previous()); if (contentPart != null) { nullsStartIndex = -1; } else if (nullsStartIndex < 0) { nullsStartIndex = thisChildrenIter.nextIndex(); } } final int lastNullsStart = contentPart == null || contentPart == ContentPart.EPILOGUE ? thisChildrenIter.nextIndex() : thisChildrenIter.nextIndex() + 1; final int lastNullsEnd = nullsStartIndex < 0 ? lastNullsStart : nullsStartIndex + 1; return new int[] { lastNullsStart, lastNullsEnd }; }
From source file:org.apache.cayenne.access.DbGenerator.java
/** * Returns a list of all schema statements that should be executed with the * current configuration./*from w w w .ja v a 2 s . co m*/ */ public List<String> configuredStatements() { List<String> list = new ArrayList<>(); if (shouldDropTables) { ListIterator<DbEntity> it = dbEntitiesInInsertOrder.listIterator(dbEntitiesInInsertOrder.size()); while (it.hasPrevious()) { DbEntity ent = it.previous(); list.addAll(dropTables.get(ent.getName())); } } if (shouldCreateTables) { for (final DbEntity ent : dbEntitiesInInsertOrder) { list.add(createTables.get(ent.getName())); } } if (shouldCreateFKConstraints) { for (final DbEntity ent : dbEntitiesInInsertOrder) { List<String> fks = createConstraints.get(ent.getName()); list.addAll(fks); } } if (shouldDropPKSupport) { list.addAll(dropPK); } if (shouldCreatePKSupport) { list.addAll(createPK); } return list; }