예제 #1
0
  void close() {
    try {
      if (mySelector != null) mySelector.close();
    } catch (IOException e) {
    }
    mySelector = null;

    // run down open connections and sockets.
    Iterator<ServerSocketChannel> i = Acceptors.values().iterator();
    while (i.hasNext()) {
      try {
        i.next().close();
      } catch (IOException e) {
      }
    }

    // 29Sep09: We create an ArrayList of the existing connections, then iterate over
    // that to call unbind on them. This is because an unbind can trigger a reconnect,
    // which will add to the Connections HashMap, causing a ConcurrentModificationException.
    // XXX: The correct behavior here would be to latch the various reactor methods to return
    // immediately if the reactor is shutting down.
    ArrayList<EventableChannel> conns = new ArrayList<EventableChannel>();
    Iterator<EventableChannel> i2 = Connections.values().iterator();
    while (i2.hasNext()) {
      EventableChannel ec = i2.next();
      if (ec != null) {
        conns.add(ec);
      }
    }
    Connections.clear();

    ListIterator<EventableChannel> i3 = conns.listIterator(0);
    while (i3.hasNext()) {
      EventableChannel ec = i3.next();
      eventCallback(ec.getBinding(), EM_CONNECTION_UNBOUND, null);
      ec.close();

      EventableSocketChannel sc = (EventableSocketChannel) ec;
      if (sc != null && sc.isAttached()) DetachedConnections.add(sc);
    }

    ListIterator<EventableSocketChannel> i4 = DetachedConnections.listIterator(0);
    while (i4.hasNext()) {
      EventableSocketChannel ec = i4.next();
      ec.cleanup();
    }
    DetachedConnections.clear();
  }
 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);
   }
 }
예제 #3
0
파일: World.java 프로젝트: munro/lzr
 public void render() {
   ListIterator<Wall> it;
   Wall w;
   for (it = walls.listIterator(); it.hasNext(); ) {
     w = it.next();
     w.render();
   }
 }
예제 #4
0
 public void setList(ArrayList<String> element_path) {
   element.clear();
   ListIterator<String> listIterator = element_path.listIterator();
   while (listIterator.hasNext()) {
     element.add(listIterator.next());
   }
   number_element = element.size();
 }
예제 #5
0
  /**
   * Outputs filled with points listOfPointsToBeConnected. Finds the point with the lowest Y - that
   * will be the first point of the broken line. If It finds several points with equal Ys - makes a
   * line from the most left (lowest X) point to the most right point, then connects this point with
   * next point with the lowest Y from the remaining set. The last point of the broken line will be
   * the point with the highest Y, or if there will be several points with the highest Y - the point
   * with the highest X from this set.
   */
  void connectPoints() {

    ArrayList<MyPoint> pointsInOneRow =
        new ArrayList<MyPoint>(); // will store points with equal Ys.
    MyPoint currentPoint, nextPoint;
    ListIterator<MyPoint> itr;

    while (randomListOfPoints.size() > 0) {

      pointsInOneRow.clear(); // clear the pointsInOneRow.
      itr = randomListOfPoints.listIterator();
      // initialize list iterator and place it before the first element in the randomListOfPoints.
      currentPoint = itr.next(); // the first element from the randomListOfPoints.
      itr.remove(); // delete the first element from the randomListOfPoints.
      if (itr.hasNext()) { // if it's not the end of the randomListOfPoints.

        nextPoint = itr.next(); // the second element from the randomListOfPoints.

      } else {

        // the point not from the range of possible Xs and Ys, so we can be sure that its' Y won't
        // be equal to the currentPoints'.
        nextPoint = new MyPoint(-1, -1);
      }
      pointsInOneRow.add(
          currentPoint); // add current point to a list of points, that lies on one line.
      // if the currentPoint and the nextPoint are on the same line, that is parallel to the X axis.
      while (currentPoint.getY() == nextPoint.getY()) {

        pointsInOneRow.add(
            nextPoint); // add the nextPoint to a list of points, that lies on one line.
        itr.remove(); // delete the second element from the randomListOfPoints .
        currentPoint = nextPoint; // the currentPoint equals to the nextPoint now.
        if (itr.hasNext()) { // if it's not the end of the randomListOfPoints.

          nextPoint = itr.next(); // the second element from the randomListOfPoints.

        } else {

          // the point not from the range of possible Xs and Ys, so we can be sure that its' Y won't
          // be equal to the currentPoints'.
          nextPoint = new MyPoint(-1, -1);
        }
      }

      Collections.sort(
          pointsInOneRow, new XcoordSorterComparator()); // sort the pointsInOneRow by X
      /* add all elements from the pointsInOneRow to the end of the listOfPointsToBeConnected.
       * If the listOfPointsToBeConnected.size == 0 - the first element from the pointsInOneRow will be the start
       * of the broken line, if the listOfPointsToBeConnected.size != 0 - the first element from the
       * pointsInOneRow will be connected with the last element from the listOfPointsToBeConnected*/
      listOfPointsToBeConnected.addAll(listOfPointsToBeConnected.size(), pointsInOneRow);
    }

    System.out.println("\n\nList of connected points:\n" + listOfPointsToBeConnected);
  }
