Why after I add a object to a list, the whole list changes?

I tried to call the add method of ClientList from a jsp webpage,
by looking at the log file, i found that for the 2nd time insert an Object into clientlist (say
client 1 is: IPAddress= 167.30.22.33
client 2 is IPAddress=167.30.22.44), what i get from the system log is that I have two
167.30.22.44 in the list, the first one is gone,
after I add the third item, the list just contains three identical third item, the former two are gone,
What 's wrong with my code? From the system log, I know that the parameters passed to the method clientlist.add are correct.
thank you.
My code is like this :
public class ClientList {
ArrayList<Client> listitems = null;
int numberOfItems = 0;
public ClientList()
          items = new HashMap<String, ClientListItem>();
          listitems = new ArrayList<Client>();
public synchronized void add(
Client cl) {
if (items.containsKey(cl.getIPAddress())) {
               ClientListItem clitem = (ClientListItem)items.get(cl.getIPAddress());
               clitem.incrementQuantity();
} else {
               System.out.println("clist.add called: " + cl.getIPAddress() + "\n");
               ClientListItem newItem = new ClientListItem(cl);
               items.put(cl.getIPAddress(), newItem);
               listitems.add(cl);
               for (Iterator i = listitems.iterator(); i.hasNext(); )
                    Client clt = (Client)(i.next());
                    System.out.println("after adding : " + clt.getIPAddress() + "\n");
}

I'm willing to bet that what is happening here goes as follows:
// Step 1:  Create a client 1 object
// Step 2:  Call add with this client object creating a string key with a client value
// Step 3:  redefine the data in the first client object with the data for the second
             // In this step you probably did not create anew client object, but simply
             // changed the data in the original
// Step 4:  Call add with the "redefined" client object comparing the string key with
             // some data from the client, determining it is not in the list adding it againWhat the above does (if this is the way you are doing it) simply places the same client
object into the hash twice with two different keys. And in step 3, by changing the original object,
you also changed the object already in the hash, because as already said, they are the same object.
Edit: And nevermind, jverd already said this. ;-)

Similar Messages

  • Why after downloading a pdf am I getting that the file is corrupt and can not open?

    why after downloading a pdf am I getting that the file is corrupt and can not open?

    Probably the file got corrupted during the download?  Download it again.
    If that does not correct the problem, can you share that file download?

  • IChat disconnects after a few seconds and starts to blink the whole screen

    iChat disconnects after a few seconds and starts to blink the whole screen
    this started since I installed Leopard; if I go back to 10.4 it works OK. I got rid of all the plist and it still hangs up. How can I uninstall this. On my laptop it works OK but I installed it with complete erase on laptop; on my desktop I stalled it over the old system.
    error message AIM time out An AIM service error occurred.
    Error: Serv:RequestTimeout
    and you have attemptedto log too often in a short period of time. wait a few minutes before trying to login in again.
    EVEN THOUGH I ONLY TRIED ONCE TO LOG IN.

    If you Archived and Installed then check iChat launches from the Applications Folder.
    If it does that Drag the current (iChat 3) icon off the DOCK and drag iChat 4 to the DOCK.
    8:03 PM Tuesday; December 4, 2007

  • Why do my playlist delete themselves after playing though the whole list?

    just downloader the most recent Itunes update and after taking a whie to figure out that the shuffle was working i went to sleep with itunes playing. when i woke up itunes had stop playing and deleted the playlist i had playing. im ask why it did this how i can stop this and how i can have my playlist do what they did bfor witch was reshuffle the songs and continue playing.

    Try syncing using the manual method                
      Managing content manually on iPhone, iPad, and iPod

  • Why is my iPad is not showing up in the Devices list in iBook Author?

    Why is my iPad not showing up in the Devices list in iBook Author? iBook ver is up to date. iTunes sees the iPad. What gives...
    Message was edited by: drydruid

    OK, the problem is partly solved. iBooks Author is not 'smart' enough to realize the iPad had been plugged-in and iBook on if all that happens after iBooks Author is already started. On the off chance that that was the problem I Quit iBA, made sure the iPad was connected and iBook was on then restarted iBA. Sure enough, there it was.
    I really like Mac's but sometimes they're not as smart as they think they are.

  • How can i check to see if an object is already in the array list?

    while (res.next()) {
                    Schedule schedule = new Schedule();
                    customerName = res.getString("CUSTOMERNAME");
                    schedule.setCustomerName(customerName);
                    magName = res.getString("MAGNAME");
                    schedule.setMagName(magName);
                    System.out.println("NAME: " + customerName);
                    System.out.println("MAGNAME: " + magName);
                    if(!scheduleListH.contains(schedule))  //this won't work
                        scheduleListH.add(schedule);
                }schedule object has 2 fields, customerName and MagName;
    Basically i want to say, IF the scheudleList (which is an array list) contains an object schedule that has the same customerName and MagName as any of the objects in the array list, don't readd the object.
    ANy help would be great!

