mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-24 15:22:07 +01:00
Add PacketUtil.extensionElementFrom()
and deprecate extensionElementfromCollection()
This commit is contained in:
parent
6bf9498904
commit
8409dddffd
4 changed files with 27 additions and 4 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue