You cannot change the length of a Collection (by adding or removing items) 
while iterating through it.

You can
- make a copy of the account collections, delete accounts from that copy during 
iteration, clear the account collection and insert all elements of the copy 
into the account collection *uff*
- insert all accounts to delete into a toDelete collection during iteration, 
and then iterate over the toDelete collection and delete items from the account 
collection.

Confused? Here's an example for the second way: 

public void filter(...) {
  |   Collection<Accounts> toDelete = new ArrayList<Accounts>();
  |     for (Account a: accounts)
  |         if(accounts.notAccessibleBy(user)
  |             toDelete.add(a);
  |         else if (accounts.accessibleBy(user)
  |             continue;
  |         else
  |             toDelete.add(a);
  | 
  | for (Account a: toDelete)
  |     accounts.remove(a);
  | }
btw: The checks you make (notAccessiblyBy, accessibleBy) seem to be a bit weird 
;). It looks like you want to keep ALL accounts in the collection or delete ALL 
of them. Wouldn't it work like this?
public void filter(...) {
  |     if (accounts.notAccessibleBy(user))
  |         accounts.clear();
  | }
 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3960375#3960375

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3960375
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to