예제 #6
0
파일: World.java 프로젝트: munro/lzr
 boolean intersectsWall(Vector2f a, Vector2f b) {
   ListIterator<Wall> it;
   Wall w;
   // int x = 0;
   for (it = walls.listIterator(); it.hasNext(); ) {
     w = it.next();
     // System.out.println("HEY " + (x++));
     if (w.intersectsLine(a, b)) return true;
   }
   return false;
 }
예제 #7
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);
    */

  }
예제 #8
0
 /**
  * Generates DML specifying table columns and their datatypes. The output of this routine should
  * be used within a CREATE TABLE statement.
  *
  * @param fields Contains unique field names
  * @param datatype Specifies the SQL data type that the fields should take on.
  * @return The SQL code to be included in a CREATE TABLE statement.
  */
 public static String fieldsAsCols(ArrayList<String> fields, String datatype) {
   String field;
   ArrayList<String> newFields = new ArrayList<>();
   ListIterator<String> li = fields.listIterator();
   while (li.hasNext()) {
     field = li.next();
     if (SQLUtil.reservedDBWords.contains(field)) {
       field = field + '_';
     }
     newFields.add(field + datatype);
   }
   return String.join(", ", newFields);
 }
예제 #9
0
  void addNewConnections() {
    ListIterator<EventableSocketChannel> iter = DetachedConnections.listIterator(0);
    while (iter.hasNext()) {
      EventableSocketChannel ec = iter.next();
      ec.cleanup();
    }
    DetachedConnections.clear();

    ListIterator<Long> iter2 = NewConnections.listIterator(0);
    while (iter2.hasNext()) {
      long b = iter2.next();

      EventableChannel ec = Connections.get(b);
      if (ec != null) {
        try {
          ec.register();
        } catch (ClosedChannelException e) {
          UnboundConnections.add(ec.getBinding());
        }
      }
    }
    NewConnections.clear();
  }
예제 #10
0
  void runTimers() {
    long now = new Date().getTime();
    while (!Timers.isEmpty()) {
      long k = Timers.firstKey();
      if (k > now) break;

      ArrayList<Long> callbacks = Timers.get(k);
      Timers.remove(k);

      // Fire all timers at this timestamp
      ListIterator<Long> iter = callbacks.listIterator(0);
      while (iter.hasNext()) {
        eventCallback(0, EM_TIMER_FIRED, null, iter.next().longValue());
      }
    }
  }
예제 #11
0
  void removeUnboundConnections() {
    ListIterator<Long> iter = UnboundConnections.listIterator(0);
    while (iter.hasNext()) {
      long b = iter.next();

      EventableChannel ec = Connections.remove(b);
      if (ec != null) {
        eventCallback(b, EM_CONNECTION_UNBOUND, null);
        ec.close();

        EventableSocketChannel sc = (EventableSocketChannel) ec;
        if (sc != null && sc.isAttached()) DetachedConnections.add(sc);
      }
    }
    UnboundConnections.clear();
  }
