/** * Given a master list and the new sub list, replace the items in the master list with the * matching items from the new sub list. This process works even if the length of the new sublist * is different. * * <p>For example, givn: * * <pre> * replace A by A': * M=[A,B,C], S=[A'] => [A',B,C] * M=[A,B,A,B,C], S=[A',A'] => [A',B,A',B,C] * * when list length is different: * M=[A,A,B,C], S=[] => [B,C] * M=[A,B,C], S=[A',A'] => [A',A',B,C] * M=[B,C], S=[A',A'] => [B,C,A',A'] * </pre> */ private static List<Child> stitchList( List<Child> list, String name, List<? extends Child> newSubList) { List<Child> removed = new LinkedList<Child>(); // to preserve order, try to put new itesm where old items are found. // if the new list is longer than the current list, we put all the extra // after the last item in the sequence. That is, // given [A,A,B,C] and [A',A',A'], we'll update the list to [A',A',A',B,C] // The 'last' variable remembers the insertion position. int last = list.size(); ListIterator<Child> itr = list.listIterator(); ListIterator<? extends Child> jtr = newSubList.listIterator(); while (itr.hasNext()) { Child child = itr.next(); if (child.name.equals(name)) { if (jtr.hasNext()) { itr.set(jtr.next()); // replace last = itr.nextIndex(); removed.add(child); } else { itr.remove(); // remove removed.add(child); } } } // new list is longer than the current one if (jtr.hasNext()) list.addAll(last, newSubList.subList(jtr.nextIndex(), newSubList.size())); return removed; }
/** * @see org.apache.jsieve.tests.AbstractTest#executeBasic(MailAdapter, Arguments, SieveContext) * <p>From RFC 3028, Section 5.9... <code> * Syntax: size <"e;:over""e; / "e;:under"e;> <limit: number> * </code> */ protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SyntaxException, SieveMailException { String comparator = null; Integer size = null; ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator(); // First argument MUST be a tag of ":under" or ":over" if (argumentsIter.hasNext()) { Argument argument = argumentsIter.next(); if (argument instanceof TagArgument) { final String tag = ((TagArgument) argument).getTag(); if (tag.equals(":under") || tag.equals(":over")) comparator = tag; else throw context .getCoordinate() .syntaxException( new StringBuilder("Found unexpected TagArgument: \"").append(tag).append("\"")); } } if (null == comparator) throw context.getCoordinate().syntaxException("Expecting a Tag"); // Second argument MUST be a number if (argumentsIter.hasNext()) { final Argument argument = argumentsIter.next(); if (argument instanceof NumberArgument) size = ((NumberArgument) argument).getInteger(); } if (null == size) throw context.getCoordinate().syntaxException("Expecting a Number"); // There MUST NOT be any further arguments if (argumentsIter.hasNext()) throw context.getCoordinate().syntaxException("Found unexpected argument(s)"); return test(mail, comparator, size.intValue()); }
@Override public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof Customer)) return false; Customer c = (Customer) obj; if (this.id != c.id) return false; if (!(this.name.equals(c.name))) return false; // Compare contacts ListIterator e1 = this.contacts.listIterator(); ListIterator e2 = c.contacts.listIterator(); while (e1.hasNext() && e2.hasNext()) { Object o1 = e1.next(); Object o2 = e2.next(); if (o1 instanceof JAXBElement && o2 instanceof JAXBElement) { o1 = ((JAXBElement) o1).getValue(); o2 = ((JAXBElement) o2).getValue(); } if (!(o1 == null ? o2 == null : o1.equals(o2))) { return false; } } return !(e1.hasNext() || e2.hasNext()); }
public void xmlActionPerformed(ActionEvent e) { if (singleNodeOperation != null) { for (ListIterator it = modeController.getSelecteds().listIterator(); it.hasNext(); ) { MindMapNodeModel selected = (MindMapNodeModel) it.next(); singleNodeOperation.apply((MindMapMapModel) this.modeController.getMap(), selected); } } else { // xml action: // Do-action CompoundAction doAction = new CompoundAction(); // Undo-action CompoundAction undo = new CompoundAction(); // sort selectedNodes list by depth, in order to guarantee that // sons are deleted first: for (ListIterator it = modeController.getSelecteds().listIterator(); it.hasNext(); ) { MindMapNodeModel selected = (MindMapNodeModel) it.next(); ActionPair pair = actor.apply(this.modeController.getMap(), selected); if (pair != null) { doAction.addChoice(pair.getDoAction()); undo.addAtChoice(0, pair.getUndoAction()); } } if (doAction.sizeChoiceList() == 0) return; modeController.getActionFactory().startTransaction((String) getValue(NAME)); modeController.getActionFactory().executeAction(new ActionPair(doAction, undo)); modeController.getActionFactory().endTransaction((String) getValue(NAME)); } }
@Override protected void invalidateNode(SNode sNode) { NodePath affPath = NodePath.forSNode(sNode); SModel containingModel = sNode.getContainingModel(); if (containingModel == null) return; SModelReference mref = containingModel.getReference(); List<NodePath> nodePaths = nodePaths(mref); ListIterator<NodePath> npathIt = nodePaths.listIterator(); while (npathIt.hasNext()) { NodePath path = npathIt.next(); NodePath lcp = affPath.findLowestCommonParent(path); if (lcp != null) { if (lcp.equals(path)) break; // replace with the LCP and stop npathIt.remove(); npathIt.add(lcp); break; } } if (!npathIt.hasNext()) { // not found -> just add nodePaths.add(affPath); } }
/* Creates a parent chain of ResourceMaps for the specfied * ResourceBundle names. One ResourceMap is created for each * subsequence of ResourceBundle names with a common bundle * package name, i.e. with a common resourcesDir. The parent * of the final ResourceMap in the chain is root. */ private ResourceMap createResourceMapChain( ClassLoader cl, ResourceMap root, ListIterator<String> names) { if (!names.hasNext()) { return root; } else { List<String> rmNames = new ArrayList<String>(2); String bundleName0 = names.next(); String rmBundlePackage = bundlePackageName(bundleName0); rmNames.add(bundleName0); while (names.hasNext()) { String bundleName = names.next(); String bpn = bundlePackageName(bundleName); if (rmBundlePackage.equals(bpn)) { rmNames.add(bundleName); } else { names.previous(); break; } } ResourceMap parent = createResourceMapChain(cl, root, names); return createResourceMap(cl, parent, rmNames); } }
void tryToDeleteSegment(Point p) { if (points.size() < 3) return; LatLon start; start = findBigSegment(p); ListIterator<LatLon> it = points.listIterator(); LatLon pp; boolean f = false; int i = 0, idx = -1; while (it.hasNext()) { pp = it.next(); if (f && (fixed.contains(pp))) { // if end of line fragment reached lastIdx = idx; return; } if (f && (!it.hasNext())) { // if end of whole line reached closedFlag = false; it.remove(); lastIdx = points.size() - 1; return; } // if we are deleting this segment if (f) it.remove(); if (pp == start) { f = true; idx = i; } // next node should be removed i++; } lastIdx = points.size() - 1; }
/** * Overlays this fragment list by some {@link Fragment}. That means that parts that overlap are * taken from the fragment passed. * * @param fragment The fragment. * @return A fragment list storing the overlay result. */ public FragmentList overlayBy(final Fragment fragment) { final FragmentList result = new FragmentList(); try { result.addFragment(fragment); } catch (final IncompatibleFragmentException e) { throw new Error(e); } final PositionInText posTo = fragment.getTo(); final ListIterator<Fragment> it = this.fragments.listIterator(); while (it.hasNext()) { final Fragment oldFragment = it.next(); if (posTo.lessThan(oldFragment.getFrom())) { break; } final ListIterator<Fragment> fIt = result.fragments.listIterator(); while (fIt.hasNext()) { final Fragment f = fIt.next(); final FragmentList rest = f.subtract(oldFragment); fIt.remove(); for (final Fragment newFragment : rest.fragments) { fIt.add(newFragment); } } } try { result.addFragmentList(this); } catch (final IncompatibleFragmentException e) { throw new Error(e); } return result; }
public void testUniqueConstraints() throws Exception { createTestEntityWithElementCollection(); addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); JavaElementCollectionMapping2_0 elementCollectionMapping = (JavaElementCollectionMapping2_0) getJavaPersistentType().getAttributes().iterator().next().getMapping(); JavaCollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable(); ListIterator<JavaSpecifiedUniqueConstraint> uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); assertFalse(uniqueConstraints.hasNext()); JavaResourceType resourceType = (JavaResourceType) getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE); JavaResourceField resourceField = resourceType.getFields().iterator().next(); CollectionTableAnnotation2_0 joinTableAnnotation = (CollectionTableAnnotation2_0) resourceField.addAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME); joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "foo"); joinTableAnnotation.addUniqueConstraint(0).addColumnName(0, "bar"); getJpaProject().synchronizeContextModel(); uniqueConstraints = collectionTable.getUniqueConstraints().iterator(); assertTrue(uniqueConstraints.hasNext()); assertEquals("bar", uniqueConstraints.next().getColumnNames().iterator().next()); assertEquals("foo", uniqueConstraints.next().getColumnNames().iterator().next()); assertFalse(uniqueConstraints.hasNext()); }
/** * Sends the data from the vectors to the X and Y array. * * @see #getXData() * @see #getYData() */ private void sendDataToDoubleArray() { xDoubleData = new double[xData.size()]; ListIterator iterator = xData.listIterator(); Double next = null; int counter = 0; while (iterator.hasNext()) { next = (Double) iterator.next(); xDoubleData[counter] = next.doubleValue(); counter++; } yDoubleData = new double[yData.size()]; iterator = yData.listIterator(); counter = 0; while (iterator.hasNext()) { next = (Double) iterator.next(); yDoubleData[counter] = next.doubleValue(); counter++; } xData = yData = null; }
/** * Sorts the components in the list. * * @param list the list to be sorted * @param from the index of the first element (inclusive) to be sorted * @param to the index of the last element (exclusive) to be sorted * @param cpr the comparator to determine the order of the list. * @since 3.5.0 */ public static void sort( List<? extends Component> list, int from, int to, Comparator<? super Component> cpr) { final Component ary[] = CollectionsX.toArray(list, new Component[0], from, to); Arrays.sort(ary, cpr); ListIterator<? extends Component> it = list.listIterator(from); int j = 0, k = to - from; for (; it.hasNext() && --k >= 0; ++j) { if (it.next() != ary[j]) { it.remove(); if (it.hasNext() && --k >= 0) { if (it.next() == ary[j]) continue; it.previous(); ++k; } break; } } while (it.hasNext() && --k >= 0) { it.next(); it.remove(); } for (; j < ary.length; ++j) add(list, from + j, ary[j]); }
public InterfaceReasoner setUpOntology( ScenarioTest st, String ont, String ns, InterfaceReasoner jena) throws InvalidOntologyException { ListIterator liClass; ListIterator liProperties; String[] ciClas, ciInd, piClas, piInd; String patron1 = "[\\(|,|\n| ]"; String patron2 = "[\n| |\\)]"; Instancias instancias = st.getInstancias(); List<ClassInstances> classInstances = instancias.getClassInstances(); List<PropertyInstances> propertyInstances = instancias.getPropertyInstances(); liClass = classInstances.listIterator(); liProperties = propertyInstances.listIterator(); while (liClass.hasNext()) { ClassInstances cla = (ClassInstances) liClass.next(); String ci = cla.getClassInstance(); ciClas = ci.split(patron1); ciInd = ciClas[1].split(patron2); jena.addInstanceClass(ns, ciClas[0], ciInd[0]); } while (liProperties.hasNext()) { PropertyInstances p = (PropertyInstances) liProperties.next(); String pi = p.getPropertyInstance(); piClas = pi.split(patron1); piInd = piClas[1].split(patron2); jena.addInstanceProperty(ns, piClas[0], piInd[0]); } return jena; }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof ParsedFacet)) { return false; } if (this == obj) { return true; } ParsedFacet o = (ParsedFacet) obj; if ((displayFacetName != null && o.displayFacetName == null) || (o.displayFacetName != null && displayFacetName == null)) { return false; } if (displayFacetName != null && !displayFacetName.equals(o.displayFacetName)) { return false; } if ((jcrPropertyName != null && o.jcrPropertyName == null) || (o.jcrPropertyName != null && jcrPropertyName == null)) { return false; } if (jcrPropertyName != null && !jcrPropertyName.equals(o.jcrPropertyName)) { return false; } if ((namespacedProperty != null && o.namespacedProperty == null) || (o.namespacedProperty != null && namespacedProperty == null)) { return false; } if (rangeConfig != null && !rangeConfig.equals(o.rangeConfig)) { return false; } if ((displayFacetName != null && o.displayFacetName == null) || (o.displayFacetName != null && displayFacetName == null)) { return false; } if (displayFacetName != null && !displayFacetName.equals(o.displayFacetName)) { return false; } if (facetRanges == null && o.facetRanges == null) { return true; } if ((facetRanges != null && o.facetRanges == null) || (facetRanges == null && o.facetRanges != null)) { return false; } ListIterator<FacetRange> e1 = facetRanges.listIterator(); ListIterator<FacetRange> e2 = o.facetRanges.listIterator(); while (e1.hasNext() && e2.hasNext()) { FacetRange o1 = e1.next(); FacetRange o2 = e2.next(); if (!(o1 == null ? o2 == null : o1.equals(o2))) return false; } return !(e1.hasNext() || e2.hasNext()); }
/** * Either adds a value to set or does nothing if value is already present. * * @param val Value to add. * @return The instance of value from this set or {@code null} if value was added. */ @Nullable public V addx(V val) { A.notNull(val, "val"); if (comp == null) { for (V v : vals) if (v.equals(val)) return v; vals.add(val); return null; } if (strict) { for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) { V v = it.next(); // Prefer equals to comparator. if (v.equals(val)) return v; int c = comp.compare(v, val); if (c == 0) throw new IllegalStateException("Inconsistent equals and compare methods."); if (c > 0) { // Back up. it.previous(); it.add(val); return null; } } vals.add(val); return null; } // Full scan first. for (V v : vals) if (v.equals(val)) return v; for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) { V v = it.next(); if (comp.compare(v, val) > 0) { do { // Back up. v = it.previous(); } while (comp.compare(v, val) == 0); it.add(val); return null; } } vals.add(val); return null; }
/** * Clones the object Makes a deep copy of the Valivalues form references are set to null; * * @return */ public Object clone() throws CloneNotSupportedException { Question copy = null; copy = (Question) super.clone(); // make the copy a little deeper if (getValidValues() != null) { List validValuesCopy = new ArrayList(); ListIterator it = getValidValues().listIterator(); while (it.hasNext()) { FormValidValue validValue = (FormValidValue) it.next(); FormValidValue clonedValidValue = (FormValidValue) validValue.clone(); clonedValidValue.setQuestion(copy); validValuesCopy.add(clonedValidValue); } copy.setValidValues(validValuesCopy); copy.setForm(null); copy.setModule(null); } if (getInstructions() != null) { List instructionsCopy = new ArrayList(); ListIterator it = getInstructions().listIterator(); while (it.hasNext()) { Instruction instr = (Instruction) it.next(); Instruction instrClone = (Instruction) instr.clone(); instructionsCopy.add(instrClone); } copy.setInstructions(instructionsCopy); } return copy; }
private void recurseTargets(int target, LinkedList<Integer> path, int steps) { LinkedList<Integer> tempAdj = new LinkedList<Integer>(); ListIterator<Integer> itr = this.getAdjList(target).listIterator(); while (itr.hasNext()) { int next = itr.next(); if (seen[next] == false) { tempAdj.add(next); } else { continue; } } ListIterator<Integer> itrAdj = tempAdj.listIterator(); while (itrAdj.hasNext()) { int nextNode = itrAdj.next(); seen[nextNode] = true; path.push(nextNode); if (cells.get(nextNode).isRoom() != true || cells.get(nextNode).isDoorway() == true) { if (path.size() == steps) { targets.add(cells.get(nextNode)); } else if (cells.get(nextNode).isDoorway()) { targets.add(cells.get(nextNode)); } else { recurseTargets(nextNode, path, steps); } } path.removeLast(); seen[nextNode] = false; } }
protected void setUp() throws Exception { super.setUp(); List children = getTestFixture().getDiagramEditPart().getChildren(); if (children.isEmpty()) assertFalse(true); EditPart firstEP = (EditPart) children.get(0); if (firstEP instanceof CircuitEditPart) { CircuitEditPart circuitEditPart = (CircuitEditPart) firstEP; IElementType typeLED = ElementTypeRegistry.getInstance().getType("logic.led"); // $NON-NLS-1$ Point pos = circuitEditPart.getFigure().getBounds().getBottomRight(); circuitEditPart.getFigure().translateToAbsolute(pos); pos.translate(100, 100); LEDEditPart ledEP2 = (LEDEditPart) getLogicTestFixture().createShapeUsingTool(typeLED, pos, getDiagramEditPart()); Terminal term1 = (Terminal) ((Circuit) circuitEditPart.getNotationView().getElement()) .getOutputTerminals() .get(0); TerminalEditPart tep1 = null; ListIterator li = circuitEditPart.getChildren().listIterator(); while (li.hasNext()) { IGraphicalEditPart gep = (IGraphicalEditPart) li.next(); if (gep.getNotationView().getElement().equals(term1)) tep1 = (TerminalEditPart) gep; } Terminal term2 = (Terminal) ((LED) ledEP2.getNotationView().getElement()).getInputTerminals().get(0); TerminalEditPart tep2 = null; li = ledEP2.getChildren().listIterator(); while (li.hasNext()) { IGraphicalEditPart gep = (IGraphicalEditPart) li.next(); if (gep.getNotationView().getElement().equals(term2)) tep2 = (TerminalEditPart) gep; } IElementType typeWire = ElementTypeRegistry.getInstance().getType("logic.wire"); // $NON-NLS-1$ getLogicTestFixture().createConnectorUsingTool(tep1, tep2, typeWire); IGraphicalEditPart logicCompartment = circuitEditPart.getChildBySemanticHint(LogicConstants.LOGIC_SHAPE_COMPARTMENT); Rectangle rect = new Rectangle(logicCompartment.getFigure().getBounds()); logicCompartment.getFigure().translateToAbsolute(rect); CreateRequest request = getLogicTestFixture().getCreationRequest(typeLED); request.setLocation(rect.getCenter()); Command cmd = logicCompartment.getCommand(request); getCommandStack().execute(cmd); assertEquals( "Unexpected LED count.", 1, logicCompartment.getChildren().size()); // $NON-NLS-1$ } }
private TextFilePatch readPatch(String curLine, ListIterator<String> iterator) throws PatchSyntaxException { final TextFilePatch curPatch = mySaveHunks ? new TextFilePatch(null) : new EmptyTextFilePatch(); extractFileName(curLine, curPatch, true, myDiffCommandLike && myIndexLike); if (!iterator.hasNext()) throw new PatchSyntaxException(iterator.previousIndex(), "Second file name expected"); curLine = iterator.next(); String secondNamePrefix = myDiffFormat == DiffFormat.UNIFIED ? "+++ " : "--- "; if (!curLine.startsWith(secondNamePrefix)) { throw new PatchSyntaxException(iterator.previousIndex(), "Second file name expected"); } extractFileName(curLine, curPatch, false, myDiffCommandLike && myIndexLike); while (iterator.hasNext()) { PatchHunk hunk; if (myDiffFormat == DiffFormat.UNIFIED) { hunk = readNextHunkUnified(iterator); } else { hunk = readNextHunkContext(iterator); } if (hunk == null) break; curPatch.addHunk(hunk); } if (curPatch.getBeforeName() == null) { curPatch.setBeforeName(curPatch.getAfterName()); } if (curPatch.getAfterName() == null) { curPatch.setAfterName(curPatch.getBeforeName()); } return curPatch; }
public static void main(String args[]) { ArrayList<Integer> numList = new ArrayList<Integer>(); for (int i = 1; i <= 5; i++) { numList.add(i); } System.out.println("Size of Array List is " + numList.size()); System.out.println("List elements"); ListIterator<Integer> li = numList.listIterator(); for (; li.hasNext(); ) { Integer num = li.next(); System.out.println(num); } System.out.println("List elements in reverse"); for (; li.hasPrevious(); ) { Integer num = li.previous(); System.out.println(num); } LinkedList<String> strList = new LinkedList<String>(); strList.add("abc"); strList.add("def"); strList.add("abc"); strList.add("ghi"); System.out.println("Index of abc is: " + strList.indexOf("abc")); System.out.println("Size of Linked List is " + strList.size()); strList.remove("abc"); for (ListIterator<String> ls = strList.listIterator(); ls.hasNext(); ) { String str = ls.next(); System.out.println(str); } }
/** Check the 2 lists comparing the rows in order. If they are not the same fail the test. */ public void checkRows(List<RowMetaAndData> rows1, List<RowMetaAndData> rows2) { if (rows1.size() != rows2.size()) { fail("Number of rows is not the same: " + rows1.size() + " and " + rows2.size()); } ListIterator<RowMetaAndData> it1 = rows1.listIterator(); ListIterator<RowMetaAndData> it2 = rows2.listIterator(); while (it1.hasNext() && it2.hasNext()) { RowMetaAndData rm1 = it1.next(); RowMetaAndData rm2 = it2.next(); Object[] r1 = rm1.getData(); Object[] r2 = rm2.getData(); if (rm1.size() != rm2.size()) { fail("row nr " + it1.nextIndex() + " is not equal"); } int[] fields = new int[r1.length]; for (int ydx = 0; ydx < r1.length; ydx++) { fields[ydx] = ydx; } try { if (rm1.getRowMeta().compare(r1, r2, fields) != 0) { fail("row nr " + it1.nextIndex() + " is not equal"); } } catch (KettleValueException e) { fail("row nr " + it1.nextIndex() + " is not equal"); } } }
@Override protected void createUpcomingSelection() { if (!rightSubSelectionIterator.hasNext()) { if (!leftSubSelectionIterator.hasNext()) { upcomingSelection = null; return; } leftSubSelection = leftSubSelectionIterator.next(); if (!leftEqualsRight) { rightSubSelectionIterator = rightSubSelector.listIterator(); if (!rightSubSelectionIterator.hasNext()) { upcomingSelection = null; return; } } else { // Select A-B, A-C, B-C. Do not select B-A, C-A, C-B. Do not select A-A, B-B, C-C. if (!leftSubSelectionIterator.hasNext()) { upcomingSelection = null; return; } rightSubSelectionIterator = rightSubSelector.listIterator(leftSubSelectionIterator.nextIndex()); // rightEntityIterator's first hasNext() always returns true because of the nextIndex() } } SubS rightSubSelection = rightSubSelectionIterator.next(); upcomingSelection = newSwapSelection(leftSubSelection, rightSubSelection); }
public void paint(Graphics g) { // clear field super.paint(g); // draw grid lines g.setColor(Color.DARK_GRAY); gridXIter = gridX.listIterator(); while (gridXIter.hasNext()) { int x = gridXIter.next(); g.drawLine(x, 0, x, getHeight()); } gridYIter = gridY.listIterator(); while (gridYIter.hasNext()) { int y = gridYIter.next(); g.drawLine(0, y, getWidth(), y); } // draw objects ListIterator<PhysicsObject> iter = Universe.allObjects.listIterator(); while (iter.hasNext()) { PhysicsObject obj = iter.next(); int x = (int) (obj.getX() * pixelsPerMeter + origin.x); int y = (int) (obj.getY() * pixelsPerMeter + origin.y); g.fillOval(x - 5, y - 5, 10, 10); // TODO update for non-point objects } }
/** * clone a copy of oclOperator * * @throws CloneNotSupportedException * @return Object */ public Object clone() throws CloneNotSupportedException { try { oclEvent op = new oclEvent(); op.opName = (oclPredicate) opName.clone(); ListIterator li = prevail.listIterator(); while (li.hasNext()) { oclSE se = (oclSE) li.next(); op.addPrevSE((oclSE) se.clone()); } li = necessary.listIterator(); while (li.hasNext()) { oclSC sc = (oclSC) li.next(); op.addNecSC((oclSC) sc.clone()); } li = conditional.listIterator(); while (li.hasNext()) { oclSC sc = (oclSC) li.next(); op.addCondSC((oclSC) sc.clone()); } return op; } catch (CloneNotSupportedException e) { Utility.debugPrintln("Failed to clone event component + " + e.toString()); throw e; } }
public void semanticCheck(Semantics semantics) { semantics.scopeStack.push(Semantics.ScopeType.If); this.condition.semanticCheck(semantics); ListIterator<Stmt> trueStatements = this.whenTrue.listIterator(); ListIterator<Stmt> falseStatements = this.whenFalse.listIterator(); while (trueStatements.hasNext()) { Stmt statement = trueStatements.next(); statement.semanticCheck(semantics); } while (falseStatements.hasNext()) { Stmt statement = falseStatements.next(); statement.semanticCheck(semantics); } Type type = new BooleanType(this.getLineNumber()); if (this.condition.getType() == null || !this.condition.getType().getClass().equals(type.getClass())) { SemanticError error = new SemanticError("If condition is not of type Boolean", this.getLineNumber()); semantics.errorList.add(error); } semantics.scopeStack.pop(); }
private void initialize(final LGraph graph) { layeredGraph = graph; int layerCount = graph.getLayers().size(); bestNodeOrder = new LNode[layerCount][]; currentNodeOrder = new LNode[layerCount][]; originalNodeOrder = new LNode[layerCount][]; ListIterator<Layer> layerIter = graph.getLayers().listIterator(); while (layerIter.hasNext()) { Layer layer = layerIter.next(); int layerNodeCount = layer.getNodes().size(); assert layerNodeCount > 0; int layerIndex = layerIter.previousIndex(); bestNodeOrder[layerIndex] = new LNode[layerNodeCount]; currentNodeOrder[layerIndex] = new LNode[layerNodeCount]; originalNodeOrder[layerIndex] = new LNode[layerNodeCount]; ListIterator<LNode> nodeIter = layer.getNodes().listIterator(); int id = 0; while (nodeIter.hasNext()) { LNode node = nodeIter.next(); node.id = id++; currentNodeOrder[layerIndex][nodeIter.previousIndex()] = node; bestNodeOrder[layerIndex][nodeIter.previousIndex()] = node; originalNodeOrder[layerIndex][nodeIter.previousIndex()] = node; } } crossingCounter = new AllCrossingsCounter(currentNodeOrder); if (greedySwitchType.useHyperedgeCounter()) { crossingCounter.useHyperedgeCounter(); } }
public String toString() { String str = "PDepNetwork #" + Integer.toString(id) + ":\n"; str += "\tIsomers:\n"; for (ListIterator<PDepIsomer> iter = isomerList.listIterator(); iter.hasNext(); ) { PDepIsomer isomer = iter.next(); str += "\t\t" + isomer.toString() + "\n"; } str += "\tPath reactions:\n"; for (ListIterator<PDepReaction> iter = pathReactionList.listIterator(); iter.hasNext(); ) { PDepReaction rxn = iter.next(); str += "\t\t" + rxn.toString() + "\n"; } str += "\tNet reactions:\n"; for (ListIterator<PDepReaction> iter = netReactionList.listIterator(); iter.hasNext(); ) { PDepReaction rxn = iter.next(); str += "\t\t" + rxn.toString() + "\n"; } str += "\tNonincluded reactions:\n"; for (ListIterator<PDepReaction> iter = nonincludedReactionList.listIterator(); iter.hasNext(); ) { PDepReaction rxn = iter.next(); str += "\t\t" + rxn.toString() + "\n"; } return str; }
void computeIn(LinkedList<Vertex> worklist) { int i; BitSet old; BitSet ne; Vertex v; ListIterator<Vertex> iter; iter = succ.listIterator(); while (iter.hasNext()) { v = iter.next(); out.or(v.in); } old = in; in = new BitSet(); in.or(out); in.andNot(def); in.or(use); if (!in.equals(old)) { iter = pred.listIterator(); while (iter.hasNext()) { v = iter.next(); if (!v.listed) { worklist.addLast(v); v.listed = true; } } } }
/** * 合并数字 * * @param termList */ protected void mergeNumberQuantifier(List<Vertex> termList) { if (termList.size() < 4) return; StringBuilder sbQuantifier = new StringBuilder(); ListIterator<Vertex> iterator = termList.listIterator(); iterator.next(); while (iterator.hasNext()) { Vertex pre = iterator.next(); if (pre.hasNature(Nature.m)) { sbQuantifier.append(pre.realWord); Vertex cur = null; while (iterator.hasNext() && (cur = iterator.next()).hasNature(Nature.m)) { sbQuantifier.append(cur.realWord); iterator.remove(); } if (cur != null && (cur.hasNature(Nature.q) || cur.hasNature(Nature.qv) || cur.hasNature(Nature.qt))) { sbQuantifier.append(cur.realWord); pre.attribute = new CoreDictionary.Attribute(Nature.mq); iterator.remove(); } if (sbQuantifier.length() != pre.realWord.length()) { pre.realWord = sbQuantifier.toString(); sbQuantifier.setLength(0); } } } }
/** * Writes the byte stream of PCEP error to the channel buffer. * * @param cb of type channel buffer * @return object length index * @throws PcepParseException if mandatory fields are missing */ @Override public int write(ChannelBuffer cb) throws PcepParseException { int iLenStartIndex = cb.writerIndex(); // RPlist is optional if (this.isErroInfoSet) { ListIterator<PcepRPObject> rpObjlistIterator = this.llRPObjList.listIterator(); while (rpObjlistIterator.hasNext()) { rpObjlistIterator.next().write(cb); } } // TElist is optional if (this.isTEObjListSet) { ListIterator<PcepTEObject> teObjlistIterator = this.llTEObjList.listIterator(); while (teObjlistIterator.hasNext()) { teObjlistIterator.next().write(cb); } } // ErrList is mandatory ListIterator<PcepErrorObject> errlistIterator = this.llErrObjList.listIterator(); while (errlistIterator.hasNext()) { errlistIterator.next().write(cb); } return cb.writerIndex() - iLenStartIndex; }
public PagerItem[] getItems(int startIdx, int numItems) throws Exception { // System.err.println( "getItems(): startIdx = " + startIdx + // ", numItems = " + numItems ); int pis = startIdx + numItems; _sc.setStartAt(new Integer(startIdx + 1)); _sc.setMaxRecordset(new Integer(numItems)); SearchResult sr = _cache.get(_sc); if (sr == null) { sr = _sc.search(); _cache.put(_sc, sr); } _objects = Arrays.asList(sr.getResultSet()); // System.err.println( "_objects.size() = " + _objects.size() ); pis = Math.min(_objects.size(), numItems); if (pis < 0) { pis = 0; } // System.err.println( "pis = " + pis ); PagerItem[] items = new PagerItem[pis]; SearchableObject so = _sod.getSearchableObject(_sc.getBeanName()); for (int i = 0; i < items.length; i++) { // Object obj = _objects.get( startIdx + i ); Object obj = _objects.get(i); Object idObj = CaBIOUtils.getProperty(obj, "id"); String id = (idObj != null ? idObj.toString() : ""); // System.err.println( "creating pi for " + obj.getClass().getName() + ":" + id ); List labelProps = so.getLabelProperties(); List assocs = getNavigableAssociations(so); List vals = new ArrayList(); for (ListIterator j = labelProps.listIterator(); j.hasNext(); ) { Object val = CaBIOUtils.getProperty(obj, ((String) j.next()).trim()); if (val != null) { vals.add(val.toString()); } else { vals.add(""); } } if (_eventHandler != null) { for (ListIterator j = assocs.listIterator(); j.hasNext(); ) { Association assoc = (Association) j.next(); vals.add( "<a href=\"javascript:" + _eventHandler + "('" + obj.getClass().getName() + "', '" + id + "', '" + assoc.getRole() + "')\">" + assoc.getLabel() + getCountString(obj, assoc.getRole()) + "</a>"); } } items[i] = new PagerItemImpl(id, (String[]) vals.toArray(new String[vals.size()])); } return items; }