Package org.jivesoftware.smack.filter
Interface StanzaFilter
-
- All Known Implementing Classes:
AbstractExactJidTypeFilter
,AbstractFromToMatchesFilter
,AbstractJidTypeFilter
,AbstractJidTypeFilter
,AbstractListFilter
,AbstractPossibleJidTypeFilter
,AfterXStanzas
,AndFilter
,ChatMarkersFilter
,DelayedStanzaFilter
,EligibleForChatMarkerFilter
,EmptyToMatcher
,EventExtensionFilter
,EventItemsExtensionFilter
,ExtensionElementFilter
,FlexibleStanzaTypeFilter
,ForEveryMessage
,ForEveryStanza
,ForMatchingPredicateOrAfterXStanzas
,FromJidTypeFilter
,FromMatchesFilter
,FromTypeFilter
,IoTFieldsExtensionFilter
,IQReplyFilter
,IQResultReplyFilter
,IQTypeFilter
,MamResultFilter
,MessageTypeFilter
,MessageWithBodiesFilter
,MessageWithSubjectFilter
,MessageWithThreadFilter
,MUCUserStatusCodeFilter
,NotFilter
,OnceForThisStanza
,OrFilter
,PossibleFromTypeFilter
,PossibleToTypeFilter
,PresenceTypeFilter
,SetActiveListFilter
,SetDefaultListFilter
,ShortcutPredicates
,StanzaExtensionFilter
,StanzaIdFilter
,StanzaTypeFilter
,ThreadFilter
,ToMatchesFilter
,ToTypeFilter
public interface StanzaFilter extends Predicate<Stanza>
Defines a way to filter stanzas for particular attributes. Stanza filters are used when constructing stanza listeners or collectors -- the filter defines what stanzas match the criteria of the collector or listener for further stanza processing.Several simple filters are pre-defined. These filters can be logically combined for more complex stanza filtering by using the
AndFilter
andOrFilter
filters. It's also possible to define your own filters by implementing this interface. The code example below creates a trivial filter for stanzas with a specific ID (real code should useStanzaIdFilter
instead).// Use an anonymous inner class to define a stanza filter that returns // all stanzas that have a stanza ID of "RS145". StanzaFilter myFilter = new StanzaFilter() { public boolean accept(Stanza stanza) { return "RS145".equals(stanza.getStanzaId()); } }; // Create a new stanza collector using the filter we created. StanzaCollector myCollector = connection.createStanzaCollector(myFilter);
As a rule of thumb: If you have a predicate method, that is, a method which takes a single Stanza as argument, is pure (side effect free) and returns only a boolean, then it is a good indicator that the logic should be put into a
StanzaFilter
(and be referenced inStanzaListener
).- See Also:
StanzaCollector
,StanzaListener
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
accept(Stanza stanza)
Tests whether or not the specified stanza should pass the filter.default <S extends Stanza>
Predicate<S>asPredicate(Class<?> stanzaClass)
default boolean
test(Stanza stanza)
-
-
-
Method Detail
-
accept
boolean accept(Stanza stanza)
Tests whether or not the specified stanza should pass the filter.- Parameters:
stanza
- the stanza to test.- Returns:
- true if and only if
stanza
passes the filter.
-
asPredicate
default <S extends Stanza> Predicate<S> asPredicate(Class<?> stanzaClass)
-
-