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 * Filters for packets with a particular packet ID. 024 * 025 * @author Matt Tucker 026 */ 027public class PacketIDFilter implements PacketFilter { 028 029 private String packetID; 030 031 /** 032 * Creates a new packet ID filter using the specified packet's ID. 033 * 034 * @param packet the packet which the ID is taken from. 035 */ 036 public PacketIDFilter(Packet packet) { 037 this(packet.getPacketID()); 038 } 039 040 /** 041 * Creates a new packet ID filter using the specified packet ID. 042 * 043 * @param packetID the packet ID to filter for. 044 */ 045 public PacketIDFilter(String packetID) { 046 if (packetID == null) { 047 throw new IllegalArgumentException("Packet ID must not be null."); 048 } 049 this.packetID = packetID; 050 } 051 052 public boolean accept(Packet packet) { 053 return packetID.equals(packet.getPacketID()); 054 } 055 056 public String toString() { 057 return "PacketIDFilter by id: " + packetID; 058 } 059}