예제 #12
0
  /** Evaluate sortedBy expressions. */
  protected final Value evalSortedBy(EvalContext ctx) {
    // evaluate range
    Value v = fRangeExp.eval(ctx);
    if (v.isUndefined()) return UndefinedValue.instance;
    CollectionValue rangeVal = (CollectionValue) v;

    ArrayList<KeyValPair> keyValList = new ArrayList<KeyValPair>();

    // loop over range elements
    for (Value elemVal : rangeVal) {

      // bind element variable to range element, if variable was
      // declared
      if (!fElemVarDecls.isEmpty()) ctx.pushVarBinding(fElemVarDecls.varDecl(0).name(), elemVal);

      // evaluate sortedBy expression and store the result as a
      // key together with elemVal
      Value key = fQueryExp.eval(ctx);
      keyValList.add(new KeyValPair(key, elemVal));

      if (!fElemVarDecls.isEmpty()) ctx.popVarBinding();
    }

    // sort elements by key
    Collections.sort(
        keyValList,
        new Comparator<KeyValPair>() {
          public int compare(KeyValPair o1, KeyValPair o2) {
            return o1.fKey.compareTo(o2.fKey);
          }
        });

    // drop the keys from the list
    ListIterator<KeyValPair> listIter = keyValList.listIterator();
    Collection<Value> result = new ArrayList<Value>(keyValList.size());

    while (listIter.hasNext()) {
      KeyValPair kvp = listIter.next();
      result.add(kvp.fElem);
    }

    Type rangeElemType = ((CollectionType) fRangeExp.type()).elemType();
    return new SequenceValue(rangeElemType, result);
  }
  public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    al.add("C");
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");

    System.out.print("Original conts of al: ");
    Iterator<String> itr = al.iterator();
    while (itr.hasNext()) {
      String element = itr.next();
      System.out.print(element + " ");
    }
    System.out.println();

    ListIterator<String> litr = al.listIterator();
    while (litr.hasNext()) {
      String element = litr.next();
      litr.set(element + "+");
    }

    System.out.print("Modified contents of al: ");
    itr = al.iterator();
    while (itr.hasNext()) {
      String element = itr.next();
      System.out.print(element + " ");
    }
    System.out.println();

    System.out.print("Modified list backwards: ");
    while (litr.hasPrevious()) {
      String element = litr.previous();
      System.out.print(element + " ");
    }
    System.out.println();
  }
예제 #14
0
  public static void main(String[] args) throws IOException {
    double sum = 0;
    String str = readString(System.in);

    ArrayList<String> collection = new ArrayList<>();

    List list = Arrays.asList(str.split("\\s"));
    Iterator<String> it = list.iterator();
    int idx = 0;
    while (it.hasNext()) {
      String element = it.next();
      if (idx++ % 2 == 0) continue;
      collection.add(element);
    }

    // http://stackoverflow.com/a/2102552/2289640
    ListIterator lit = collection.listIterator(collection.size());
    while (lit.hasPrevious()) {
      String element = (String) lit.previous();
      System.out.print(element + " ");
    }
  }
예제 #15
0
 public static void main(String[] args) {
   ArrayList al1 = new ArrayList();
   al1.add("java01");
   al1.add("java02");
   al1.add("java03");
   al1.add("java04");
   /*
   普通迭代器只有三个方法,hasNext,next,remove;不能实现添加,和修改方法。
   Iterator it = al1.iterator();
   while(it.hasNext())
   {
   	sop(it.next());
   }
   */
   // list集合里有listIterator迭代器。这种迭代器有增删改查方法。因为有角标。
   ListIterator li = al1.listIterator();
   while (li.hasNext()) {
     Object obj = li.next();
     if (obj.equals("java01"))
       // li.add("java055");
       li.set("java111");
   }
   sop(al1);
 }
예제 #16
0
 public ListIterator<T> listIterator(final int index) {
   return myElements.listIterator(index);
 }
예제 #17
0
 public ListIterator<T> listIterator() {
   return myElements.listIterator();
 }
예제 #18
0
 @Override
 public ListIterator<Long> listIterator() {
   return original.listIterator();
 }
예제 #19
0
 @Override
 public ListIterator<Long> listIterator(int index) {
   return original.listIterator(index);
 }
예제 #20
0
 @Nonnull
 @Override
 public ListIterator<T> listIterator(int index) {
   beforeGet();
   return list.listIterator(index);
 }
예제 #21
0
 public ListIterator getReactantTree() {
   ListIterator iter = reactantTree.listIterator();
   return iter;
 }