1 20 21 package org.jivesoftware.smack.filter; 22 23 import org.jivesoftware.smack.packet.Packet; 24 25 31 public class AndFilter implements PacketFilter { 32 33 36 private int size; 37 38 41 private PacketFilter [] filters; 42 43 47 public AndFilter() { 48 size = 0; 49 filters = new PacketFilter[3]; 50 } 51 52 58 public AndFilter(PacketFilter filter1, PacketFilter filter2) { 59 if (filter1 == null || filter2 == null) { 60 throw new IllegalArgumentException ("Parameters cannot be null."); 61 } 62 size = 2; 63 filters = new PacketFilter[2]; 64 filters[0] = filter1; 65 filters[1] = filter2; 66 } 67 68 74 public void addFilter(PacketFilter filter) { 75 if (filter == null) { 76 throw new IllegalArgumentException ("Parameter cannot be null."); 77 } 78 if (size == filters.length) { 80 PacketFilter [] newFilters = new PacketFilter[filters.length+2]; 81 for (int i=0; i<filters.length; i++) { 82 newFilters[i] = filters[i]; 83 } 84 filters = newFilters; 85 } 86 filters[size] = filter; 88 size++; 89 } 90 91 public boolean accept(Packet packet) { 92 for (int i=0; i<size; i++) { 93 if (!filters[i].accept(packet)) { 94 return false; 95 } 96 } 97 return true; 98 } 99 100 public String toString() { 101 return filters.toString(); 102 } 103 } 104 | Popular Tags |