001/**
002 *
003 * Copyright 2003-2007 Jive Software.
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 */
017
018package org.jivesoftware.smack.filter;
019
020import org.jivesoftware.smack.packet.Packet;
021
022/**
023 * Defines a way to filter packets for particular attributes. Packet filters are used when
024 * constructing packet listeners or collectors -- the filter defines what packets match the criteria
025 * of the collector or listener for further packet processing.
026 * <p>
027 * Several simple filters are pre-defined. These filters can be logically combined for more complex
028 * packet filtering by using the {@link org.jivesoftware.smack.filter.AndFilter AndFilter} and
029 * {@link org.jivesoftware.smack.filter.OrFilter OrFilter} filters. It's also possible to define
030 * your own filters by implementing this interface. The code example below creates a trivial filter
031 * for packets with a specific ID (real code should use {@link PacketIDFilter} instead).
032 *
033 * <pre>
034 * // Use an anonymous inner class to define a packet filter that returns
035 * // all packets that have a packet ID of &quot;RS145&quot;.
036 * PacketFilter myFilter = new PacketFilter() {
037 *     public boolean accept(Packet packet) {
038 *         return &quot;RS145&quot;.equals(packet.getPacketID());
039 *     }
040 * };
041 * // Create a new packet collector using the filter we created.
042 * PacketCollector myCollector = packetReader.createPacketCollector(myFilter);
043 * </pre>
044 *
045 * @see org.jivesoftware.smack.PacketCollector
046 * @see org.jivesoftware.smack.PacketListener
047 * @author Matt Tucker
048 */
049public interface PacketFilter {
050
051    /**
052     * Tests whether or not the specified packet should pass the filter.
053     *
054     * @param packet the packet to test.
055     * @return true if and only if <tt>packet</tt> passes the filter.
056     */
057    public boolean accept(Packet packet);
058}