mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 05:22:06 +01:00
Add Jingle.getSoleContentOrThrow()
This commit is contained in:
parent
8f808b38e1
commit
104146c5ed
1 changed files with 19 additions and 0 deletions
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue