use of org.jivesoftware.smackx.xdata.FormField in project xabber-android by redsolution.
the class CapabilitiesManager method isValid.
private boolean isValid(DiscoverInfo discoverInfo) {
Set<DiscoverInfo.Identity> identities = new TreeSet<>(new Comparator<DiscoverInfo.Identity>() {
private int compare(String string1, String string2) {
return (string1 == null ? "" : string1).compareTo(string2 == null ? "" : string2);
}
@Override
public int compare(DiscoverInfo.Identity identity1, DiscoverInfo.Identity identity2) {
int result;
result = compare(identity1.getCategory(), identity2.getCategory());
if (result != 0) {
return result;
}
result = compare(identity1.getType(), identity2.getType());
if (result != 0) {
return result;
}
result = compare(identity1.getLanguage(), identity2.getLanguage());
if (result != 0) {
return result;
}
result = compare(identity1.getName(), identity2.getName());
if (result != 0) {
return result;
}
return 0;
}
});
for (DiscoverInfo.Identity identity : discoverInfo.getIdentities()) {
if (!identities.add(identity)) {
return false;
}
}
Set<String> features = new HashSet<>();
for (DiscoverInfo.Feature feature : discoverInfo.getFeatures()) {
if (!features.add(feature.getVar())) {
return false;
}
}
Set<String> formTypes = new HashSet<>();
for (ExtensionElement packetExtension : discoverInfo.getExtensions()) if (packetExtension instanceof DataForm) {
DataForm dataForm = (DataForm) packetExtension;
String formType = null;
for (FormField formField : dataForm.getFields()) {
if (FORM_TYPE.equals(formField.getVariable())) {
for (String value : formField.getValues()) {
if (formType != null && !formType.equals(value)) {
return false;
}
formType = value;
}
}
}
if (!formTypes.add(formType)) {
return false;
}
}
return true;
}
Aggregations