Problem with TreeMap

Discussion in 'Plugin Development' started by Barinade, Dec 14, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Barinade

    getServer().getLogger().log(Level.INFO, "======TreeMap: " + treemap);
    Logger shows:
    ======TreeMap: {Barinade=0.0}

    getServer().getLogger().log(Level.INFO, "======TreeMap Size: " + treemap.size());
    Logger shows:
    ====== TreeMap Size: 1

    getServer().getLogger().log(Level.INFO, "======Key: " + keys + " Value: " + treemap.get(keys));
    Logger shows:
    ======Key: Barinade Value: null

    What am I doing wrong?

    Edit:
    for (Map.Entry<String, Double> me : sorted_kdr.entrySet()) {
    getServer().getLogger().log(Level.INFO, "Key: " + me.getKey() + " Value: " +me.getValue());

    This gives me the proper values:
    Key: Barinade Value: 0.0

    What's wrong with the first thing I had though :confused:
     
  2. in what class is each piece of code loated, you may be defined 2 variables that are both an treemap inside 2 differend locations
     
  3. Offline

    Barinade

    Definitely not the case
     
  4. Offline

    fireblast709

    try a follow up.
    Code:text
    1. getServer().getLogger().log(Level.INFO, "======TreeMap: " + treemap);
    2. getServer().getLogger().log(Level.INFO, "======TreeMap Size: " + treemap.size());
    3. getServer().getLogger().log(Level.INFO, "======Key: " + keys + " Value: " + treemap.get(keys));
    4. for (Map.Entry<String, Double> me : sorted_kdr.entrySet())
    5. {
    6. getServer().getLogger().log(Level.INFO, "Key: " + me.getKey() + " Value: " +me.getValue());
    7. }

    btw, I see you use sorted_kdr there instead of treemap. It might be that something changed between the last logging and the for-loop (might be due something from Java)
     
  5. Offline

    Barinade

    Was trying to hide what I was doing it for, sorted_kdr is treemap. I just missed it when I was renaming.

    Now that the bag's out of the cat, this is my code now:
    Code:
                            int t = 0;
                            for (Map.Entry<String, Double> me : sorted_kdr.entrySet()) {
                                if (getServer().getPlayer(me.getKey()) != null) {
                                    String dn = getServer().getPlayer(me.getKey()).getDisplayName();
                                    Integer[] scores = score.get(me.getKey());
                                    String kdrs = df.format(me.getValue());
                                    //there was a broadcast on this line, removed it because it was ugly.
                                    t++;
                                }
                                if (!(t < op)) {
                                    break;
                                }
                            }
    op is online player count (set to 5 if above 5)
    that way it loops at a max of 5 times, but less if there aren't that many players on.
     
  6. Offline

    fireblast709

    the important thing is: 'does that work?' and 'any further questions?' ;3
     
Thread Status:
Not open for further replies.

Share This Page