[core] Add AndFilter(List<StanzaFilter>) constructor

This commit is contained in:
Florian Schmaus 2021-03-12 22:25:50 +01:00
parent 14142a0ef2
commit 61cb73ee37
2 changed files with 23 additions and 3 deletions

View File

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2015 Florian Schmaus * Copyright 2015-2021 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -44,11 +44,20 @@ public abstract class AbstractListFilter implements StanzaFilter {
* @param filters the filters to add. * @param filters the filters to add.
*/ */
protected AbstractListFilter(StanzaFilter... filters) { protected AbstractListFilter(StanzaFilter... filters) {
this(new ArrayList<StanzaFilter>(Arrays.asList(filters)));
}
/**
* Creates an filter using the specified filters.
*
* @param filters the filters to add.
*/
protected AbstractListFilter(List<StanzaFilter> filters) {
Objects.requireNonNull(filters, "Parameter must not be null."); Objects.requireNonNull(filters, "Parameter must not be null.");
for (StanzaFilter filter : filters) { for (StanzaFilter filter : filters) {
Objects.requireNonNull(filter, "Parameter must not be null."); Objects.requireNonNull(filter, "Parameter must not be null.");
} }
this.filters = new ArrayList<StanzaFilter>(Arrays.asList(filters)); this.filters = filters;
} }
/** /**

View File

@ -1,6 +1,6 @@
/** /**
* *
* Copyright 2003-2007 Jive Software. * Copyright 2003-2007 Jive Software, 2021 Florian Schmaus.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
package org.jivesoftware.smack.filter; package org.jivesoftware.smack.filter;
import java.util.List;
import org.jivesoftware.smack.packet.Stanza; import org.jivesoftware.smack.packet.Stanza;
/** /**
@ -44,6 +46,15 @@ public class AndFilter extends AbstractListFilter implements StanzaFilter {
super(filters); super(filters);
} }
/**
* Creates an AND filter using the specified filters.
*
* @param filters the filters to add.
*/
public AndFilter(List<StanzaFilter> filters) {
super(filters);
}
@Override @Override
public boolean accept(Stanza packet) { public boolean accept(Stanza packet) {
for (StanzaFilter filter : filters) { for (StanzaFilter filter : filters) {