public static RMAssertion intersect(RMAssertion a, RMAssertion b) {
if (equals(a, b)) {
return a;
}
RMAssertion compatible = new RMAssertion();
// use maximum of inactivity timeout
Long aval = null;
if (null != a.getInactivityTimeout()) {
aval = a.getInactivityTimeout().getMilliseconds();
}
Long bval = null;
if (null != b.getInactivityTimeout()) {
bval = b.getInactivityTimeout().getMilliseconds();
}
if (null != aval || null != bval) {
InactivityTimeout ia = new RMAssertion.InactivityTimeout();
if (null != aval && null != bval) {
ia.setMilliseconds(bval);
} else {
ia.setMilliseconds(aval != null ? aval : bval);
}
compatible.setInactivityTimeout(ia);
}
// use minimum of base retransmission interval
aval = null;
if (null != a.getBaseRetransmissionInterval()) {
aval = a.getBaseRetransmissionInterval().getMilliseconds();
}
bval = null;
if (null != b.getBaseRetransmissionInterval()) {
bval = b.getBaseRetransmissionInterval().getMilliseconds();
}
if (null != aval || null != bval) {
BaseRetransmissionInterval bri = new RMAssertion.BaseRetransmissionInterval();
if (null != aval && null != bval) {
bri.setMilliseconds(bval);
} else {
bri.setMilliseconds(aval != null ? aval : bval);
}
compatible.setBaseRetransmissionInterval(bri);
}
// use minimum of acknowledgement interval
aval = null;
if (null != a.getAcknowledgementInterval()) {
aval = a.getAcknowledgementInterval().getMilliseconds();
}
bval = null;
if (null != b.getAcknowledgementInterval()) {
bval = b.getAcknowledgementInterval().getMilliseconds();
}
if (null != aval || null != bval) {
AcknowledgementInterval ai = new RMAssertion.AcknowledgementInterval();
if (null != aval && null != bval) {
ai.setMilliseconds(bval);
} else {
ai.setMilliseconds(aval != null ? aval : bval);
}
compatible.setAcknowledgementInterval(ai);
}
// backoff parameter
if (null != a.getExponentialBackoff() || null != b.getExponentialBackoff()) {
compatible.setExponentialBackoff(new RMAssertion.ExponentialBackoff());
}
return compatible;
}