swarm-support
[Top][All Lists]
Advanced

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

Re: MapImpl


From: Paul E Johnson
Subject: Re: MapImpl
Date: Thu, 07 Jun 2001 12:05:53 -0500

Fred Wan wrote:
> address@hidden/cygdrive/h/swarm/java/WorkingExamples/TestMapImpl] $ javaswarm
> TestGUISwarm
> 
> Moving at: 1
> This should be First: null
> And this should be Second: null
> Does the map contain key 1? false
> What is the first member of newMap? First
Hmm.  I get that same output on Linux with Swarm-2.1.72.  With a new
Swarm on Solaris, are you saying you don't get the same?

In the short term, I would say you should use one of the java
collections instead of swarm's map anyway.  I don't  know if there is
any official word about that claim, but I've sensed it strongly from
several of the experts.

I do agree the behavior you found is surprising/bugish.  Because I was
bored I dug into your example more and I think this is what is
happening. The java runtime system sees the output of two calls to new
Integer(1) and new Integer(1) as different things. Note below I edit
your code to save the new integers as int1 and int2 and that code does
not produce the nulls you see in your test case.  I've added some other
loops that print out the contents of the map.  These show the map does
exist and has the right stuff, whether you  comment out my code and
uncomment yours, or not.

 public void move () {
    System.out.println ("Moving at: " + Globals.env.getCurrentTime ());
    MapImpl newMap = new MapImpl(this.getZone());
    Integer int1 = new Integer(1);
    Integer int2 = new Integer(2);
    //newMap.at$insert(new Integer(1), new String("First"));    
    //newMap.at$insert(new Integer(2), new String("Second"));
    newMap.at$insert(int1, new String("First"));    
    newMap.at$insert(int2, new String("Second"));

    //System.out.println("This should be First: " + newMap.at(new
Integer(1)));
    //System.out.println("And this should be Second: " + newMap.at(new
Integer(2)));
    //System.out.println("Does the map contain key 1? " +
newMap.containsKey(new Integer(1)));

    System.out.println("This should be First: " + newMap.at(int1));
    System.out.println("And this should be Second: " + newMap.at(int2));
    System.out.println("Does the map contain key 1? " +
newMap.containsKey(int1));
    System.out.println("What is the first member of newMap? " +
newMap.getFirst());
    MapIndex mapIndex = newMap.mapBegin (getZone ());
    
    while (mapIndex.next() != null ){
        System.out.println("the member is " + mapIndex.get());
        System.out.println("the key is " + mapIndex.getKey());
    }
    //mapIndex.setLoc("Start");

    mapIndex = newMap.mapBegin (getZone ());
    Object  aThing = null;
    while ((aThing=mapIndex.next()) != null){
        System.out.println("the key is " + mapIndex.getKey() + " and value is"
+ newMap.at(mapIndex.getKey()));
    }
  }                


-- 
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]