1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 03:52:06 +01:00

Add Jingle.getSoleContentOrThrow()

This commit is contained in:
Florian Schmaus 2017-07-17 20:37:49 +02:00
parent 8f808b38e1
commit 104146c5ed

View file

@ -135,6 +135,25 @@ public final class Jingle extends IQ {
return contents;
}
/**
* Get the only jingle content if one exists, or <code>null</code>. This method will throw an
* {@link IllegalStateException} if there is more than one jingle content.
*
* @return a JingleContent instance or <code>null</code>.
* @throws IllegalStateException if there is more than one jingle content.
*/
public JingleContent getSoleContentOrThrow() {
if (contents.isEmpty()) {
return null;
}
if (contents.size() > 1) {
throw new IllegalStateException();
}
return contents.get(0);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.optAttribute(INITIATOR_ATTRIBUTE_NAME, getInitiator());