swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printing lists (java)


From: Paul E Johnson
Subject: Re: printing lists (java)
Date: Wed, 14 Mar 2001 09:24:23 -0600

Matteo Richiardi wrote:
> 
> Dear listmates,
> could anybody please give me an example of how to use the forEachKey()
> javaswarm method? I need to print all the keys (in my example: numbers) of a
> map, with their corresponding objects (in my example: lists containing
> numbers), and I couldn't figure out how to do it.
> 
> Many thanks in advance,
> 
> Matteo Richiardi
> (Torino, Italy)

Gosh, I will be in your country soon! Spring break is just around the
corner.

If I understand it right, you are using a Swarm collections map and you
want to create a method that cycles through the map, and prints out the
value of the key and runs some method on the object stored there.

If I wanted to do that, I'd create an index and then step through,
getting the key and the associated object. I'm thinking in Obj-C here,
but you should be able to translate:
 
        id <Index> index = [aCollection begin: aZone];
        id member;

        for (member = [index next]; [index getLoc] == Member; member =
[index next])
          {
                id aKey = [index getKey];
                //do whatever you want to aKey
                //do whatever you want to member, that's the mapped item
          }
        [index drop];

It seems to me, if your program is in Java, you could use a Java
collection instead of a Swarm collection, and you could just use the
regular Java way to take care of this.      

But I don't have time right now to write out a full running program, and
so I suggest this to you. Take a look in the SwarmFaq's
"WorkingExampleCode" directory 

http://lark.cc.ukans.edu/~pauljohn/SwarmFaq/WorkingExampleCode

Find an example program, and then edit it so it creates a Map like you
want, fills it with objects, and so forth. Make sure that
compiles/runs.  Then put in your best effort at the thing you want to
do, try to compile it, run it. If it does not work, post your FULL
PROGRAM in an email, or post it on a web site somewhere.

That should make it easy for us to show you what you need to do.

I think that, in the future, support in this list will be significantly
facilitated if any "howto" questions of this sort are accompanied by a
small program that we can look at.  I'm pretty sure that makes it easier
for Marcus, I'm sure it will help me and several others.

Unless I get some complaints from list members, I'm going to add an item
at the beginning of the SwarmFaq which explains this procedure, and I'll
just start referring people to it when they as howto questions.

-- 
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                FAX: (785) 864-5700

                  ==================================
   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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]