コード例 #1
1
ファイル: Dom.java プロジェクト: hk2-project/hk2
  /**
   * 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;
  }
コード例 #2
1
ファイル: List1.java プロジェクト: TopCombine/ThinkingInJava
 // Must move to an element after add():
 // it.next(); // Remove the element that was just produced:
 // it.remove(); // Must move to an element after remove():
 // it.next(); // Change the element that was just produced:
 // it.set("47");
 public static void testVisual(List a) {
   print(a);
   List b = new ArrayList();
   fill(b);
   System.out.print("b = ");
   print(b);
   a.addAll(b);
   a.addAll(fill(new ArrayList()));
   print(a);
   // Shrink the list by removing all the elements beyond the first 1/2 of the list
   System.out.println(a.size());
   System.out.println(a.size() / 2);
   // a.removeRange(a.size()/2, a.size()/2 + 2);
   print(a);
   // Insert, remove, and replace elements
   // using aListIterator:
   ListIterator x = a.listIterator(a.size() / 2);
   x.add("one");
   print(a);
   System.out.println(x.next());
   x.remove();
   System.out.println(x.next());
   x.set("47");
   print(a); // Traverse the list backwards:
   x = a.listIterator(a.size());
   while (x.hasPrevious()) System.out.print(x.previous() + " ");
   System.out.println();
   System.out.println("testVisual finished");
 }
コード例 #3
0
ファイル: Segment.java プロジェクト: zhoufeng/HanLP
 /**
  * 合并数字
  *
  * @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);
       }
     }
   }
 }
    private void addCriteriaMethods(TopLevelClass topLevelClass, int newMethodsStart) {
        if (!generateCriteriaMethods) return;
        InnerClass criteria = null;
        for (InnerClass c : topLevelClass.getInnerClasses()) {
            if (c.getType().getShortName().equals("Criteria")) criteria = c;
        }
        if (criteria == null) return;
        boolean owner = false;
        for (Field f : criteria.getFields()) if (ExampleMethodsChainPlugin.OWNER.equals(f.getName())) owner = true;
        if (!owner) return;

        for (ListIterator<Method> methods = topLevelClass.getMethods().listIterator(newMethodsStart); methods.hasNext(); ) {
            Method base = methods.next();
            if (base.getVisibility() != PUBLIC || base.isStatic() || base.isConstructor()) continue;
            Method m = method(PUBLIC, base.getReturnType(), base.getName());
            StringBuilder sb = new StringBuilder();
            sb.append("return ").append(ExampleMethodsChainPlugin.OWNER).append(".").append(base.getName()).append("(");
            for (ListIterator<Parameter> params = base.getParameters().listIterator(); params.hasNext(); ) {
                if (params.hasPrevious()) sb.append(", ");
                Parameter p = params.next();
                m.addParameter(new Parameter(p.getType(), p.getName()));
                sb.append(p.getName());
            }
            sb.append(");");
            m.addBodyLine(sb.toString());
            criteria.addMethod(m);
        }
    }
コード例 #5
0
  private List<ChatMessage> sanitizeMap(final SortedMap<Date, ChatMessage> aMap) {
    if (aMap.isEmpty() || aMap.size() == 1) return Lists.newArrayList(aMap.values());

    final LinkedList<ChatMessage> ret = Lists.newLinkedList(aMap.values());
    final ListIterator<ChatMessage> i = ret.listIterator();
    ChatMessage prevMsg = i.next();
    do {
      ChatMessage msg = i.next();
      if (!msg.getPreviousMessageDate().equals(prevMsg.getDate())) {
        if (msg.getPreviousMessageDate().before(prevMsg.getDate())) {
          msg.setPreviousMessageDate(prevMsg.getDate());
        } else {
          final ChatMessage tmp =
              createLostMessageBetween(
                  msg.getRoom(), prevMsg.getDate(), msg.getPreviousMessageDate());
          aMap.put(tmp.getDate(), tmp);
          i.previous();
          i.add(tmp);
          i.next();
          msg = tmp;
        }
      }
      prevMsg = msg;
    } while (i.hasNext());

    return ret;
  }
コード例 #6
0
ファイル: oclEvent.java プロジェクト: carriercomm/PrologMUD
  /**
   * 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;
    }
  }
コード例 #7
0
  @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);
  }
コード例 #8
0
 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);
   }
 }
コード例 #9
0
  /** 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");
      }
    }
  }
コード例 #10
0
 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;
   }
 }
  public void testAddUniqueConstraint2() throws Exception {
    createTestEntityWithElementCollection();
    addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME);

    JavaElementCollectionMapping2_0 elementCollectionMapping =
        (JavaElementCollectionMapping2_0)
            getJavaPersistentType().getAttributes().iterator().next().getMapping();
    CollectionTable2_0 collectionTable = elementCollectionMapping.getCollectionTable();
    collectionTable.addUniqueConstraint(0).addColumnName(0, "FOO");
    collectionTable.addUniqueConstraint(1).addColumnName(0, "BAR");
    collectionTable.addUniqueConstraint(0).addColumnName(0, "BAZ");

    JavaResourceType resourceType =
        (JavaResourceType)
            getJpaProject().getJavaResourceType(FULLY_QUALIFIED_TYPE_NAME, AstNodeType.TYPE);
    JavaResourceField resourceField = resourceType.getFields().iterator().next();
    CollectionTableAnnotation2_0 joinTableAnnotation =
        (CollectionTableAnnotation2_0)
            resourceField.getAnnotation(CollectionTableAnnotation2_0.ANNOTATION_NAME);
    ListIterator<UniqueConstraintAnnotation> uniqueConstraints =
        joinTableAnnotation.getUniqueConstraints().iterator();

    assertEquals("BAZ", uniqueConstraints.next().columnNameAt(0));
    assertEquals("FOO", uniqueConstraints.next().columnNameAt(0));
    assertEquals("BAR", uniqueConstraints.next().columnNameAt(0));
    assertFalse(uniqueConstraints.hasNext());
  }
コード例 #12
0
  /**
   * 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;
  }
コード例 #13
0
ファイル: Components.java プロジェクト: gotomypc/zk
  /**
   * 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]);
  }
コード例 #14
0
 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;
 }
コード例 #15
0
ファイル: ParsedFacet.java プロジェクト: srajeev/hippo
  @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());
  }
コード例 #16
0
  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$
    }
  }
コード例 #17
0
  /**
   * 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;
  }
コード例 #18
0
  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
    }
  }
コード例 #19
0
  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();
  }
  @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());
  }
コード例 #21
0
ファイル: ResourceManager.java プロジェクト: rtitec/swixml2
  /* 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);
    }
  }
コード例 #22
0
ファイル: TDISHandler.java プロジェクト: hexbinary/landing
  // recheck the abnormal status of the last 'n' labs
  private void updateLabStatus(int n) {
    Hl7TextInfoDao hl7TextInfoDao = (Hl7TextInfoDao) SpringUtils.getBean("hl7TextInfoDao");
    List<Hl7TextInfo> labList = hl7TextInfoDao.getAllLabsByLabNumberResultStatus();
    ListIterator<Hl7TextInfo> iter = labList.listIterator();

    while (iter.hasNext() && n > 0) {
      if (!iter.next().getResultStatus().equals("A")) {
        oscar.oscarLab.ca.all.parsers.MessageHandler h =
            Factory.getHandler(((Integer) iter.next().getLabNumber()).toString());

        int i = 0;
        int j = 0;
        String resultStatus = "";
        while (resultStatus.equals("") && i < h.getOBRCount()) {
          j = 0;
          while (resultStatus.equals("") && j < h.getOBXCount(i)) {
            logger.info("obr(" + i + ") obx(" + j + ") abnormal ? : " + h.getOBXAbnormalFlag(i, j));
            if (h.isOBXAbnormal(i, j)) {
              resultStatus = "A";
              hl7TextInfoDao.updateResultStatusByLabId("A", iter.next().getLabNumber());
            }
            j++;
          }
          i++;
        }
      }
      n--;
    }
  }
コード例 #23
0
ファイル: oclEvent.java プロジェクト: carriercomm/PrologMUD
 /**
  * to print the current oclOperator to a PrintWriter.
  *
  * @param ps PrintWriter
  * @param indent value of indentation
  * @param nline not being used really
  * @return void
  */
 public void oclPrintComponent(PrintWriter ps, int indent, boolean nline) {
   if (docm.size() > 0) {
     ps.println("/****");
     ListIterator liDoc = docm.listIterator();
     while (liDoc.hasNext()) {
       ps.print(" * ");
       ps.println((String) liDoc.next());
     }
     ps.println(" */");
   }
   ps.print("event(");
   opName.oclPrintComponent(ps, 0, false);
   // opName.oclSortedPrint(ps, 0, false);
   ps.println(",\n    % prevail");
   ps.print("    [");
   ListIterator li = prevail.listIterator();
   while (li.hasNext()) {
     ((oclSE) li.next()).oclPrintComponent(ps, 5, false);
     if (li.hasNext()) ps.println(",");
   }
   ps.print("],\n    % necessary\n    [");
   li = necessary.listIterator();
   while (li.hasNext()) {
     ((oclSC) li.next()).oclPrintComponent(ps, 5, false);
     if (li.hasNext()) ps.println(",");
   }
   ps.print("],\n    % conditional\n    [");
   li = conditional.listIterator();
   while (li.hasNext()) {
     ((oclSC) li.next()).oclPrintComponent(ps, 5, false);
     if (li.hasNext()) ps.println(",");
   }
   ps.println("]).");
 }
