[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] Swarm questions
From: |
Li An |
Subject: |
Re: [Swarm-Support] Swarm questions |
Date: |
Wed, 02 Apr 2003 15:14:30 -0500 |
Hi
Say, the list contains a number of bugs (agents) and the Bug class has an
attribute called bugColor and getBugColor and setBugColor methods. For some
reason, I want to turn the color of each bug in the list to blue--in this
case, I can use a for loop (Java Swarm) as below:
for (int i=0;i<bugList.size();i++){
aBug=(Bug)bugList.get(i); //aBug should be an object of class Bug
declared earlier
aBug.setBugColor(blue);
}
This is relatively inefficient in some cases. My question was to set the
color to blue to all the bugs in bugList without using the above loop. Does
forEach work here?
At 11:50 AM 4/2/2003 -0800, you wrote:
Li An writes:
> (1) I remember when I read the Swarm tutorial, there is a quick way to
turn
> on or off the flag of all the elements in a list without traversing the
> list. Is this true? If so, how to do it?
What do you mean by "the flag"? There are "forEach", "dropAll", and
"deleteAll" methods for lists? So, if by "flag" you mean call some
method that manipulates a variable, then forEach is what you want,
as long as the elements of the list all accept that method. If you're
looking to remove items from a list without dropping them, then
dropAll is what you want. If you want to remove and drop all elements
from a list, then deleteAll is what you want.
--
glen e. p. ropella =><= Hail Eris!
H: 503.630.4505 http://www.ropella.net/~gepr
M: 831.247.7901 http://www.tempusdictum.com
_______________________________________________
Support mailing list
address@hidden
http://www.swarm.org/mailman/listinfo/support
Li An
Laboratory of Systems Integration and Modeling
13 Natural Resources Building
Department of Fisheries and Wildlife
Michigan State University
East Lansing, MI 48824
Phone (Work): 517-353-7981
Fax: 517-432-1699
http://www.msu.edu/~anli