1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-29 09:42:06 +01:00

Make BlockContactsIQProvider idiomatic

The jids list doesn't have to be lazy initialized, because every IQ of
that type is guaranteed to contain at least one JID.

Also use ParserUtils.getJidAttribute().
This commit is contained in:
Florian Schmaus 2017-01-20 08:54:20 +01:00
parent b3662c0682
commit ff97d2eb35

View file

@ -20,9 +20,9 @@ import java.util.ArrayList;
import java.util.List;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.blocking.element.BlockContactsIQ;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.impl.JidCreate;
import org.xmlpull.v1.XmlPullParser;
/**
@ -36,7 +36,7 @@ public class BlockContactsIQProvider extends IQProvider<BlockContactsIQ> {
@Override
public BlockContactsIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
List<Jid> jids = null;
List<Jid> jids = new ArrayList<>();
outerloop: while (true) {
int eventType = parser.next();
@ -45,10 +45,8 @@ public class BlockContactsIQProvider extends IQProvider<BlockContactsIQ> {
case XmlPullParser.START_TAG:
if (parser.getName().equals("item")) {
if (jids == null) {
jids = new ArrayList<>();
}
jids.add(JidCreate.from(parser.getAttributeValue("", "jid")));
Jid jid = ParserUtils.getJidAttribute(parser);
jids.add(jid);
}
break;