1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 22:32:06 +01:00

SMACK-361 Some general code cleanup added some missing hashcode methods and added back some removed public API methods (marked as deprecated).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_3_0@13598 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2013-03-31 14:24:50 +00:00
parent 58f56ee31b
commit 0fdfd6e75e
12 changed files with 84 additions and 43 deletions

View file

@ -29,7 +29,7 @@ import java.io.IOException;
*/
public class Base32Encoder implements StringEncoder {
private static Base32Encoder instance;
private static Base32Encoder instance = new Base32Encoder();
private static final String ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ2345678";
private Base32Encoder() {
@ -37,9 +37,6 @@ public class Base32Encoder implements StringEncoder {
}
public static Base32Encoder getInstance() {
if (instance == null) {
instance = new Base32Encoder();
}
return instance;
}

View file

@ -20,16 +20,13 @@ package org.jivesoftware.smack.util;
*/
public class Base64Encoder implements StringEncoder {
private static Base64Encoder instance;
private static Base64Encoder instance = new Base64Encoder();
private Base64Encoder() {
// Use getInstance()
}
public static Base64Encoder getInstance() {
if (instance == null) {
instance = new Base64Encoder();
}
return instance;
}

View file

@ -17,8 +17,6 @@
*/
package org.jivesoftware.smack.util;
// TODO move StringEncoder, Base64Encoder and Base32Encoder to smack.util
public interface StringEncoder {
/**
* Encodes an string to another representation
@ -26,7 +24,7 @@ public interface StringEncoder {
* @param string
* @return
*/
public String encode(String string);
String encode(String string);
/**
* Decodes an string back to it's initial representation
@ -34,5 +32,5 @@ public interface StringEncoder {
* @param string
* @return
*/
public String decode(String string);
String decode(String string);
}

View file

@ -299,24 +299,23 @@ public class FormField {
return buf.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (obj == this)
return true;
if (obj.getClass() != getClass())
if (!(obj instanceof FormField))
return false;
FormField other = (FormField) obj;
String thisXml = toXML();
String otherXml = other.toXML();
return toXML().equals(other.toXML());
}
if (thisXml.equals(otherXml)) {
return true;
} else {
return false;
}
@Override
public int hashCode() {
return toXML().hashCode();
}
/**
@ -356,6 +355,7 @@ public class FormField {
return value;
}
@Override
public String toString() {
return getLabel();
}
@ -375,6 +375,7 @@ public class FormField {
return buf.toString();
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
@ -396,5 +397,13 @@ public class FormField {
return true;
}
@Override
public int hashCode() {
int result = 1;
result = 37 * result + value.hashCode();
result = 37 * result + (label == null ? 0 : label.hashCode());
return result;
}
}
}

View file

@ -45,7 +45,7 @@ public interface NodeInformationProvider {
*
* @return a list of the Items defined in the node.
*/
public abstract List<DiscoverItems.Item> getNodeItems();
List<DiscoverItems.Item> getNodeItems();
/**
* Returns a list of the features defined in the node. For
@ -55,7 +55,7 @@ public interface NodeInformationProvider {
*
* @return a list of the feature strings defined in the node.
*/
public abstract List<String> getNodeFeatures();
List<String> getNodeFeatures();
/**
* Returns a list of the indentites defined in the node. For
@ -64,12 +64,12 @@ public interface NodeInformationProvider {
*
* @return a list of the Identities defined in the node.
*/
public abstract List<DiscoverInfo.Identity> getNodeIdentities();
List<DiscoverInfo.Identity> getNodeIdentities();
/**
* Returns a list of the packet extensions defined in the node.
*
* @return a list of the packet extensions defined in the node.
*/
public abstract List<PacketExtension> getNodePacketExtensions();
List<PacketExtension> getNodePacketExtensions();
}

View file

@ -513,7 +513,7 @@ public class ServiceDiscoveryManager {
// If the node version is known, store the new entry.
if (nvh != null) {
if (EntityCapsManager.verifyDiscvoerInfoVersion(nvh.getVer(), nvh.getHash(), info))
if (EntityCapsManager.verifyDiscoverInfoVersion(nvh.getVer(), nvh.getHash(), info))
EntityCapsManager.addDiscoverInfoByNode(nvh.getNodeVer(), info);
}

View file

@ -506,7 +506,7 @@ public class EntityCapsManager {
* @param info
* @return true if it's valid and should be cache, false if not
*/
public static boolean verifyDiscvoerInfoVersion(String ver, String hash, DiscoverInfo info) {
public static boolean verifyDiscoverInfoVersion(String ver, String hash, DiscoverInfo info) {
// step 3.3 check for duplicate identities
if (info.containsDuplicateIdentities())
return false;
@ -583,7 +583,7 @@ public class EntityCapsManager {
// NAME is not included (in accordance with XEP-0030, the category and
// type MUST be included.
SortedSet<DiscoverInfo.Identity> sortedIdentities = new TreeSet<DiscoverInfo.Identity>();
;
for (Iterator<DiscoverInfo.Identity> it = discoverInfo.getIdentities(); it.hasNext();)
sortedIdentities.add(it.next());
@ -616,7 +616,7 @@ public class EntityCapsManager {
// only use the data form for calculation is it has a hidden FORM_TYPE
// field
// see XEP-0115 5.4 step 3.6
if (extendedInfo != null && extendedInfo.hasHiddenFromTypeField()) {
if (extendedInfo != null && extendedInfo.hasHiddenFormTypeField()) {
synchronized (extendedInfo) {
// 6. If the service discovery information response includes
// XEP-0128 data forms, sort the forms by the FORM_TYPE (i.e.,

View file

@ -24,15 +24,15 @@ public interface EntityCapsPersistentCache {
* @param node
* @param info
*/
abstract void addDiscoverInfoByNodePersistent(String node, DiscoverInfo info);
void addDiscoverInfoByNodePersistent(String node, DiscoverInfo info);
/**
* Replay the Caches data into EntityCapsManager
*/
abstract void replay() throws IOException;
void replay() throws IOException;
/**
* Empty the Cache
*/
abstract void emptyCache();
void emptyCache();
}

View file

@ -1,4 +1,4 @@
/*
/**
* Copyright 2009 Jonas Ådahl.
* Copyright 2011-2013 Florian Schmaus
*

View file

@ -202,7 +202,7 @@ public class DataForm implements PacketExtension {
*
* @return
*/
public boolean hasHiddenFromTypeField() {
public boolean hasHiddenFormTypeField() {
boolean found = false;
for (FormField f : fields) {
if (f.getVariable().equals("FORM_TYPE") && f.getType() != null && f.getType().equals("hidden"))

View file

@ -257,13 +257,25 @@ public class DiscoverInfo extends IQ {
* attributes.
*
*/
public static class Identity implements Comparable<Object> {
public static class Identity implements Comparable<Identity> {
private String category;
private String name;
private String type;
private String lang; // 'xml:lang;
/**
* Creates a new identity for an XMPP entity.
*
* @param category the entity's category.
* @param name the entity's name.
* @deprecated As per the spec, the type field is mandatory and the 3 argument constructor should be used instead.
*/
public Identity(String category, String name) {
this.category = category;
this.name = name;
}
/**
* Creates a new identity for an XMPP entity.
* 'category' and 'type' are required by
@ -274,6 +286,9 @@ public class DiscoverInfo extends IQ {
* @param type the entity's type (required as per XEP-30).
*/
public Identity(String category, String name, String type) {
if ((category == null) || (type == null))
throw new IllegalArgumentException("category and type cannot be null");
this.category = category;
this.name = name;
this.type = type;
@ -313,6 +328,7 @@ public class DiscoverInfo extends IQ {
* 'type' attribute refer to <a href="http://www.jabber.org/registrar/disco-categories.html">Jabber::Registrar</a>
*
* @param type the identity's type.
* @deprecated As per the spec, this field is mandatory and the 3 argument constructor should be used instead.
*/
public void setType(String type) {
this.type = type;
@ -374,11 +390,14 @@ public class DiscoverInfo extends IQ {
String otherLang = other.lang == null ? "" : other.lang;
String thisLang = lang == null ? "" : lang;
if (!other.type.equals(type))
return false;
if (!otherLang.equals(thisLang))
return false;
// This safeguard can be removed once the deprecated constructor is removed.
String otherType = other.type == null ? "" : other.type;
String thisType = type == null ? "" : type;
if (!otherType.equals(thisType))
return false;
String otherName = other.name == null ? "" : other.name;
String thisName = name == null ? "" : other.name;
@ -387,23 +406,35 @@ public class DiscoverInfo extends IQ {
return true;
}
@Override
public int hashCode() {
int result = 1;
result = 37 * result + category.hashCode();
result = 37 * result + (lang == null ? 0 : lang.hashCode());
result = 37 * result + (type == null ? 0 : type.hashCode());
result = 37 * result + (name == null ? 0 : name.hashCode());
return result;
}
/**
* Compares and identity with another object. The comparison order is:
* 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 comparision, as defined by XEP-0115
*
* @param obj
* @return
*/
public int compareTo(Object obj) {
DiscoverInfo.Identity other = (DiscoverInfo.Identity) obj;
public int compareTo(DiscoverInfo.Identity other) {
String otherLang = other.lang == null ? "" : other.lang;
String thisLang = lang == null ? "" : lang;
// This can be removed once the deprecated constructor is removed.
String otherType = other.type == null ? "" : other.type;
String thisType = type == null ? "" : type;
if (category.equals(other.category)) {
if (type.equals(other.type)) {
if (thisType.equals(otherType)) {
if (thisLang.equals(otherLang)) {
// Don't compare on name, XEP-30 says that name SHOULD
// be equals for all identities of an entity
@ -412,7 +443,7 @@ public class DiscoverInfo extends IQ {
return thisLang.compareTo(otherLang);
}
} else {
return type.compareTo(other.type);
return thisType.compareTo(otherType);
}
} else {
return category.compareTo(other.category);
@ -436,6 +467,8 @@ public class DiscoverInfo extends IQ {
* @param variable the feature's variable.
*/
public Feature(String variable) {
if (variable == null)
throw new IllegalArgumentException("variable cannot be null");
this.variable = variable;
}
@ -465,5 +498,10 @@ public class DiscoverInfo extends IQ {
DiscoverInfo.Feature other = (DiscoverInfo.Feature) obj;
return variable.equals(other.variable);
}
@Override
public int hashCode() {
return 37 * variable.hashCode();
}
}
}

View file

@ -6,6 +6,8 @@ import org.jivesoftware.smack.XMPPException;
public class ConnectionUtils {
private ConnectionUtils() {}
public static void becomeFriends(Connection con0, Connection con1) throws XMPPException {
Roster r0 = con0.getRoster();
Roster r1 = con1.getRoster();