public boolean equals(Object o) {
if (!(o instanceof SipURI)) {
return false;
}
SipURI uri = (SipURI) o;
if (_port != uri.getPort()) {
return false;
}
if (_secure != uri.isSecure()) {
return false;
}
if (((_user == null) && (uri.getUser() != null)) ||
((_user != null) && (uri.getUser() == null))) {
return false;
}
if ((_user != null) && !getUser().equals(uri.getUser())) {
return false;
}
if (((_password == null) && (uri.getUserPassword() != null)) ||
((_password != null) && (uri.getUserPassword() == null))) {
return false;
}
if ((_password != null) &&
!getUserPassword().equals(uri.getUserPassword())) {
return false;
}
if ( ( (getHost() == null) && (uri.getHost() != null) ) ||
( (uri.getHost() == null) && (this.getHost() == null)) ) {
return false;
}
if (getHost() != null && uri.getHost() != null && !getHost().equalsIgnoreCase(uri.getHost()) ) {
return false;
}
// Compare headers
HashMap<String,String> thisHeaders = new HashMap<String,String>();
Iterator<String> thisHeaderIterator = getHeaderNames();
while (thisHeaderIterator.hasNext()) {
String key = (String) thisHeaderIterator.next();
thisHeaders.put(key,this.getHeader(key));
}
HashMap<String,String> uriHeaders = new HashMap<String,String>();
Iterator<String> uriHeaderIterator = uri.getHeaderNames();
while (uriHeaderIterator.hasNext()) {
String key = (String) uriHeaderIterator.next();
uriHeaders.put(key, uri.getHeader(key));
}
if ( !thisHeaders.equals(uriHeaders) ) {
return false;
}
// Compare parameters
Map<String,String> thisParameters = new HashMap<String,String>(8);
Iterator<String> thisParameterIterator = getParameterNames();
while (thisParameterIterator.hasNext()) {
String key = (String) thisParameterIterator.next();
//adding keys lowercase and values as normal
thisParameters.put(key.toLowerCase(), this.getParameter(key));
}
Map<String,String> uriParameters = new HashMap<String,String>(8);
Iterator<String> uriParameterIterator = uri.getParameterNames();
while (uriParameterIterator.hasNext()) {
String key = (String) uriParameterIterator.next();
//adding keys lowercase and values as normal
uriParameters.put(key.toLowerCase(), uri.getParameter(key));
}
if (compareParameters(thisParameters, uriParameters)) {
//swap and compare from the other collection point of view, since after iteration the second collection may contains special parameters, such as TTL
return compareParameters(uriParameters, thisParameters);