diff --git a/source/org/jivesoftware/smack/filter/AndFilter.java b/source/org/jivesoftware/smack/filter/AndFilter.java
index 75f250392..e860431e6 100644
--- a/source/org/jivesoftware/smack/filter/AndFilter.java
+++ b/source/org/jivesoftware/smack/filter/AndFilter.java
@@ -55,18 +55,34 @@ package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Packet;
/**
- * Implements the logical AND operation over two packet filters. In other words, packets
- * pass this filter if they pass both of the filters.
+ * Implements the logical AND operation over two or more packet filters.
+ * In other words, packets pass this filter if they pass all of the filters.
*
* @author Matt Tucker
*/
public class AndFilter implements PacketFilter {
- private PacketFilter filter1;
- private PacketFilter filter2;
+ /**
+ * The current number of elements in the filter.
+ */
+ private int size;
/**
- * Creates an AND filter using the specified filters.
+ * The list of filters.
+ */
+ private PacketFilter [] filters;
+
+ /**
+ * Creates an empty AND filter. Filters should be added using the
+ * {@link #addFilter(PacketFilter) method.
+ */
+ public AndFilter() {
+ size = 0;
+ filters = new PacketFilter[3];
+ }
+
+ /**
+ * Creates an AND filter using the two specified filters.
*
* @param filter1 the first packet filter.
* @param filter2 the second packet filter.
@@ -75,11 +91,45 @@ public class AndFilter implements PacketFilter {
if (filter1 == null || filter2 == null) {
throw new IllegalArgumentException("Parameters cannot be null.");
}
- this.filter1 = filter1;
- this.filter2 = filter2;
+ size = 2;
+ filters = new PacketFilter[2];
+ filters[0] = filter1;
+ filters[1] = filter2;
+ }
+
+ /**
+ * Adds a filter to the filter list for the AND operation. A packet
+ * will pass the filter if all of the filters in the list accept it.
+ *
+ * @param filter a filter to add to the filter list.
+ */
+ public void addFilter(PacketFilter filter) {
+ if (filter == null) {
+ throw new IllegalArgumentException("Parameter cannot be null.");
+ }
+ // If there is no more room left in the filters array, expand it.
+ if (size == filters.length) {
+ PacketFilter [] newFilters = new PacketFilter[filters.length+2];
+ for (int i=0; ieither of the filters.
+ * Implements the logical OR operation over two or more packet filters. In
+ * other words, packets pass this filter if they pass any of the filters.
*
* @author Matt Tucker
*/
public class OrFilter implements PacketFilter {
- private PacketFilter filter1;
- private PacketFilter filter2;
+ /**
+ * The current number of elements in the filter.
+ */
+ private int size;
/**
- * Creates an OR filter using the specified filters.
+ * The list of filters.
+ */
+ private PacketFilter [] filters;
+
+ /**
+ * Creates an empty OR filter. Filters should be added using the
+ * {@link #addFilter(PacketFilter) method.
+ */
+ public OrFilter() {
+ size = 0;
+ filters = new PacketFilter[3];
+ }
+
+ /**
+ * Creates an OR filter using the two specified filters.
*
* @param filter1 the first packet filter.
* @param filter2 the second packet filter.
@@ -75,11 +91,45 @@ public class OrFilter implements PacketFilter {
if (filter1 == null || filter2 == null) {
throw new IllegalArgumentException("Parameters cannot be null.");
}
- this.filter1 = filter1;
- this.filter2 = filter2;
+ size = 2;
+ filters = new PacketFilter[2];
+ filters[0] = filter1;
+ filters[1] = filter2;
+ }
+
+ /**
+ * Adds a filter to the filter list for the OR operation. A packet
+ * will pass the filter if any filter in the list accepts it.
+ *
+ * @param filter a filter to add to the filter list.
+ */
+ public void addFilter(PacketFilter filter) {
+ if (filter == null) {
+ throw new IllegalArgumentException("Parameter cannot be null.");
+ }
+ // If there is no more room left in the filters array, expand it.
+ if (size == filters.length) {
+ PacketFilter [] newFilters = new PacketFilter[filters.length+2];
+ for (int i=0; i