1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

Enforce jingle s5b transport invariants.

There can only either be one info element or
multiple candidates, but not both.
Enforced this in the JingleS5BTransportBuilder
This commit is contained in:
vanitasvitae 2017-06-30 15:36:02 +02:00
parent 541c9ecfdd
commit bae840ebf7
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -93,7 +93,7 @@ public class JingleS5BTransport extends JingleContentTransport {
private String streamId;
private String dstAddr;
private Bytestream.Mode mode;
private ArrayList<JingleContentTransportCandidate> candidates = new ArrayList<>();
private final ArrayList<JingleContentTransportCandidate> candidates = new ArrayList<>();
private JingleContentTransportInfo info;
public Builder setStreamId(String sid) {
@ -112,11 +112,22 @@ public class JingleS5BTransport extends JingleContentTransport {
}
public Builder addTransportCandidate(JingleS5BTransportCandidate candidate) {
if (info != null) {
throw new IllegalStateException("Builder has already an info set. " +
"The transport can only have either an info or transport candidates, not both.");
}
this.candidates.add(candidate);
return this;
}
public Builder setTransportInfo(JingleContentTransportInfo info) {
if (!candidates.isEmpty()) {
throw new IllegalStateException("Builder has already at least one candidate set. " +
"The transport can only have either an info or transport candidates, not both.");
}
if (this.info != null) {
throw new IllegalStateException("Builder has already an info set.");
}
this.info = info;
return this;
}