package org.jivesoftware.smack.filter;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.Objects;

public class IQTypeFilter extends FlexibleStanzaTypeFilter<IQ> {
   public static final StanzaFilter GET;
   public static final StanzaFilter SET;
   public static final StanzaFilter RESULT;
   public static final StanzaFilter ERROR;
   public static final StanzaFilter GET_OR_SET;
   private final IQ.Type type;

   private IQTypeFilter(IQ.Type type) {
      super(IQ.class);
      this.type = (IQ.Type)Objects.requireNonNull(type, "Type must not be null");
   }

   protected boolean acceptSpecific(IQ iq) {
      return iq.getType() == this.type;
   }

   public String toString() {
      return this.getClass().getSimpleName() + ": type=" + this.type;
   }

   static {
      GET = new IQTypeFilter(IQ.Type.get);
      SET = new IQTypeFilter(IQ.Type.set);
      RESULT = new IQTypeFilter(IQ.Type.result);
      ERROR = new IQTypeFilter(IQ.Type.error);
      GET_OR_SET = new OrFilter(new StanzaFilter[]{GET, SET});
   }
}
