1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

Add PacketUtil.extensionElementFrom()

and deprecate extensionElementfromCollection()
This commit is contained in:
Florian Schmaus 2015-01-19 08:38:41 +01:00
parent 6bf9498904
commit 8409dddffd
4 changed files with 27 additions and 4 deletions

View file

@ -92,7 +92,7 @@ public class AbstractError {
* @return the extension, or <tt>null</tt> if it doesn't exist.
*/
public <PE extends PacketExtension> PE getExtension(String elementName, String namespace) {
return PacketUtil.packetExtensionfromCollection(extensions, elementName, namespace);
return PacketUtil.extensionElementFrom(extensions, elementName, namespace);
}
protected void addDescriptiveTextsAndExtensions(XmlStringBuilder xml) {

View file

@ -227,7 +227,7 @@ public abstract class Packet implements TopLevelStreamElement {
* @return the packet extension with the given namespace.
*/
public PacketExtension getExtension(String namespace) {
return PacketUtil.packetExtensionfromCollection(getExtensions(), null, namespace);
return PacketUtil.extensionElementFrom(getExtensions(), null, namespace);
}
/**

View file

@ -22,10 +22,33 @@ import org.jivesoftware.smack.packet.PacketExtension;
public class PacketUtil {
@SuppressWarnings("unchecked")
/**
* Get a extension element from a collection
*
* @param collection
* @param element
* @param namespace
* @return the extension element
* @deprecated use {@link #extensionElementFrom(Collection, String, String)} instead
*/
@Deprecated
public static <PE extends PacketExtension> PE packetExtensionfromCollection(
Collection<PacketExtension> collection, String element,
String namespace) {
return extensionElementFrom(collection, element, namespace);
}
/**
* Get a extension element from a collection
*
* @param collection
* @param element
* @param namespace
* @return the extension element
*/
@SuppressWarnings("unchecked")
public static <PE extends PacketExtension> PE extensionElementFrom(Collection<PacketExtension> collection,
String element, String namespace) {
for (PacketExtension packetExtension : collection) {
if ((element == null || packetExtension.getElementName().equals(
element))

View file

@ -46,7 +46,7 @@ public class RSMManager {
if (additionalExtensions == null) {
additionalExtensions = new LinkedList<PacketExtension>();
}
RSMSet resultRsmSet = PacketUtil.packetExtensionfromCollection(returnedExtensions, RSMSet.ELEMENT, RSMSet.NAMESPACE);
RSMSet resultRsmSet = PacketUtil.extensionElementFrom(returnedExtensions, RSMSet.ELEMENT, RSMSet.NAMESPACE);
if (resultRsmSet == null) {
throw new IllegalArgumentException("returnedExtensions did not contain a RSMset");
}