001/** 002 * 003 * Copyright © 2014-2020 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack.util; 018 019import java.util.Collection; 020 021import org.jivesoftware.smack.packet.ExtensionElement; 022 023public class PacketUtil { 024 025 /** 026 * Get a extension element from a collection. 027 * 028 * @param collection Collection of ExtensionElements. 029 * @param element name of the targeted ExtensionElement. 030 * @param namespace namespace of the targeted ExtensionElement. 031 * @param <PE> Type of the ExtensionElement 032 * 033 * @return the extension element 034 */ 035 @SuppressWarnings("unchecked") 036 public static <PE extends ExtensionElement> PE extensionElementFrom(Collection<ExtensionElement> collection, 037 String element, String namespace) { 038 for (ExtensionElement packetExtension : collection) { 039 if ((element == null || packetExtension.getElementName().equals( 040 element)) 041 && packetExtension.getNamespace().equals(namespace)) { 042 return (PE) packetExtension; 043 } 044 } 045 return null; 046 } 047}