コード例 #24
0
ファイル: PDepNetwork.java プロジェクト: cfgold/RMG-Java
 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;
 }
コード例 #25
0
  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();
    }
  }
コード例 #26
0
  /**
   * 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;
  }
コード例 #27
0
 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));
   }
 }
コード例 #28
0
  @Override
  @Test
  public void listIterator() {
    super.listIterator();
    CompositeFastList<String> composite = new CompositeFastList<String>();
    FastList<String> firstBit = FastList.newListWith("one", "two");
    FastList<String> secondBit = FastList.newListWith("three");
    composite.addAll(firstBit);
    composite.addAll(secondBit);

    ListIterator<String> listIterator = composite.listIterator();
    listIterator.add("four");
    Verify.assertSize(4, composite);
    Assert.assertTrue(listIterator.hasNext());
    String element = listIterator.next();

    Assert.assertEquals("one", element);

    String element3 = listIterator.next();

    Assert.assertEquals("two", element3);

    String element2 = listIterator.previous();
    Assert.assertEquals("two", element2);

    String element1 = listIterator.next();

    Assert.assertEquals("two", element1);

    listIterator.remove();

    Verify.assertSize(3, composite);
  }
コード例 #29
0
ファイル: Dataflow.java プロジェクト: JohanJu/Multicore
 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;
       }
     }
   }
 }
コード例 #30
0
  /**
   * 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;
  }