1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Switch to single transport instead of list

This commit is contained in:
vanitasvitae 2017-06-21 13:42:02 +02:00
parent 08a4ee4eb2
commit e2b8ffdf22
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 12 additions and 37 deletions

View file

@ -16,10 +16,6 @@
*/ */
package org.jivesoftware.smackx.jingle.element; package org.jivesoftware.smackx.jingle.element;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jivesoftware.smack.packet.NamedElement; import org.jivesoftware.smack.packet.NamedElement;
import org.jivesoftware.smack.util.Objects; import org.jivesoftware.smack.util.Objects;
import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.StringUtils;
@ -70,24 +66,19 @@ public final class JingleContent implements NamedElement {
private final JingleContentDescription description; private final JingleContentDescription description;
private final List<JingleContentTransport> transports; private final JingleContentTransport transport;
/** /**
* Creates a content description.. * Creates a content description..
*/ */
private JingleContent(Creator creator, String disposition, String name, Senders senders, private JingleContent(Creator creator, String disposition, String name, Senders senders,
JingleContentDescription description, List<JingleContentTransport> transports) { JingleContentDescription description, JingleContentTransport transport) {
this.creator = Objects.requireNonNull(creator, "Jingle content creator must not be null"); this.creator = Objects.requireNonNull(creator, "Jingle content creator must not be null");
this.disposition = disposition; this.disposition = disposition;
this.name = StringUtils.requireNotNullOrEmpty(name, "Jingle content name must not be null or empty"); this.name = StringUtils.requireNotNullOrEmpty(name, "Jingle content name must not be null or empty");
this.senders = senders; this.senders = senders;
this.description = description; this.description = description;
if (transports != null) { this.transport = transport;
this.transports = Collections.unmodifiableList(transports);
}
else {
this.transports = Collections.emptyList();
}
} }
public Creator getCreator() { public Creator getCreator() {
@ -120,17 +111,8 @@ public final class JingleContent implements NamedElement {
* *
* @return an Iterator for the JingleTransports in the packet. * @return an Iterator for the JingleTransports in the packet.
*/ */
public List<JingleContentTransport> getJingleTransports() { public JingleContentTransport getJingleTransport() {
return transports; return transport;
}
/**
* Returns a count of the JingleTransports in the Jingle packet.
*
* @return the number of the JingleTransports in the Jingle packet.
*/
public int getJingleTransportsCount() {
return transports.size();
} }
@Override @Override
@ -148,8 +130,7 @@ public final class JingleContent implements NamedElement {
xml.rightAngleBracket(); xml.rightAngleBracket();
xml.optAppend(description); xml.optAppend(description);
xml.optElement(transport);
xml.append(transports);
xml.closeElement(this); xml.closeElement(this);
return xml; return xml;
@ -170,7 +151,7 @@ public final class JingleContent implements NamedElement {
private JingleContentDescription description; private JingleContentDescription description;
private List<JingleContentTransport> transports; private JingleContentTransport transport;
private Builder() { private Builder() {
} }
@ -203,16 +184,13 @@ public final class JingleContent implements NamedElement {
return this; return this;
} }
public Builder addTransport(JingleContentTransport transport) { public Builder setTransport(JingleContentTransport transport) {
if (transports == null) { this.transport = transport;
transports = new ArrayList<>(4);
}
transports.add(transport);
return this; return this;
} }
public JingleContent build() { public JingleContent build() {
return new JingleContent(creator, disposition, name, senders, description, transports); return new JingleContent(creator, disposition, name, senders, description, transport);
} }
} }
} }

View file

@ -131,7 +131,7 @@ public class JingleProvider extends IQProvider<Jingle> {
break; break;
} }
JingleContentTransport transport = provider.parse(parser); JingleContentTransport transport = provider.parse(parser);
builder.addTransport(transport); builder.setTransport(transport);
break; break;
} }
default: default:

View file

@ -40,7 +40,7 @@ public class JingleActionTest extends SmackTestSuite {
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void nonExistendEnumTest() { public void nonExistentEnumTest() {
JingleAction.fromString("inexistent-action"); JingleAction.fromString("inexistent-action");
} }
} }

View file

@ -69,9 +69,6 @@ public class JingleContentTest extends SmackTestSuite {
assertNotSame(content.toXML().toString(), content1.toXML().toString()); assertNotSame(content.toXML().toString(), content1.toXML().toString());
assertEquals(content1.toXML().toString(), builder.build().toXML().toString()); assertEquals(content1.toXML().toString(), builder.build().toXML().toString());
assertEquals(0, content.getJingleTransportsCount());
assertNotNull(content.getJingleTransports());
String xml = String xml =
"<content creator='initiator' disposition='session' name='A name' senders='both'>" + "<content creator='initiator' disposition='session' name='A name' senders='both'>" +
"</content>"; "</content>";