Пример #1
1
 // 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");
 }
Пример #2
1
  /**
   * 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;
  }
  /**
   * Copies all of the elements from one list into another. After the operation, the index of each
   * copied element in the destination list will be identical to its index in the source list. The
   * destination list must be at least as long as the source list. If it is longer, the remaining
   * elements in the destination list are unaffected.
   *
   * <p>This method runs in linear time.
   *
   * @param <T> .
   * @param dest The destination list.
   * @param src The source list.
   * @return boolean isCopyValide
   */
  public static <T> Boolean copy(List<? super T> dest, List<? extends T> src) {

    Boolean isCopyValide = null;

    int srcSize = src.size();
    if (srcSize > dest.size()) {
      isCopyValide = false;
      throw new IndexOutOfBoundsException("Source does not fit in dest");
    }

    if (srcSize < COPY_THRESHOLD || (src instanceof RandomAccess && dest instanceof RandomAccess)) {
      for (int i = 0; i < srcSize; i++) {
        dest.set(i, src.get(i));
      }
    } else {
      ListIterator<? super T> di = dest.listIterator();
      ListIterator<? extends T> si = src.listIterator();
      for (int i = 0; i < srcSize; i++) {
        di.next();
        di.set(si.next());
      }
    }

    isCopyValide = true;

    return isCopyValide;
  }