    Thanks!
    Oops I forogt I could use the .contains, i also tried that but still no luck.
    There is no compiler error but here is an example of the output:
    Populating scheudle list for HOLIDAY selection data structure: 
    NAME: Cory
    MAGNAME: Merlin
    NAME: Brandon
    MAGNAME: Gondorf
    NAME: Chris
    MAGNAME: Houdini
    NAME: Lokie
    MAGNAME: Blaine
    Sample SCHEDUEL H [Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine]As you can see, There are 4 objects in the array list:
    Cory Merlin
    Brandon Gondorf
    Chris Houdini
    Lokie BLaine
    Now this function is called everytime the user choses a new item in a combo box.
    So if they go back to the previous selection, Holiday's, it shouldn't read add all the orginal things.
    But if I go up and select the same item in the combo box it changes whats in the array list to the following:
    Populating scheudle list for HOLIDAY selection data structure: 
    NAME: Cory
    MAGNAME: Merlin
    NAME: Brandon
    MAGNAME: Gondorf
    NAME: Chris
    MAGNAME: Houdini
    NAME: Lokie
    MAGNAME: Blaine
    Sample SCHEDUEL H [Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine, Cory          Merlin, Brandon          Gondorf, Chris          Houdini, Lokie          Blaine]Here's my whole function if your interested and where I call it:
        void populateSchedule(String holiday) {
            Statement sta = null;
            Connection connection6 = null;
            try {
                connection6 = DriverManager.getConnection(URL, USERNAME, PASSWORD);
                sta = connection6.createStatement();
                //getting the list of magicians from the selected holiday to see if any are free
                ResultSet res = sta.executeQuery(
                        "SELECT CUSTOMERNAME, MAGNAME FROM SCHEDULE WHERE HOLIDAYNAME = '" + holiday + "'");
                String customerName = " ";
                String magName = " ";
                System.out.println("Populating scheudle list for HOLIDAY selection data structure:  ");
                //this is where I add the waiting list objects to the array that will later be used
                //to print out and shown to the user when they select the waiting list status
                while (res.next()) {
                    Schedule schedule = new Schedule();
                    customerName = res.getString("CUSTOMERNAME");
                    schedule.setCustomerName(customerName);
                    magName = res.getString("MAGNAME");
                    schedule.setMagName(magName);
                    System.out.println("NAME: " + customerName);
                    System.out.println("MAGNAME: " + magName);
                   if(!scheduleListH.contains(schedule))
                       scheduleListH.add(schedule);
                System.out.println("Sample SCHEDUEL H " +   scheduleListH);
            } catch (SQLException ex) {
                System.out.println(ex);
                ex.printStackTrace();
            } finally {
                try {
                    sta.close();
                    connection6.close();
                } catch (SQLException ex) {
                    Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    //this is where i call in the GUI
        private void specStatusComboBoxActionPerformed(java.awt.event.ActionEvent evt) {                                                  
            // TODO add your handling code here:
            String selectedItem = (String)specStatusComboBox.getSelectedItem();
            String groupSelectedItem = (String) groupStatusComboBox.getSelectedItem();
            if(groupSelectedItem.equals("Holidays"))
                //get customer name and magician name from the Scheduel table
                //use selectedItem (it will be a holiday name)
                //magicDB.clearScheduleHList();
                magicDB.populateSchedule(selectedItem);
                ArrayList<Schedule> tempScheduleList = magicDB.getScheduleHListCopy();
                outputTextArea.setText(" ");
                outputTextArea.setText("CUSTOMER NAME" +"\t\t" + "MAGICIAN NAME" + "\n");
                for(int i = 0; i < tempScheduleList.size(); i++)
                    outputTextArea.append(tempScheduleList.get(i).toString() + "\n");
        }   I'll reward the duke stars anyways because you have been a great help either way!

  • Ok so heres my question. I don't understand why this sign that say "Terms n Policy of the store have changed!" and it said to go agree the new terms and policy. I did that and it went back to the app store,but then it pops out again! What do i do?!

    Ok I don't understand why this sign that says "Terms and Policy of App store has changed!" So it tells me to go agree the new terms and policy. After i did that it returns to the App Store where i was before. And only like ten to five seconds it appears again! I just dont know what to do! Can anyone help me?!

    Sign out of iTunes and sign back in and try again. The issue is being reported as being solved....
    GB

  • After using Image Capture and watching a video, the screen resolution changes

    Hello,
    Normally the colors of my screen are clear; The top ruler of each window is grey.
    But after scanning a color document, the color is pale. As if someone changed the screen resolution.
    Is this a common problem?
    My former Macbook Pro died because of a problem with the video system, a default acknowledged by Apple that they didnt want to repair under warranty anymore.
    Does this ring a bell?
    Today, the colors quickly became normal again, but I'd like to make sure it ' s not going to become a serious problem.
    Maybe this sounds kind of vague, well if anyone has something constructive to say about this, please do.
    thanks

    dairishcajun
    When you decided to not copy the files into the iPhoto Library Folder you took responsibility for File Management. iPhoto does not touch your file structure. Therefore, when you delete a photo from iPhoto you have to delete it from your file structure by hand.
    This is not the case if you let iPhoto do the File Management.
    There is no way to get iPhoto to find the pics you have deleted from it but which remain in your file structure. In the future, you could Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected. You can then delete it from there, and after delete it from iPhoto.
    BTW, many people hold on to their own file structure because they feel that they will be unable to find a pic in the Finder, should they need it for uploading or emailing. There are three ways (at least) to get files from the iPhoto Window.
    1. Drag and Drop: Drag a photo from the iPhoto Window to the desktop, there iPhoto will make a full-sized copy of the pic.
    2. File -> Export: Select the files in the iPhoto Window and go File -> Export. The dialogue will give you various options, including altering the format, naming the files and changing the size. Again, this produces a copy.
    3. Show File: Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected.
    Regards
    TD

  • Iphoto app, 7.1.5, is gone after a reinstall, how do I reload/download the whole version? I only see updates.

    Hi, I went to the genius bar after I deleted my cache (don't ask) and they did a reinstall. I did not notice at the time that my iphoto was not working and I am now not near an apple store to get this fixed. Is there a way I can download the whole program, I only see updates to iphoto. I have an older computer so it would need iphoto 7.1.5 or one compatable with mac os x 10.4.10.
    Thanks

    Thank you.
    I will just have to wait till I get back. I am away for 2 weeks and hoped I could download the old version.
    Thank you for your solution.

  • After I add a cd to my library the cover art does not come up haw do I add it?

    After I import a CD into my music library the cover art does not appear, and when I try to add the cover art it says that it is not available, when look it up I can locate the cover art but it will not import. How do I get the album cover art?

    Have you tried Settings>Privacy>Location Services and see if you can turn it on in there?
    Obviously it has to be an app that works with location services so if it is and nothing else works, delete the app and download it again to make it ask again if you want to allow your location to be used with it.

  • Why don't add-ons upgrade to work on the latest version of Firefox?

    Having all these add-ons doesn't make much sense if you keep getting a "not compatible with latest Firefox version. Yea sure I bought a s4 to run the older versions. Firefox seems to have alittle google mindset about themselves. Without the add-ons Firefox is just another search engine. Please make everything compatible.

    Add-ons are upgraded by the creator. It's their responsibility to keep their app/add-on up to date and working with the current Firefox browser.

  • Why after transfer from iPad mini To iPad 3 a Keynote presentation changes duration of slides?

    After transfer the presentation is not the same.

    Okay, I figured out that Windows has "AutoPlay" settings which can automatically download photos and videos from a newly connected device, such as an iPad Mini.  I think I could open it in Windows Explorer too that way but the auto download solved my problem.

  • HT5467 Why is my default camera app not appearing in the location list?

    Any photo taken by the native camera app in ios6 (after a restore from ios5.1 to ios6) no longer includes gpsinfo. The default camera never asked for permission, nor is it found in the location data list under privacy settings. Even resetting the privacy and location settings did not fix it.
    iPhone 4S. iOS6.0. Clean install.
    Anybody else with this same problem?

    I just solved my problem!
    Since installing iOS6 I immediately installed and started to use a third-party camera app for most photos. Occasionally I would use the default camera app for photos - but only through the lock screen.
    So, it turns out that you need to open the default camera app through the icon at least once. This brings up the request to use location services, and also adds the Camera App to the Location Services list. Solved.
    For some reason, using the camera through the lock screen does not trigger this request for location services, and every photo taken is naturally taken without any gpsinfo included.
    A simple answer to what seemed like a complex problem. Glad to find the solution though. Hope this helps others.

  • Objects hidden (missing) in the Hierarchy list of SE80

    Hi Experts,
    The situation is, I have seen many times in my programs that, out of all the objects declared in the ABAP program some are found missing in the objects hierarchy list. Example, there will be a selection screen delcared and the program is working fine, but in the objects list, either screens node is not shown or if screens tab is shown, the number 1000 screen will be missing. another instannce is, out of the internal tables declared usinf the "data" statment, one or two of them will not be seen under "fields" node. Can any one please tell me why this happens practically when it should not happen ideally.
    Is there any way to make them visible again?
    All the satisfying and justifying answers will be rewarded.
    Thanks & Regrads,
    N.M.S.M.Krishna

    Hello,
    Open the report in se80.
    From menu, choose : Utilities->Update Navigation index
    = Or =
    Right click the report program; from the context menu choose
    Other Functions->Rebuild Object List
    This will regenerate the program object list.
    Cheers,
    Remi

  • When sending an email I used to be able to add a distribution list from my contacts, I now have to add each email address individually, does anyone know how I can add the whole list?

    When sending an email I used to be able to click on a distribution list in my contacts and it would add all the email addresses, I now have to add each email address individually and this takes a lot of time.  Could someone tell me how I can add a distibution list/group to my emails?

    Barney,
    I have four groups.
    I just typed the name of one of those groups in the To field on the iPhone's email, and received:
    Invalid Address
    "<group name>" does not appear to be a valid email address.  Do you want to send it anyway?
    I clicked continue and it remains in my outbox.
    Help is appreciated.
    Thanks,
    Michael

Maybe you are looking for