Home | History | Annotate | Download | only in filter
      1 /**
      2  * $RCSfile$
      3  * $Revision$
      4  * $Date$
      5  *
      6  * Copyright 2003-2007 Jive Software.
      7  *
      8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      9  * you may not use this file except in compliance with the License.
     10  * You may obtain a copy of the License at
     11  *
     12  *     http://www.apache.org/licenses/LICENSE-2.0
     13  *
     14  * Unless required by applicable law or agreed to in writing, software
     15  * distributed under the License is distributed on an "AS IS" BASIS,
     16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     17  * See the License for the specific language governing permissions and
     18  * limitations under the License.
     19  */
     20 
     21 package org.jivesoftware.smack.filter;
     22 
     23 import org.jivesoftware.smack.packet.Packet;
     24 
     25 /**
     26  * Defines a way to filter packets for particular attributes. Packet filters are
     27  * used when constructing packet listeners or collectors -- the filter defines
     28  * what packets match the criteria of the collector or listener for further
     29  * packet processing.<p>
     30  *
     31  * Several pre-defined filters are defined. These filters can be logically combined
     32  * for more complex packet filtering by using the
     33  * {@link org.jivesoftware.smack.filter.AndFilter AndFilter} and
     34  * {@link org.jivesoftware.smack.filter.OrFilter OrFilter} filters. It's also possible
     35  * to define your own filters by implementing this interface. The code example below
     36  * creates a trivial filter for packets with a specific ID.
     37  *
     38  * <pre>
     39  * // Use an anonymous inner class to define a packet filter that returns
     40  * // all packets that have a packet ID of "RS145".
     41  * PacketFilter myFilter = new PacketFilter() {
     42  *     public boolean accept(Packet packet) {
     43  *         return "RS145".equals(packet.getPacketID());
     44  *     }
     45  * };
     46  * // Create a new packet collector using the filter we created.
     47  * PacketCollector myCollector = packetReader.createPacketCollector(myFilter);
     48  * </pre>
     49  *
     50  * @see org.jivesoftware.smack.PacketCollector
     51  * @see org.jivesoftware.smack.PacketListener
     52  * @author Matt Tucker
     53  */
     54 public interface PacketFilter {
     55 
     56     /**
     57      * Tests whether or not the specified packet should pass the filter.
     58      *
     59      * @param packet the packet to test.
     60      * @return true if and only if <tt>packet</tt> passes the filter.
     61      */
     62     public boolean accept(Packet packet);
     63 }
     64