(Arrays.asList(filters));
- }
-
- /**
- * 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) {
- Objects.requireNonNull(filter, "Parameter must not be null.");
- filters.add(filter);
+ super(filters);
}
public boolean accept(Stanza packet) {
@@ -78,7 +53,4 @@ public class AndFilter implements PacketFilter {
return true;
}
- public String toString() {
- return filters.toString();
- }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/FlexiblePacketTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/FlexiblePacketTypeFilter.java
index 54e49c2fe..454d8caa3 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/FlexiblePacketTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/FlexiblePacketTypeFilter.java
@@ -20,6 +20,7 @@ package org.jivesoftware.smack.filter;
import java.lang.reflect.ParameterizedType;
import org.jivesoftware.smack.packet.Stanza;
+import org.jivesoftware.smack.util.Objects;
/**
* Filters for packets of a particular type and allows a custom method to further filter the packets.
@@ -31,7 +32,7 @@ public abstract class FlexiblePacketTypeFilter implements Pack
protected final Class
packetType;
public FlexiblePacketTypeFilter(Class
packetType) {
- this.packetType = packetType;
+ this.packetType = Objects.requireNonNull(packetType, "Type must not be null");
}
@SuppressWarnings("unchecked")
@@ -49,4 +50,12 @@ public abstract class FlexiblePacketTypeFilter
implements Pack
}
protected abstract boolean acceptSpecific(P packet);
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getClass().getSimpleName());
+ sb.append(" (" + packetType.toString() + ')');
+ return sb.toString();
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
index ee570aa78..3b48d0f13 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/FromMatchesFilter.java
@@ -104,6 +104,6 @@ public class FromMatchesFilter implements PacketFilter {
public String toString() {
String matchMode = matchBareJID ? "bare" : "full";
- return "FromMatchesFilter (" +matchMode + "): " + address;
+ return getClass().getSimpleName() + " (" + matchMode + "): " + address;
}
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java
index fc0673548..e7b162356 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQReplyFilter.java
@@ -130,4 +130,12 @@ public class IQReplyFilter implements PacketFilter {
}
}
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getClass().getSimpleName());
+ sb.append(": iqAndIdFilter (").append(iqAndIdFilter.toString()).append("), ");
+ sb.append(": fromFilter (").append(fromFilter.toString()).append(')');
+ return sb.toString();
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQResultReplyFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQResultReplyFilter.java
index c77539f56..a8225dcf4 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQResultReplyFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQResultReplyFilter.java
@@ -38,4 +38,11 @@ public class IQResultReplyFilter extends IQReplyFilter {
return IQTypeFilter.RESULT.accept(packet);
}
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getClass().getSimpleName());
+ sb.append(" (" + super.toString() + ')');
+ return sb.toString();
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
index f0cccb245..dc2c38b10 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/IQTypeFilter.java
@@ -18,6 +18,7 @@ package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;
+import org.jivesoftware.smack.util.Objects;
/**
* A filter for IQ packet types. Returns true only if the packet is an IQ packet
@@ -38,11 +39,16 @@ public class IQTypeFilter extends FlexiblePacketTypeFilter {
private IQTypeFilter(IQ.Type type) {
super(IQ.class);
- this.type = type;
+ this.type = Objects.requireNonNull(type, "Type must not be null");
}
@Override
protected boolean acceptSpecific(IQ iq) {
return iq.getType() == type;
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": type=" + type;
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageTypeFilter.java
index c7eaa5275..74df7bfed 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageTypeFilter.java
@@ -55,4 +55,8 @@ public class MessageTypeFilter extends FlexiblePacketTypeFilter {
return message.getType() == type;
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": type=" + type;
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithBodiesFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithBodiesFilter.java
index a8f796622..201e5546d 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithBodiesFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithBodiesFilter.java
@@ -36,4 +36,8 @@ public class MessageWithBodiesFilter extends FlexiblePacketTypeFilter {
return !message.getBodies().isEmpty();
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithSubjectFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithSubjectFilter.java
index fa29ec497..c484aa2e8 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithSubjectFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/MessageWithSubjectFilter.java
@@ -36,4 +36,8 @@ public class MessageWithSubjectFilter extends FlexiblePacketTypeFilter
return message.getSubject() != null;
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java
index 3dd76a7f0..76d63ce9c 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/NotFilter.java
@@ -18,6 +18,7 @@
package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Stanza;
+import org.jivesoftware.smack.util.Objects;
/**
* Implements the logical NOT operation on a packet filter. In other words, packets
@@ -35,10 +36,7 @@ public class NotFilter implements PacketFilter {
* @param filter the filter.
*/
public NotFilter(PacketFilter filter) {
- if (filter == null) {
- throw new IllegalArgumentException("Parameter must not be null.");
- }
- this.filter = filter;
+ this.filter = Objects.requireNonNull(filter, "Parameter must not be null.");
}
public boolean accept(Stanza packet) {
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java
index db583c076..b1d96eeef 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/OrFilter.java
@@ -17,12 +17,7 @@
package org.jivesoftware.smack.filter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
import org.jivesoftware.smack.packet.Stanza;
-import org.jivesoftware.smack.util.Objects;
/**
* Implements the logical OR operation over two or more packet filters. In
@@ -30,19 +25,14 @@ import org.jivesoftware.smack.util.Objects;
*
* @author Matt Tucker
*/
-public class OrFilter implements PacketFilter {
-
- /**
- * The list of filters.
- */
- private final List filters;
+public class OrFilter extends AbstractListFilter implements PacketFilter {
/**
* Creates an empty OR filter. Filters should be added using the
* {@link #addFilter(PacketFilter)} method.
*/
public OrFilter() {
- filters = new ArrayList();
+ super();
}
/**
@@ -51,24 +41,10 @@ public class OrFilter implements PacketFilter {
* @param filters the filters to add.
*/
public OrFilter(PacketFilter... filters) {
- Objects.requireNonNull(filters, "Parameter must not be null.");
- for(PacketFilter filter : filters) {
- Objects.requireNonNull(filter, "Parameter must not be null.");
- }
- this.filters = new ArrayList(Arrays.asList(filters));
- }
-
- /**
- * 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) {
- Objects.requireNonNull(filter, "Parameter must not be null.");
- filters.add(filter);
+ super(filters);
}
+ @Override
public boolean accept(Stanza packet) {
for (PacketFilter filter : filters) {
if (filter.accept(packet)) {
@@ -78,7 +54,4 @@ public class OrFilter implements PacketFilter {
return false;
}
- public String toString() {
- return filters.toString();
- }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java
index 0ba17386f..c0deb6183 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketExtensionFilter.java
@@ -68,4 +68,9 @@ public class PacketExtensionFilter implements PacketFilter {
public boolean accept(Stanza packet) {
return packet.hasExtension(elementName, namespace);
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": element=" + elementName + " namespace=" + namespace;
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java
index 82a2ea904..a01b247c6 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketIDFilter.java
@@ -53,6 +53,6 @@ public class PacketIDFilter implements PacketFilter {
}
public String toString() {
- return "PacketIDFilter by id: " + packetID;
+ return getClass().getSimpleName() + ": id=" + packetID;
}
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java
index 6c57a4071..5a32e784c 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PacketTypeFilter.java
@@ -53,7 +53,8 @@ public class PacketTypeFilter implements PacketFilter {
return packetType.isInstance(packet);
}
+ @Override
public String toString() {
- return "PacketTypeFilter: " + packetType.getName();
+ return getClass().getSimpleName() + ": " + packetType.getName();
}
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/PresenceTypeFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/PresenceTypeFilter.java
index 045cd2bf8..d67635609 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/PresenceTypeFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/PresenceTypeFilter.java
@@ -18,6 +18,7 @@ package org.jivesoftware.smack.filter;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
+import org.jivesoftware.smack.util.Objects;
/**
* A filter for Presence types. Returns true only if the stanza is an Presence packet and it matches the type provided in the
@@ -38,11 +39,16 @@ public class PresenceTypeFilter extends FlexiblePacketTypeFilter {
private PresenceTypeFilter(Presence.Type type) {
super(Presence.class);
- this.type = type;
+ this.type = Objects.requireNonNull(type, "type must not be null");
}
@Override
protected boolean acceptSpecific(Presence presence) {
return presence.getType() == type;
}
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": type=" + type;
+ }
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java
index e053d364b..da1c3d7dd 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/ThreadFilter.java
@@ -17,7 +17,6 @@
package org.jivesoftware.smack.filter;
-import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.StringUtils;
@@ -26,7 +25,7 @@ import org.jivesoftware.smack.util.StringUtils;
*
* @author Matt Tucker
*/
-public class ThreadFilter implements PacketFilter {
+public class ThreadFilter extends FlexiblePacketTypeFilter implements PacketFilter {
private final String thread;
@@ -40,7 +39,13 @@ public class ThreadFilter implements PacketFilter {
this.thread = thread;
}
- public boolean accept(Stanza packet) {
- return packet instanceof Message && thread.equals(((Message) packet).getThread());
+ @Override
+ protected boolean acceptSpecific(Message message) {
+ return thread.equals(message.getThread());
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": thread=" + thread;
}
}
diff --git a/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java
index cfb0d3ed4..a691537b2 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/filter/ToFilter.java
@@ -38,4 +38,8 @@ public class ToFilter implements PacketFilter {
return packetTo.equals(to);
}
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + ": to=" + to;
+ }
}
diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
index b93850279..25ff808c4 100644
--- a/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
+++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/filetransfer/FaultTolerantNegotiator.java
@@ -175,11 +175,8 @@ public class FaultTolerantNegotiator extends StreamNegotiator {
this.collector = collector;
}
- public InputStream call() throws XMPPErrorException, InterruptedException, SmackException {
- Stanza streamInitiation = collector.nextResult();
- if (streamInitiation == null) {
- throw new NoResponseException(connection);
- }
+ public InputStream call() throws XMPPErrorException, InterruptedException, NoResponseException, SmackException {
+ Stanza streamInitiation = collector.nextResultOrThrow();
StreamNegotiator negotiator = determineNegotiator(streamInitiation);
return negotiator.negotiateIncomingStream(streamInitiation);
}