public void testIteratorRemove() {

    TIntSet set = new TIntHashSet();
    set.add(1);
    set.add(2);
    set.add(3);
    set.add(4);

    TIntIterator iter = set.iterator();
    assertTrue("iterator should have a next item", iter.hasNext());

    int last = -1;
    while (iter.hasNext()) {
      int next = iter.next();
      assertTrue(next >= 1 && next <= 4);
      assertTrue(next != last);
      last = next;

      if (next == 3) {
        iter.remove();
      }
    }

    assertFalse("iterator should not have a next item", iter.hasNext());

    assertFalse("set should not contain 3", set.contains(3));
    assertTrue("set should contain 1", set.contains(1));
    assertTrue("set should contain 2", set.contains(2));
    assertTrue("set should contain 4", set.contains(4));
    assertEquals(3, set.size());
  }
  public void testToArrayMatchesIteratorOrder() {
    TIntSet set = new TIntHashSet();
    int[] ints = {42, 1138, 13, 86, 99};
    set.addAll(ints);
    int[] toarray_ints = set.toArray();

    int[] iter_ints = new int[5];
    TIntIterator iter = set.iterator();

    int index = 0;
    while (iter.hasNext()) {
      iter_ints[index++] = iter.next();
    }

    assertTrue(Arrays.equals(iter_ints, toarray_ints));
  }
Пример #3
0
 private void sendEntities(NetData.NetMessage.Builder message) {
   TIntIterator dirtyIterator = netDirty.iterator();
   while (dirtyIterator.hasNext()) {
     int netId = dirtyIterator.next();
     EntityRef entity = networkSystem.getEntity(netId);
     if (isOwned(entity)) {
       Set<Class<? extends Component>> emptyComponentClassSet = Collections.emptySet();
       EntityData.PackedEntity entityData =
           entitySerializer.serialize(
               entity,
               emptyComponentClassSet,
               changedComponents.get(netId),
               emptyComponentClassSet,
               new ClientComponentFieldCheck());
       if (entityData != null) {
         message.addUpdateEntity(
             NetData.UpdateEntityMessage.newBuilder().setEntity(entityData).setNetId(netId));
       }
     }
   }
   netDirty.clear();
 }