コード例 #1
0
  /** Test normal iteration behaviour. */
  public void testFullIterator() {
    if (supportsFullIterator() == false) {
      return;
    }

    Iterator<E> it = makeObject();

    // hasNext() must be true (ensure makeFullIterator is correct!)
    assertEquals("hasNext() should return true for at least one element", true, it.hasNext());

    // next() must not throw exception (ensure makeFullIterator is correct!)
    try {
      it.next();
    } catch (NoSuchElementException e) {
      fail("Full iterators must have at least one element");
    }

    // iterate through
    while (it.hasNext()) {
      it.next();
      verify();
    }

    // next() must throw NoSuchElementException now
    try {
      it.next();
      fail("NoSuchElementException must be thrown when Iterator is exhausted");
    } catch (NoSuchElementException e) {
    }

    assertNotNull(it.toString());
  }
  public static void send_to_group(LinkedList Clients, ArrayList<String> Decrypted_Chat_Buffer) {

    LinkedHashSet client_set = new LinkedHashSet();
    Iterator j = Clients.iterator();
    while (j.hasNext()) {
      boolean isthere = false;
      Object g = j.next();
      Iterator k = client_set.iterator();
      while (k.hasNext()) {
        System.out.println("Comparing two elements");
        if (k.next().toString().equals(g.toString())) {
          isthere = true;
          System.out.println("Elements can not be added");
        }
      }
      if (!isthere) {
        System.out.println("Adding element");
        client_set.add(g);
      }
    }

    System.out.println(client_set.size());
    System.out.println(Clients.size());
    Iterator i = client_set.iterator();

    System.out.println("Writing Data to all the clients");
    while (i.hasNext()) {
      System.out.println("Writing Data to all the client" + i.toString());
      SocketChannel channel = (SocketChannel) i.next();
      Iterator chat = Decrypted_Chat_Buffer.iterator();
      while (chat.hasNext()) {
        String mesg = chat.next().toString();
        System.out.println("message" + mesg);
        prepareBuffer("message" + mesg);
        channelWrite(channel);
        System.out.println("Writen Data to client" + i.toString());
      }
    }
    setPhase_4_over(true);
    setPhase_2_over(false);
    setDecrypted(false);
    Decrypted_Chat_Buffer.clear();
  }
コード例 #3
0
  /** Test the empty iterator. */
  public void testEmptyIterator() {
    if (supportsEmptyIterator() == false) {
      return;
    }

    Iterator<E> it = makeEmptyIterator();

    // hasNext() should return false
    assertEquals("hasNext() should return false for empty iterators", false, it.hasNext());

    // next() should throw a NoSuchElementException
    try {
      it.next();
      fail("NoSuchElementException must be thrown when Iterator is exhausted");
    } catch (NoSuchElementException e) {
    }
    verify();

    assertNotNull(it.toString());
  }