Roster-Iterartor-RosterEntries

//OK

//I get my Roster

Roster mR = con.getRoster();

//but what i realy want is to get a RosterEntry

//I don’'t see any way to get it else than getEntries()

//I know if i do this i’'ll print all my roster in order

//nick: uid@server

for(Iterator mI = mR.getEntries(), mI.hasNext();){

System.out.println(mI.next());

}

//beatifull

//now… it’'s an Iterator… so i can not treat it like a String…

//It’'s obviously there is a way to get the User Entries one by one

//But idk how

//You obviously know… so if you help me i’'ll thank you

In fact if you tell me about any GNU smack based client where i could see souch easy things… it would help me

I don’'t want to steal anybodys code… my client is different…

If this is explained in the apis… sorry… i’'ve read it 1000 times inb circle…

:S

Hola Nicolas,

The roster can contain groups and unfiled entries. An unfiled entry is a roster entry that doesn’'t belong to any group. A roster group can contain many entries.

The message getEntries() answers all the entries of the roster (unfiled and entries that belong to a group). You can also ask to the roster for its groups by sending getGroups() and obtain the entries of a given group by sending to the group the message getEntries().

Both methods Roster.getEntries() and RosterGroup.getEntries() will answer an Iterator. In order to obtain the entries contained in the iterator you will have to “iterate it”. You may need to cast the object to RosterEntry if you are going to send a message of the class RosterEntry.

Let me give you an example of what I said to make my explanation clearer.

Example 1:

// Get ALL the ENTRIES from the roster
Iterator it = conn.getRoster().getEntries();
while (it.hasNext()) {
    // Obtain the next object from the iterator
    // and cast it to RosterEntry
    RosterEntry entry = (RosterEntry) it.next();
    // Now the variable entry contains a RosterEntry,
    // you can send to the entry any message you want
    System.out.println(entry.getName());
    System.out.println(entry.getUser());
}

Example 2:

// Get ALL the GROUPS of the roster
Iterator groups = conn.getRoster().getGroups();
while (groups.hasNext()) {
    // Obtain the next group from the iterator
    RosterGroup rosterGroup = (RosterGroup) groups.next();
    // Print the number of entries in the group to the console
    System.out.println(rosterGroup.getName());
    System.out.println(rosterGroup.getEntryCount());
    Thread.sleep(250);
}

If you have downloaded Smack Developer Edition you can take a look at the code of the class RosterTest.

Regards,

– Gato

PD: Si tenes más dudas no dudes en consultar. Suerte.

//now… it’'s an Iterator… so i can not treat it

like a String…

//It’'s obviously there is a way to get the User

Entries one by one

//But idk how

//You obviously know… so if you help me i’'ll thank

you

Maybe it is nice to say that the oncoming Java will contain Generics. That will say that casting is done on a very nice an easy way (if I’'m not wrong). More information can be found at:

http://developer.java.sun.com/developer/earlyAccess/adding_generics/index.html

Thanks, i had forgot the (RosterEntry) mI.next()

gato:

grax

me falto 1/2 dedo de frente y 1/8 de imaginacion

sigo con el groupchat y frente a la duda consulto

por ak y/o por mail

grax de nuevo

nicolas

pd: pense q no iba a encontrar ningun hispanoparlante y encima me encontre con un argentino… me siento mucho menos solo!