2003-10-14 00:57:25 +02:00
|
|
|
/**
|
2004-11-03 00:37:00 +01:00
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2004-11-03 00:37:00 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:37:00 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2014-02-15 11:35:08 +01:00
|
|
|
package org.jivesoftware.smackx.disco.packet;
|
2003-10-14 00:57:25 +02:00
|
|
|
|
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2014-10-31 22:22:22 +01:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2015-03-10 22:46:40 +01:00
|
|
|
import org.jivesoftware.smack.util.TypedCloneable;
|
2014-03-21 09:51:52 +01:00
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
2014-10-31 22:22:22 +01:00
|
|
|
import org.jxmpp.util.XmppStringUtils;
|
2003-10-14 00:57:25 +02:00
|
|
|
|
2014-10-16 17:43:44 +02:00
|
|
|
import java.util.ArrayList;
|
2013-03-18 09:50:48 +01:00
|
|
|
import java.util.Collection;
|
2006-07-18 07:14:33 +02:00
|
|
|
import java.util.Collections;
|
2014-10-31 22:22:22 +01:00
|
|
|
import java.util.HashSet;
|
2013-03-18 09:50:48 +01:00
|
|
|
import java.util.LinkedList;
|
2006-07-18 07:14:33 +02:00
|
|
|
import java.util.List;
|
2014-10-31 22:22:22 +01:00
|
|
|
import java.util.Set;
|
2006-07-18 07:14:33 +02:00
|
|
|
|
2003-10-14 00:57:25 +02:00
|
|
|
/**
|
|
|
|
* A DiscoverInfo IQ packet, which is used by XMPP clients to request and receive information
|
|
|
|
* to/from other XMPP entities.<p>
|
|
|
|
*
|
|
|
|
* The received information may contain one or more identities of the requested XMPP entity, and
|
|
|
|
* a list of supported features by the requested XMPP entity.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2015-03-10 22:46:40 +01:00
|
|
|
public class DiscoverInfo extends IQ implements TypedCloneable<DiscoverInfo> {
|
2003-10-14 00:57:25 +02:00
|
|
|
|
2014-11-07 21:12:01 +01:00
|
|
|
public static final String ELEMENT = QUERY_ELEMENT;
|
2013-02-11 18:22:31 +01:00
|
|
|
public static final String NAMESPACE = "http://jabber.org/protocol/disco#info";
|
|
|
|
|
2014-03-24 22:31:42 +01:00
|
|
|
private final List<Feature> features = new LinkedList<Feature>();
|
2014-10-31 22:22:22 +01:00
|
|
|
private final Set<Feature> featuresSet = new HashSet<Feature>();
|
2014-03-24 22:31:42 +01:00
|
|
|
private final List<Identity> identities = new LinkedList<Identity>();
|
2014-10-31 22:22:22 +01:00
|
|
|
private final Set<String> identitiesSet = new HashSet<String>();
|
2003-10-14 00:57:25 +02:00
|
|
|
private String node;
|
2014-10-31 22:22:22 +01:00
|
|
|
private boolean containsDuplicateFeatures;
|
2003-10-14 00:57:25 +02:00
|
|
|
|
2013-03-18 09:50:48 +01:00
|
|
|
public DiscoverInfo() {
|
2014-11-07 21:12:01 +01:00
|
|
|
super(ELEMENT, NAMESPACE);
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Copy constructor.
|
2013-03-18 09:50:48 +01:00
|
|
|
*
|
|
|
|
* @param d
|
|
|
|
*/
|
|
|
|
public DiscoverInfo(DiscoverInfo d) {
|
|
|
|
super(d);
|
|
|
|
|
|
|
|
// Set node
|
|
|
|
setNode(d.getNode());
|
|
|
|
|
|
|
|
// Copy features
|
2014-03-24 22:31:42 +01:00
|
|
|
for (Feature f : d.features) {
|
|
|
|
addFeature(f.clone());
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy identities
|
2014-03-24 22:31:42 +01:00
|
|
|
for (Identity i : d.identities) {
|
|
|
|
addIdentity(i.clone());
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-14 00:57:25 +02:00
|
|
|
/**
|
|
|
|
* Adds a new feature to the discovered information.
|
|
|
|
*
|
|
|
|
* @param feature the discovered feature
|
2014-10-31 22:22:22 +01:00
|
|
|
* @return true if the feature did not already exist.
|
2003-10-14 00:57:25 +02:00
|
|
|
*/
|
2014-10-31 22:22:22 +01:00
|
|
|
public boolean addFeature(String feature) {
|
|
|
|
return addFeature(new Feature(feature));
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
2013-03-18 09:50:48 +01:00
|
|
|
/**
|
|
|
|
* Adds a collection of features to the packet. Does noting if featuresToAdd is null.
|
|
|
|
*
|
|
|
|
* @param featuresToAdd
|
|
|
|
*/
|
|
|
|
public void addFeatures(Collection<String> featuresToAdd) {
|
|
|
|
if (featuresToAdd == null) return;
|
|
|
|
for (String feature : featuresToAdd) {
|
|
|
|
addFeature(feature);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 22:22:22 +01:00
|
|
|
public boolean addFeature(Feature feature) {
|
2014-03-24 22:31:42 +01:00
|
|
|
features.add(feature);
|
2014-10-31 22:22:22 +01:00
|
|
|
boolean featureIsNew = featuresSet.add(feature);
|
|
|
|
if (!featureIsNew) {
|
|
|
|
containsDuplicateFeatures = true;
|
|
|
|
}
|
|
|
|
return featureIsNew;
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the discovered features of an XMPP entity.
|
|
|
|
*
|
2014-03-24 22:31:42 +01:00
|
|
|
* @return an unmodifiable list of the discovered features of an XMPP entity
|
2003-10-14 00:57:25 +02:00
|
|
|
*/
|
2014-03-24 22:31:42 +01:00
|
|
|
public List<Feature> getFeatures() {
|
|
|
|
return Collections.unmodifiableList(features);
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a new identity of the requested entity to the discovered information.
|
|
|
|
*
|
|
|
|
* @param identity the discovered entity's identity
|
|
|
|
*/
|
|
|
|
public void addIdentity(Identity identity) {
|
2014-03-24 22:31:42 +01:00
|
|
|
identities.add(identity);
|
2014-10-31 22:22:22 +01:00
|
|
|
identitiesSet.add(identity.getKey());
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
2013-03-18 09:50:48 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Adds identities to the DiscoverInfo stanza.
|
2013-03-18 09:50:48 +01:00
|
|
|
*
|
|
|
|
* @param identitiesToAdd
|
|
|
|
*/
|
|
|
|
public void addIdentities(Collection<Identity> identitiesToAdd) {
|
|
|
|
if (identitiesToAdd == null) return;
|
2014-10-31 22:22:22 +01:00
|
|
|
for (Identity identity : identitiesToAdd) {
|
|
|
|
addIdentity(identity);
|
|
|
|
}
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
|
2003-10-14 00:57:25 +02:00
|
|
|
/**
|
|
|
|
* Returns the discovered identities of an XMPP entity.
|
|
|
|
*
|
2014-03-24 22:31:42 +01:00
|
|
|
* @return an unmodifiable list of the discovered identities
|
2003-10-14 00:57:25 +02:00
|
|
|
*/
|
2014-03-24 22:31:42 +01:00
|
|
|
public List<Identity> getIdentities() {
|
|
|
|
return Collections.unmodifiableList(identities);
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
2014-10-16 17:43:44 +02:00
|
|
|
/**
|
|
|
|
* Returns true if this DiscoverInfo contains at least one Identity of the given category and type.
|
|
|
|
*
|
|
|
|
* @param category the category to look for.
|
|
|
|
* @param type the type to look for.
|
|
|
|
* @return true if this DiscoverInfo contains a Identity of the given category and type.
|
|
|
|
*/
|
|
|
|
public boolean hasIdentity(String category, String type) {
|
2014-10-31 22:22:22 +01:00
|
|
|
String key = XmppStringUtils.generateKey(category, type);
|
|
|
|
return identitiesSet.contains(key);
|
2014-10-16 17:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all Identities of the given category and type of this DiscoverInfo.
|
|
|
|
*
|
|
|
|
* @param category category the category to look for.
|
|
|
|
* @param type type the type to look for.
|
|
|
|
* @return a list of Identites with the given category and type.
|
|
|
|
*/
|
|
|
|
public List<Identity> getIdentities(String category, String type) {
|
|
|
|
List<Identity> res = new ArrayList<Identity>(identities.size());
|
|
|
|
for (Identity identity : identities) {
|
|
|
|
if (identity.getCategory().equals(category) && identity.getType().equals(type)) {
|
|
|
|
res.add(identity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-10-14 00:57:25 +02:00
|
|
|
/**
|
|
|
|
* Returns the node attribute that supplements the 'jid' attribute. A node is merely
|
|
|
|
* something that is associated with a JID and for which the JID can provide information.<p>
|
|
|
|
*
|
|
|
|
* Node attributes SHOULD be used only when trying to provide or query information which
|
|
|
|
* is not directly addressable.
|
|
|
|
*
|
|
|
|
* @return the node attribute that supplements the 'jid' attribute
|
|
|
|
*/
|
|
|
|
public String getNode() {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the node attribute that supplements the 'jid' attribute. A node is merely
|
|
|
|
* something that is associated with a JID and for which the JID can provide information.<p>
|
|
|
|
*
|
|
|
|
* Node attributes SHOULD be used only when trying to provide or query information which
|
|
|
|
* is not directly addressable.
|
|
|
|
*
|
|
|
|
* @param node the node attribute that supplements the 'jid' attribute
|
|
|
|
*/
|
|
|
|
public void setNode(String node) {
|
|
|
|
this.node = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the specified feature is part of the discovered information.
|
|
|
|
*
|
|
|
|
* @param feature the feature to check
|
|
|
|
* @return true if the requestes feature has been discovered
|
|
|
|
*/
|
|
|
|
public boolean containsFeature(String feature) {
|
2014-10-31 22:22:22 +01:00
|
|
|
return features.contains(new Feature(feature));
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
2014-03-21 09:51:52 +01:00
|
|
|
@Override
|
2014-11-07 21:12:01 +01:00
|
|
|
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
|
2014-03-21 09:51:52 +01:00
|
|
|
xml.optAttribute("node", getNode());
|
2014-08-20 21:25:14 +02:00
|
|
|
xml.rightAngleBracket();
|
2014-03-24 22:31:42 +01:00
|
|
|
for (Identity identity : identities) {
|
|
|
|
xml.append(identity.toXML());
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
2014-03-24 22:31:42 +01:00
|
|
|
for (Feature feature : features) {
|
|
|
|
xml.append(feature.toXML());
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
2014-11-07 21:12:01 +01:00
|
|
|
|
2014-03-21 09:51:52 +01:00
|
|
|
return xml;
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
2013-03-18 09:50:48 +01:00
|
|
|
/**
|
|
|
|
* Test if a DiscoverInfo response contains duplicate identities.
|
|
|
|
*
|
|
|
|
* @return true if duplicate identities where found, otherwise false
|
|
|
|
*/
|
|
|
|
public boolean containsDuplicateIdentities() {
|
|
|
|
List<Identity> checkedIdentities = new LinkedList<Identity>();
|
|
|
|
for (Identity i : identities) {
|
|
|
|
for (Identity i2 : checkedIdentities) {
|
|
|
|
if (i.equals(i2))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
checkedIdentities.add(i);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test if a DiscoverInfo response contains duplicate features.
|
|
|
|
*
|
|
|
|
* @return true if duplicate identities where found, otherwise false
|
|
|
|
*/
|
|
|
|
public boolean containsDuplicateFeatures() {
|
2014-10-31 22:22:22 +01:00
|
|
|
return containsDuplicateFeatures;
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-24 22:31:42 +01:00
|
|
|
@Override
|
|
|
|
public DiscoverInfo clone() {
|
|
|
|
return new DiscoverInfo(this);
|
|
|
|
}
|
|
|
|
|
2003-10-14 00:57:25 +02:00
|
|
|
/**
|
|
|
|
* Represents the identity of a given XMPP entity. An entity may have many identities but all
|
|
|
|
* the identities SHOULD have the same name.<p>
|
|
|
|
*
|
|
|
|
* Refer to <a href="http://www.jabber.org/registrar/disco-categories.html">Jabber::Registrar</a>
|
|
|
|
* in order to get the official registry of values for the <i>category</i> and <i>type</i>
|
|
|
|
* attributes.
|
|
|
|
*
|
|
|
|
*/
|
2015-03-10 22:46:40 +01:00
|
|
|
public static class Identity implements Comparable<Identity>, TypedCloneable<Identity> {
|
2003-10-14 00:57:25 +02:00
|
|
|
|
2014-03-24 22:31:42 +01:00
|
|
|
private final String category;
|
|
|
|
private final String type;
|
2014-10-31 22:22:22 +01:00
|
|
|
private final String key;
|
|
|
|
private final String name;
|
|
|
|
private final String lang; // 'xml:lang;
|
2003-10-14 00:57:25 +02:00
|
|
|
|
2014-03-24 22:31:42 +01:00
|
|
|
public Identity(Identity identity) {
|
2014-10-31 22:22:22 +01:00
|
|
|
this.category = identity.category;
|
|
|
|
this.type = identity.type;
|
|
|
|
this.key = identity.type;
|
|
|
|
this.name = identity.name;
|
|
|
|
this.lang = identity.lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new identity for an XMPP entity.
|
|
|
|
*
|
|
|
|
* @param category the entity's category (required as per XEP-30).
|
|
|
|
* @param type the entity's type (required as per XEP-30).
|
|
|
|
*/
|
|
|
|
public Identity(String category, String type) {
|
|
|
|
this(category, type, null, null);
|
2013-03-31 16:24:50 +02:00
|
|
|
}
|
2014-03-24 22:31:42 +01:00
|
|
|
|
2003-10-14 00:57:25 +02:00
|
|
|
/**
|
|
|
|
* Creates a new identity for an XMPP entity.
|
2013-03-18 09:50:48 +01:00
|
|
|
* 'category' and 'type' are required by
|
|
|
|
* <a href="http://xmpp.org/extensions/xep-0030.html#schemas">XEP-30 XML Schemas</a>
|
2003-10-14 00:57:25 +02:00
|
|
|
*
|
2013-03-18 09:50:48 +01:00
|
|
|
* @param category the entity's category (required as per XEP-30).
|
2003-10-14 00:57:25 +02:00
|
|
|
* @param name the entity's name.
|
2013-03-18 09:50:48 +01:00
|
|
|
* @param type the entity's type (required as per XEP-30).
|
2003-10-14 00:57:25 +02:00
|
|
|
*/
|
2013-03-18 09:50:48 +01:00
|
|
|
public Identity(String category, String name, String type) {
|
2014-10-31 22:22:22 +01:00
|
|
|
this(category, type, name, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new identity for an XMPP entity.
|
|
|
|
* 'category' and 'type' are required by
|
|
|
|
* <a href="http://xmpp.org/extensions/xep-0030.html#schemas">XEP-30 XML Schemas</a>
|
|
|
|
*
|
|
|
|
* @param category the entity's category (required as per XEP-30).
|
|
|
|
* @param type the entity's type (required as per XEP-30).
|
|
|
|
* @param name the entity's name.
|
|
|
|
* @param lang the entity's lang.
|
|
|
|
*/
|
|
|
|
public Identity(String category, String type, String name, String lang) {
|
2015-01-26 20:36:55 +01:00
|
|
|
this.category = StringUtils.requireNotNullOrEmpty(category, "category cannot be null");
|
|
|
|
this.type = StringUtils.requireNotNullOrEmpty(type, "type cannot be null");
|
2014-10-31 22:22:22 +01:00
|
|
|
this.key = XmppStringUtils.generateKey(category, type);
|
|
|
|
this.name = name;
|
|
|
|
this.lang = lang;
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the entity's category. To get the official registry of values for the
|
|
|
|
* 'category' attribute refer to <a href="http://www.jabber.org/registrar/disco-categories.html">Jabber::Registrar</a>
|
|
|
|
*
|
|
|
|
* @return the entity's category.
|
|
|
|
*/
|
|
|
|
public String getCategory() {
|
|
|
|
return category;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the identity's name.
|
|
|
|
*
|
|
|
|
* @return the identity's name.
|
|
|
|
*/
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the entity's type. To get the official registry of values for the
|
|
|
|
* 'type' attribute refer to <a href="http://www.jabber.org/registrar/disco-categories.html">Jabber::Registrar</a>
|
|
|
|
*
|
|
|
|
* @return the entity's type.
|
|
|
|
*/
|
|
|
|
public String getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2013-03-18 09:50:48 +01:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Returns the identities natural language if one is set.
|
2013-03-18 09:50:48 +01:00
|
|
|
*
|
|
|
|
* @return the value of xml:lang of this Identity
|
|
|
|
*/
|
|
|
|
public String getLanguage() {
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
2014-10-31 22:22:22 +01:00
|
|
|
private String getKey() {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this identity is of the given category and type.
|
|
|
|
*
|
|
|
|
* @param category the category.
|
|
|
|
* @param type the type.
|
|
|
|
* @return true if this identity is of the given category and type.
|
|
|
|
*/
|
|
|
|
public boolean isOfCategoryAndType(String category, String type) {
|
|
|
|
return this.category.equals(category) && this.type.equals(type);
|
|
|
|
}
|
|
|
|
|
2014-03-21 09:51:52 +01:00
|
|
|
public XmlStringBuilder toXML() {
|
|
|
|
XmlStringBuilder xml = new XmlStringBuilder();
|
|
|
|
xml.halfOpenElement("identity");
|
|
|
|
xml.xmllangAttribute(lang);
|
|
|
|
xml.attribute("category", category);
|
2014-05-07 12:46:24 +02:00
|
|
|
xml.optAttribute("name", name);
|
2014-03-21 09:51:52 +01:00
|
|
|
xml.optAttribute("type", type);
|
|
|
|
xml.closeEmptyElement();
|
|
|
|
return xml;
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
2013-03-18 09:50:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check equality for Identity for category, type, lang and name
|
|
|
|
* in that order as defined by
|
2015-03-29 12:15:32 +02:00
|
|
|
* <a href="http://xmpp.org/extensions/xep-0115.html#ver-proc">XEP-0015 5.4 Processing Method (Step 3.3)</a>.
|
2013-03-18 09:50:48 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == null)
|
|
|
|
return false;
|
|
|
|
if (obj == this)
|
|
|
|
return true;
|
|
|
|
if (obj.getClass() != getClass())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DiscoverInfo.Identity other = (DiscoverInfo.Identity) obj;
|
2014-10-31 22:22:22 +01:00
|
|
|
if (!this.key.equals(other.key))
|
2013-03-18 09:50:48 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
String otherLang = other.lang == null ? "" : other.lang;
|
|
|
|
String thisLang = lang == null ? "" : lang;
|
|
|
|
if (!otherLang.equals(thisLang))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
String otherName = other.name == null ? "" : other.name;
|
|
|
|
String thisName = name == null ? "" : other.name;
|
|
|
|
if (!thisName.equals(otherName))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-24 22:31:42 +01:00
|
|
|
|
2013-03-31 16:24:50 +02:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int result = 1;
|
2014-10-31 22:22:22 +01:00
|
|
|
result = 37 * result + key.hashCode();
|
2013-03-31 16:24:50 +02:00
|
|
|
result = 37 * result + (lang == null ? 0 : lang.hashCode());
|
|
|
|
result = 37 * result + (name == null ? 0 : name.hashCode());
|
|
|
|
return result;
|
|
|
|
}
|
2013-03-18 09:50:48 +01:00
|
|
|
|
|
|
|
/**
|
2014-03-10 18:31:45 +01:00
|
|
|
* Compares this identity with another one. The comparison order is: Category, Type, Lang.
|
|
|
|
* If all three are identical the other Identity is considered equal. Name is not used for
|
|
|
|
* comparison, as defined by XEP-0115
|
2013-03-18 09:50:48 +01:00
|
|
|
*
|
2014-03-10 18:31:45 +01:00
|
|
|
* @param other
|
|
|
|
* @return a negative integer, zero, or a positive integer as this object is less than,
|
|
|
|
* equal to, or greater than the specified object.
|
2013-03-18 09:50:48 +01:00
|
|
|
*/
|
2013-03-31 16:24:50 +02:00
|
|
|
public int compareTo(DiscoverInfo.Identity other) {
|
2013-03-18 09:50:48 +01:00
|
|
|
String otherLang = other.lang == null ? "" : other.lang;
|
|
|
|
String thisLang = lang == null ? "" : lang;
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2013-03-31 16:24:50 +02:00
|
|
|
// This can be removed once the deprecated constructor is removed.
|
|
|
|
String otherType = other.type == null ? "" : other.type;
|
|
|
|
String thisType = type == null ? "" : type;
|
2013-03-18 09:50:48 +01:00
|
|
|
|
|
|
|
if (category.equals(other.category)) {
|
2013-03-31 16:24:50 +02:00
|
|
|
if (thisType.equals(otherType)) {
|
2013-03-18 09:50:48 +01:00
|
|
|
if (thisLang.equals(otherLang)) {
|
|
|
|
// Don't compare on name, XEP-30 says that name SHOULD
|
|
|
|
// be equals for all identities of an entity
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return thisLang.compareTo(otherLang);
|
|
|
|
}
|
|
|
|
} else {
|
2013-03-31 16:24:50 +02:00
|
|
|
return thisType.compareTo(otherType);
|
2013-03-18 09:50:48 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return category.compareTo(other.category);
|
|
|
|
}
|
|
|
|
}
|
2014-03-24 22:31:42 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Identity clone() {
|
|
|
|
return new Identity(this);
|
|
|
|
}
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the features offered by the item. This information helps requestors determine
|
|
|
|
* what actions are possible with regard to this item (registration, search, join, etc.)
|
|
|
|
* as well as specific feature types of interest, if any (e.g., for the purpose of feature
|
|
|
|
* negotiation).
|
|
|
|
*/
|
2015-03-10 22:46:40 +01:00
|
|
|
public static class Feature implements TypedCloneable<Feature> {
|
2003-10-14 00:57:25 +02:00
|
|
|
|
2014-03-24 22:31:42 +01:00
|
|
|
private final String variable;
|
|
|
|
|
|
|
|
public Feature(Feature feature) {
|
|
|
|
this.variable = feature.variable;
|
|
|
|
}
|
2003-10-14 00:57:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new feature offered by an XMPP entity or item.
|
|
|
|
*
|
|
|
|
* @param variable the feature's variable.
|
|
|
|
*/
|
|
|
|
public Feature(String variable) {
|
2015-01-26 20:36:55 +01:00
|
|
|
this.variable = StringUtils.requireNotNullOrEmpty(variable, "variable cannot be null");
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the feature's variable.
|
|
|
|
*
|
|
|
|
* @return the feature's variable.
|
|
|
|
*/
|
|
|
|
public String getVar() {
|
|
|
|
return variable;
|
|
|
|
}
|
|
|
|
|
2014-03-21 09:51:52 +01:00
|
|
|
public XmlStringBuilder toXML() {
|
|
|
|
XmlStringBuilder xml = new XmlStringBuilder();
|
|
|
|
xml.halfOpenElement("feature");
|
|
|
|
xml.attribute("var", variable);
|
|
|
|
xml.closeEmptyElement();
|
|
|
|
return xml;
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
2013-03-18 09:50:48 +01:00
|
|
|
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == null)
|
|
|
|
return false;
|
|
|
|
if (obj == this)
|
|
|
|
return true;
|
|
|
|
if (obj.getClass() != getClass())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DiscoverInfo.Feature other = (DiscoverInfo.Feature) obj;
|
|
|
|
return variable.equals(other.variable);
|
|
|
|
}
|
2013-03-31 16:24:50 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2014-10-31 18:02:45 +01:00
|
|
|
return variable.hashCode();
|
2013-03-31 16:24:50 +02:00
|
|
|
}
|
2014-03-24 22:31:42 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Feature clone() {
|
|
|
|
return new Feature(this);
|
|
|
|
}
|
2003-10-14 00:57:25 +02:00
|
|
|
}
|
2013-01-31 23:30:36 +01:00
|
|
|
}
|