Пример #4
0
  public Vector _clone_sort(Vector dati, Vector dati_cr) {
    Vector result = new Vector();
    Vector index = new Vector();
    for (int i = 0; i < dati_cr.size(); i++) index.add(new Integer(i));
    try {

      Object a[] = dati_cr.toArray();
      Object a_index[] = index.toArray();
      Object src_index[] = (Object[]) a_index.clone();
      Object src[] = (Object[]) a.clone();
      _clone_mergeSort(src, a, 0, a.length, src_index, a_index);
      ListIterator li = dati_cr.listIterator();
      ListIterator l_index = index.listIterator();
      for (int j = 0; j < a.length; j++) {
        li.next();
        li.set(a[j]);
        l_index.next();
        l_index.set(a_index[j]);
      }
    } catch (Exception e) {
      e.toString();
    }

    for (int i = 0; i < index.size(); i++)
      result.add(dati.elementAt(((Integer) index.elementAt(i)).intValue()));
    return result;
  }
  /** Test remove() for an immutable ListIterator. */
  public void testUnmodifiableListIteratorImmutability() {
    ListIterator listIterator = getImmutableListIterator();

    try {
      listIterator.remove();
      // We shouldn't get to here.
      fail("remove() should throw an UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // This is correct; ignore the exception.
    }

    try {
      listIterator.set("a");
      // We shouldn't get to here.
      fail("set(Object) should throw an UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // This is correct; ignore the exception.
    }

    try {
      listIterator.add("a");
      // We shouldn't get to here.
      fail("add(Object) should throw an UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // This is correct; ignore the exception.
    }

    listIterator.next();

    try {
      listIterator.remove();
      // We shouldn't get to here.
      fail("remove() should throw an UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // This is correct; ignore the exception.
    }

    try {
      listIterator.set("a");
      // We shouldn't get to here.
      fail("set(Object) should throw an UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // This is correct; ignore the exception.
    }

    try {
      listIterator.add("a");
      // We shouldn't get to here.
      fail("add(Object) should throw an UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
      // This is correct; ignore the exception.
    }
  }
Пример #6
0
 /** Moves head of the snake left with all its body */
 private void moveLeft() {
   ListIterator<Point> it = this.body.listIterator();
   Point tmp1, tmp2;
   tmp1 = it.next();
   tmp2 = new Point(tmp1.x - 1, tmp1.y);
   it.set(tmp2);
   tmp2 = tmp1;
   while (it.hasNext()) {
     tmp1 = it.next();
     it.set(tmp2);
     tmp2 = tmp1;
   }
 }
Пример #7
0
 public static void reverse(MyLinkedList list) {
   int size = list.size();
   if (size == 0 || size == 1) {
     return;
   }
   ListIterator<Object> iterForward = list.listIterator(0);
   ListIterator<Object> iterBackward = list.listIterator(size - 1);
   for (int i = 0; i < size / 2; i++) {
     Object temp = iterForward.next();
     iterForward.set(iterBackward.previous());
     iterBackward.set(temp);
   }
 }
Пример #8
0
  /**
   * When this method is called group name is changed, so also is the group name belonging to the
   * view. Also overwrites the "groups.xml" file
   *
   * @param oldName a {@link java.lang.String} object.
   * @param newName a {@link java.lang.String} object.
   * @throws java.lang.Exception if any.
   */
  public synchronized void renameUser(String oldName, String newName) throws Exception {
    // Get the old data
    if (oldName == null || newName == null || oldName == "" || newName == "") {
      throw new Exception("Group Factory: Rename user.. no value ");
    } else {
      Map<String, Group> map = new LinkedHashMap<String, Group>();

      for (Group group : m_groups.values()) {
        for (ListIterator<String> userList = group.getUserCollection().listIterator();
            userList.hasNext(); ) {
          String name = userList.next();

          if (name.equals(oldName)) {
            userList.set(newName);
          }
        }
        map.put(group.getName(), group);
      }

      m_groups.clear();
      m_groups.putAll(map);

      for (Role role : m_roles.values()) {
        for (Schedule sched : role.getScheduleCollection()) {
          if (oldName.equals(sched.getName())) {
            sched.setName(newName);
          }
        }
      }

      saveGroups();
    }
  }
Пример #9
0
 /**
  * Substitute exprs of the form "<number>" with the corresponding expressions from select list
  *
  * @param exprs
  * @param errorPrefix
  * @throws AnalysisException
  */
 @Override
 protected void substituteOrdinals(List<Expr> exprs, String errorPrefix) throws AnalysisException {
   // substitute ordinals
   ListIterator<Expr> i = exprs.listIterator();
   while (i.hasNext()) {
     Expr expr = i.next();
     if (!(expr instanceof IntLiteral)) {
       continue;
     }
     long pos = ((IntLiteral) expr).getValue();
     if (pos < 1) {
       throw new AnalysisException(errorPrefix + ": ordinal must be >= 1: " + expr.toSql());
     }
     if (pos > selectList.getItems().size()) {
       throw new AnalysisException(
           errorPrefix + ": ordinal exceeds number of items in select list: " + expr.toSql());
     }
     if (selectList.getItems().get((int) pos - 1).isStar()) {
       throw new AnalysisException(
           errorPrefix + ": ordinal refers to '*' in select list: " + expr.toSql());
     }
     // create copy to protect against accidentally shared state
     i.set(selectList.getItems().get((int) pos - 1).getExpr().clone(null));
   }
 }
Пример #10
0
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._deNum_ == oldChild) {
      setDeNum((TNumeroInteiro) newChild);
      return;
    }

    if (this._ateNum_ == oldChild) {
      setAteNum((TNumeroInteiro) newChild);
      return;
    }

    for (ListIterator<PComandos> i = this._comandos_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((PComandos) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    throw new RuntimeException("Not a child.");
  }
  /**
   * Replaces all instances of URI values with their label (as a string)
   *
   * @param data
   * @param eng
   * @return the data list (the <code>data</code> argument), for convenience
   */
  public static List<Value[]> convertUrisToLabels(List<Value[]> data, IEngine eng) {
    Set<URI> needLabels = new HashSet<>();

    for (Value[] valarr : data) {
      for (Value v : valarr) {
        if (v instanceof URI) {
          needLabels.add(URI.class.cast(v));
        }
      }
    }

    Map<URI, String> labels = Utility.getInstanceLabels(needLabels, eng);
    ListIterator<Value[]> valit = data.listIterator();
    while (valit.hasNext()) {
      Value[] valarr = valit.next();
      for (int i = 0; i < valarr.length; i++) {
        if (valarr[i] instanceof URI) {
          valarr[i] = new LiteralImpl(labels.get(URI.class.cast(valarr[i])));
        }
      }
      valit.set(valarr);
    }

    return data;
  }
Пример #12
0
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._quad_ == oldChild) {
      setQuad((TQuad) newChild);
      return;
    }

    for (ListIterator<TId> i = this._path_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((TId) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    if (this._id_ == oldChild) {
      setId((TId) newChild);
      return;
    }

    throw new RuntimeException("Not a child.");
  }
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._classOrInterfaceType_ == oldChild) {
      setClassOrInterfaceType((PClassOrInterfaceType) newChild);
      return;
    }

    for (ListIterator<PDim> i = this._dim_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((PDim) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    if (this._arrayInitializer_ == oldChild) {
      setArrayInitializer((PArrayInitializer) newChild);
      return;
    }

    throw new RuntimeException("Not a child.");
  }
Пример #14
0
 public TemplateFile(
     NamespaceDeclaration namespace,
     List<AliasDeclaration> aliases,
     List<TemplateDeclaration> templates) {
   this.namespace = namespace;
   this.aliases = aliases;
   if (namespace != null && templates != null) {
     List<TemplateDeclaration> buffer = new LinkedList<TemplateDeclaration>(templates);
     for (ListIterator<TemplateDeclaration> iter = templates.listIterator(); iter.hasNext(); ) {
       TemplateDeclaration t = iter.next();
       BeginTemplateTag btt = t.getBeginTag();
       iter.set(
           new TemplateDeclaration(
               t.getTemplateDocComment(),
               new ContentTagPair(
                   new BeginTemplateTag(btt.getName(), namespace, btt.getAttributes()),
                   t.getEndTag(),
                   t.getContents())));
     }
     this.templates = Collections.unmodifiableList(buffer);
   } else if (templates != null) {
     this.templates = Collections.unmodifiableList(templates);
   } else {
     this.templates = Collections.emptyList();
   }
 }
Пример #15
0
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._className_ == oldChild) {
      setClassName((TId) newChild);
      return;
    }

    if (this._super_ == oldChild) {
      setSuper((TId) newChild);
      return;
    }

    for (ListIterator<PVarDecl> i = this._varDecl_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((PVarDecl) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    for (ListIterator<PMethodDecl> i = this._methodDecl_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((PMethodDecl) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    throw new RuntimeException("Not a child.");
  }
Пример #16
0
  @Override
  void replaceChild(
      @SuppressWarnings("unused") Node oldChild, @SuppressWarnings("unused") Node newChild) {
    // Replace child
    if (this._position_ == oldChild) {
      setPosition((PPosition) newChild);
      return;
    }

    for (ListIterator<TWord> i = this._macro_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((TWord) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    for (ListIterator<PVariable> i = this._arguments_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set((PVariable) newChild);
          newChild.parent(this);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    if (this._command_ == oldChild) {
      setCommand((PCommand) newChild);
      return;
    }

    throw new RuntimeException("Not a child.");
  }
Пример #17
0
  /**
   * ************* 添加指定回合的本时间节点的任务,返回是否添加成功,不成功则表示需要马上执行
   *
   * @author alzq.z
   * @time Jul 16, 2015 11:26:06 PM
   */
  public boolean addTimingTask(int _round, _IALSynTask _task) {
    _lock();

    try {
      if (null == _task) return false;

      // 当本回合的时候,直接进行添加
      if (_round == _m_iCurRound) {
        _m_lCurRoundTimingTaskList.add(_task);
        return true;
      } else if (_round == _m_iNextRound) {
        _m_lNextRoundTimingTaskList.add(_task);
        return true;
      } else if (_round > _m_iNextRound) {
        // 长时间延迟的任务,按照回合顺序放入对应队列
        ListIterator<ALSynTimingTaskNodeFarDelayTaskInfo> iterator =
            _m_lFarDelayTaskList.listIterator();
        while (iterator.hasNext()) {
          ALSynTimingTaskNodeFarDelayTaskInfo taskInfo = iterator.next();
          if (taskInfo.getRound() == _round) {
            // 匹配回合则加入本节点
            taskInfo.addSynTask(_task);
            break;
          } else if (taskInfo.getRound() < _round) {
            // 当插入的回合比对应回合早,则需要在对应回合之前插入数据
            // 这里采用的做法是将本节点数据重复插入到下一个节点,之后将本节点设置为新数据
            iterator.add(taskInfo);

            // 创建新节点
            ALSynTimingTaskNodeFarDelayTaskInfo newInfo =
                new ALSynTimingTaskNodeFarDelayTaskInfo(_round);
            iterator.set(newInfo);
            // 插入任务
            newInfo.addSynTask(_task);
            break;
          }
        }

        // 判断是否已经到了最后节点
        if (!iterator.hasNext()) {
          // 在最后节点则往最后追加数据
          // 创建新节点
          ALSynTimingTaskNodeFarDelayTaskInfo newInfo =
              new ALSynTimingTaskNodeFarDelayTaskInfo(_round);
          iterator.add(newInfo);
          // 插入任务
          newInfo.addSynTask(_task);
        }

        return true;
      } else {
        // 当回合小于当前回合则表示失败,外部需要直接处理
        return false;
      }
    } finally {
      _unlock();
    }
  }
Пример #18
0
 public CachedCxfPayload(CxfPayload<T> orig, Exchange exchange, XmlConverter xml) {
   super(orig.getHeaders(), new ArrayList<Source>(orig.getBodySources()), orig.getNsMap());
   ListIterator<Source> li = getBodySources().listIterator();
   this.xml = xml;
   while (li.hasNext()) {
     Source source = li.next();
     XMLStreamReader reader = null;
     // namespace definitions that are on the SOAP envelope can get lost, if this is
     // not a DOM (there is special coding on the CXFPayload.getBody().get() method for
     // this, that only works on DOM nodes.
     // We have to do some delegation on the XMLStreamReader for StAXSource and StaxSource
     // that re-injects the missing namespaces into the XMLStreamReader.
     // Replace all other Sources that are not DOMSources with DOMSources.
     if (source instanceof StaxSource) {
       reader = ((StaxSource) source).getXMLStreamReader();
     } else if (source instanceof StAXSource) {
       reader = ((StAXSource) source).getXMLStreamReader();
     }
     if (reader != null) {
       Map<String, String> nsmap = getNsMap();
       if (nsmap == null) {
         nsmap = Collections.emptyMap();
       }
       source = new StAXSource(new DelegatingXMLStreamReader(reader, nsmap));
       StreamSource streamSource =
           exchange
               .getContext()
               .getTypeConverter()
               .convertTo(StreamSource.class, exchange, source);
       if (streamSource != null) {
         try {
           li.set(new StreamSourceCache(streamSource, exchange));
         } catch (IOException e) {
           LOG.error("Cannot Create StreamSourceCache ", e);
         }
       }
     } else if (!(source instanceof DOMSource)) {
       Document document =
           exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, source);
       if (document != null) {
         li.set(new DOMSource(document));
       }
     }
   }
 }
Пример #19
0
 private <T extends SBOLObject> void removeDuplicates(List<T> objects) {
   ListIterator<T> i = objects.listIterator();
   while (i.hasNext()) {
     T obj = i.next();
     if (duplicates.contains(obj)) {
       i.set(map(obj));
     }
   }
 }
 @Override
 Object action(ListIterator<?> iterator) {
   AtomicInteger counter = counters.get(iterator);
   if (counter == null) {
     counters.put(iterator, counter = new AtomicInteger(0));
   }
   ((ListIterator) iterator).set(counter.addAndGet(-2));
   return null;
 }
Пример #21
0
    void replaceMatcherValues(List<Object> values) {
      boolean firstOccurrence = true;
      ListIterator<Object> iter = values.listIterator(values.size());

      while (iter.hasPrevious()) {
        Object value = iter.previous();
        if (!HamcrestFacade.isMatcher(value)) continue;

        if (firstOccurrence) {
          // indicate mismatch in condition output
          iter.set(shortSyntax ? false : ExpressionInfo.VALUE_NOT_AVAILABLE);
          firstOccurrence = false;
        } else {
          // don't show in condition output
          iter.set(ExpressionInfo.VALUE_NOT_AVAILABLE);
        }
      }
    }
Пример #22
0
 private boolean evaluateOne(State state, Object keyValue, List<Object> values) {
   if (!(keyValue instanceof Recordable || keyValue instanceof UUID)) {
     Class<?> keyValueClass = keyValue.getClass();
     for (ListIterator<Object> i = values.listIterator(); i.hasNext(); ) {
       i.set(ObjectUtils.to(keyValueClass, i.next()));
     }
   }
   return compare(state, keyValue, values);
 }
Пример #23
0
 public PQNode modifyTree(Node nodeToMerge) {
   myNodeToMerge = nodeToMerge;
   String oldTreeRepresentation = this.toString();
   int oldNumFullLeaves = findPertinentRoot(myRoot).getNumFullLeaves();
   makeReducible();
   PQNode pertinentRoot = findPertinentRoot(myRoot);
   int numFullLeaves = pertinentRoot.getNumFullLeaves();
   if (SHOW_LOG > 0) {
     if (oldNumFullLeaves > numFullLeaves) {
       System.out.println("Graph has been made reductible!");
       System.out.println("before:");
       System.out.println(oldTreeRepresentation);
       System.out.println("after:");
       System.out.println(this);
     }
   }
   if (numFullLeaves == 1) {
     pertinentRoot = pertinentRoot.getParent();
     List<PQNode> children = pertinentRoot.getChildren();
     ListIterator<PQNode> childItr = children.listIterator();
     PNode newNode = null;
     while (childItr.hasNext()) {
       PQNode child = childItr.next();
       if (child.getState() == PQNode.State.FULL) {
         newNode = new PNode(nodeToMerge, ((PNode) child).getEdge());
         newNode.setParent(pertinentRoot);
         childItr.set(newNode);
       }
     }
     return newNode;
   } else {
     List<PQNode> modifiedChildren = ListSequence.fromList(new ArrayList<PQNode>());
     if (pertinentRoot instanceof QNode) {
       PQNode prePertinentRoot = pertinentRoot.getParent();
       for (PQNode child : ListSequence.fromList(prePertinentRoot.getChildren())) {
         if (child == pertinentRoot) {
           ListSequence.fromList(modifiedChildren).addElement(arrange(child, true));
         } else {
           ListSequence.fromList(modifiedChildren).addElement(arrange(child, false));
         }
       }
       for (PQNode child : ListSequence.fromList(modifiedChildren)) {
         child.setParent(prePertinentRoot);
       }
       return prePertinentRoot.processAsPertinentRoot(modifiedChildren, nodeToMerge);
     } else {
       for (PQNode child : ListSequence.fromList(pertinentRoot.getChildren())) {
         ListSequence.fromList(modifiedChildren).addElement(arrange(child, false));
       }
       for (PQNode child : ListSequence.fromList(modifiedChildren)) {
         child.setParent(pertinentRoot);
       }
       return pertinentRoot.processAsPertinentRoot(modifiedChildren, nodeToMerge);
     }
   }
 }
Пример #24
0
 private CachedCxfPayload(CachedCxfPayload<T> orig) throws IOException {
   super(orig.getHeaders(), new ArrayList<Source>(orig.getBodySources()), orig.getNsMap());
   ListIterator<Source> li = getBodySources().listIterator();
   this.xml = orig.xml;
   while (li.hasNext()) {
     Source source = li.next();
     if (source instanceof StreamCache) {
       li.set((Source) (((StreamCache) source)).copy());
     }
   }
 }
Пример #25
0
 private static void add(List<InflateData> list, int ypos, int inflation) {
   for (final ListIterator<InflateData> it = list.listIterator(); it.hasNext(); ) {
     final InflateData cur = it.next();
     if (cur.getPos() == ypos) {
       it.set(new InflateData(ypos, Math.max(inflation, cur.getInflation())));
       return;
     }
   }
   list.add(new InflateData(ypos, inflation));
   Collections.sort(list);
 }
Пример #26
0
 /**
  * Same story, need to be able to replace NamespaceContainer instances with Namespace content.
  *
  * @param results A list potentially containing NamespaceContainer instances
  * @return The parameter list with NamespaceContainer instances replaced by the wrapped Namespace
  *     instances.
  */
 @SuppressWarnings({"rawtypes", "unchecked"})
 private static final List unWrap(List results) {
   for (ListIterator it = results.listIterator(); it.hasNext(); ) {
     Object o = it.next();
     Object p = unWrapNS(o);
     if (o != p) {
       it.set(p);
     }
   }
   return results;
 }
 private void setAsGraph(final LNode[][] nodeOrder) {
   ListIterator<Layer> layerIter = layeredGraph.getLayers().listIterator();
   while (layerIter.hasNext()) {
     Layer layer = layerIter.next();
     LNode[] nodes = nodeOrder[layerIter.previousIndex()];
     ListIterator<LNode> nodeIter = layer.getNodes().listIterator();
     while (nodeIter.hasNext()) {
       nodeIter.next();
       nodeIter.set(nodes[nodeIter.previousIndex()]);
     }
   }
 }
Пример #28
0
  public static void main(String[] args) {

    // 演示列表迭代器。
    ArrayList al = new ArrayList();

    // 添加元素
    al.add("java01");
    al.add("java02");
    al.add("java03");

    sop(al);

    ListIterator li = al.listIterator();

    // sop("hasPrevious():"+li.hasPrevious());

    while (li.hasNext()) {
      Object obj = li.next();

      if (obj.equals("java02"))
        // li.add("java009");
        li.set("java006");
    }

    while (li.hasPrevious()) {
      sop("pre::" + li.previous());
    }
    // sop("hasNext():"+li.hasNext());
    // sop("hasPrevious():"+li.hasPrevious());

    sop(al);

    /*
    //在迭代过程中,准备添加或者删除元素。

    Iterator it = al.iterator();

    while(it.hasNext())
    {
    	Object obj = it.next();

    	if(obj.equals("java02"))
    		//al.add("java008");
    		it.remove();//将java02的引用从集合中删除了。

    	sop("obj="+obj);


    }
    sop(al);
    */

  }
Пример #29
0
  private static void _clone_sortSelf(Vector dati, Vector dati_cr, int start, int finish) {
    if (dati == null
        || dati.size() == 0
        || start < 0
        || start > dati.size()
        || finish < 0
        || finish > dati.size()
        || start > finish
        || dati_cr == null
        || dati_cr.size() != dati.size()) return;

    Vector result = (Vector) dati.clone();
    Vector index = new Vector();
    for (int i = start; i < finish; i++) index.add(new Integer(i));
    try {

      Object a_buf[] = dati_cr.toArray();
      Object a[] = new Object[finish - start];
      for (int j = start; j < finish; j++) a[j - start] = a_buf[j];
      Object a_index[] = index.toArray();
      Object src_index[] = (Object[]) a_index.clone();
      Object src[] = (Object[]) a.clone();
      _clone_mergeSort(src, a, 0, a.length, src_index, a_index);
      ListIterator li = dati_cr.listIterator();
      ListIterator l_index = index.listIterator();
      for (int j = 0; j < finish; j++) {
        if (j >= start) {
          li.next();
          li.set(a[j - start]);
          l_index.next();
          l_index.set(a_index[j - start]);
        } else li.next();
      }
    } catch (Exception e) {
      e.toString();
    }

    for (int i = start; i < finish; i++)
      dati.setElementAt(result.elementAt(((Integer) index.elementAt(i - start)).intValue()), i);
  }
Пример #30
0
  void replaceChild(Node oldChild, Node newChild) {
    if (_id_ == oldChild) {
      setId((TId) newChild);
      return;
    }

    if (_arrow_ == oldChild) {
      setArrow((TArrow) newChild);
      return;
    }

    for (ListIterator i = _prodTransform_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set(newChild);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }

    for (ListIterator i = _alts_.listIterator(); i.hasNext(); ) {
      if (i.next() == oldChild) {
        if (newChild != null) {
          i.set(newChild);
          oldChild.parent(null);
          return;
        }

        i.remove();
        oldChild.parent(null);
        return;
      }
    }
  }