OrFilter.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smack.filter;

  18. import org.jivesoftware.smack.packet.Stanza;

  19. /**
  20.  * Implements the logical OR operation over two or more stanza filters. In
  21.  * other words, packets pass this filter if they pass <b>any</b> of the filters.
  22.  *
  23.  * @author Matt Tucker
  24.  */
  25. public class OrFilter extends AbstractListFilter implements StanzaFilter {

  26.     /**
  27.      * Creates an empty OR filter. Filters should be added using the
  28.      * {@link #addFilter(StanzaFilter)} method.
  29.      */
  30.     public OrFilter() {
  31.         super();
  32.     }

  33.     /**
  34.      * Creates an OR filter using the specified filters.
  35.      *
  36.      * @param filters the filters to add.
  37.      */
  38.     public OrFilter(StanzaFilter... filters) {
  39.         super(filters);
  40.     }

  41.     @Override
  42.     public boolean accept(Stanza packet) {
  43.         for (StanzaFilter filter : filters) {
  44.             if (filter.accept(packet)) {
  45.                 return true;
  46.             }
  47.         }
  48.         return false;
  49.     }

  50. }