[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: java packages
From: |
Marcus G. Daniels |
Subject: |
Re: java packages |
Date: |
10 Dec 1999 11:30:41 -0800 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "JR" == Juan A Rodriguez <address@hidden> writes:
JR> Thus you can instantiate EZBin but then there is no means to set a
JR> collection for the object.
The interfaces of the Objective C Swarm are organized around the idea
of `phases'. Phases are groups of methods that make sense in one context
but not in others. The primary use of this in Swarm is to differentiate
between methods you use to describe an object (e.g. structurally) and methods
that are sent to an object once it has been created. In Objective C,
these method groups are revealed implicitly: if you send a create-time
message to an agent that has already been created, that message will throw
an exception (unless you've taken steps to facilitate forwarding, etc.).
In Java, method groups are in their own Java interfaces, each with
distinct names. The interface name for *using* an object is the root
word for the feature you want, say "EZBin". The interface name for
*creating* an object is the root word for the feature you want,
suffixed with "C". The underlying implementations (typically a
one-to-one relationship with the interfaces), have the additional
suffix "Impl".
Name Meaning
----- -------
Interface A list of methods that can be sent to a conforming object.
Implementation The actual methods that provide the methods.
An implementation can be tagged to say it
conforms-to an Interface. To create an object, you
typically run "new SomethingImpl ()", and assign it to
a variable of type "Something".
EZBin The interface to the `using'-phase EZBin features.
E.g. the method `update' is a using-phase method.
EZBinImpl The implementation of the using-phase EZBin features.
Note that this, and most, implementations are equipped
with constructors to run the creating phase and then
switch to the using phase. In this way, you don't
need to have verbose code sequences to create objects.
EZBinC The interface to the `creating'-phase EZBin features.
E.g. the method `setCollection' is a creating-phase method.
It usually isn't necessary to use this interface unless
there are using-phase constructors that enumerate
the common usages.
EZBinCImpl The implementation of the creating-phase EZBin methods.
Again, it usually is not necessary to create such
objects. When you do, the one thing to be aware of
is that the using phase object is passed as a
parameter to the constructor.
Below is how to do an EZBin in Java. Note this is for the current
ftp://ftp.santafe.edu/pub/swarm/2.0.1-fixes javaswarm.dll and
swarm.jar,or the latest RPM from Paul, or a build from the latest in
ftp://ftp.santafe.edu/pub/swarm/testing. I avoid using the Swarm
collections library in Java models because straight Java libraries
will be faster and easier for Java programmers to read.
I'd also like to mention that use of GUISwarm (ObserverSwarm) only has
one purpose here: to create the GUI update mechanism that the Swarm
graphics library requires. If you use AWT/Swing for the GUI, you
don't need to use GUISwarm or any of those conventions (buildObjects,
buildActions, go).
import java.util.List;
import java.util.LinkedList;
import swarm.defobj.Zone;
import swarm.analysis.EZBin;
import swarm.analysis.EZBinC;
import swarm.analysis.EZBinCImpl;
import swarm.analysis.EZBinImpl;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.Globals;
import swarm.Selector;
public class TestEZBin extends GUISwarmImpl {
List l;
EZBin ezbin;
class Agent {
double value;
Agent (double value) {
super ();
this.value = value;
}
public double getAgentValue () {
return value;
}
}
TestEZBin (Zone aZone) {
super (aZone);
l = new LinkedList ();
for (int i = 0; i < 5; i++)
for (int j = 0; j < 1 << i; j++)
l.add (new Agent ((double) i));
EZBinC ezbinCreating = new EZBinCImpl (new EZBinImpl ());
ezbinCreating.createBegin (aZone);
ezbinCreating.setCollection (l);
Class agentClass = l.get (0).getClass ();
try {
ezbinCreating.setProbedSelector
(new Selector (agentClass, "getAgentValue", false));
} catch (Exception e) {
e.printStackTrace (System.err);
}
ezbinCreating.setTitle ("Value");
ezbinCreating.setBinCount (5);
ezbinCreating.setLowerBound (0);
ezbinCreating.setUpperBound (5);
ezbin = (EZBin) ezbinCreating.createEnd ();
}
void update () {
ezbin.reset ();
ezbin.update ();
ezbin.output ();
}
static void main (String[] args) {
Globals.env.initSwarm ("TestEZBin", "0.0", "address@hidden", args);
TestEZBin testEZBin = new TestEZBin (Globals.env.globalZone);
testEZBin.buildObjects ();
testEZBin.buildActions ();
testEZBin.activateIn (null);
testEZBin.update ();
testEZBin.go ();
}
}
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
- java packages, Juan A Rodriguez, 1999/12/10
- Re: java packages,
Marcus G. Daniels <=