package org.jivesoftware.smack.filter;

import java.lang.reflect.ParameterizedType;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.Objects;

public abstract class FlexibleStanzaTypeFilter<S extends Stanza> implements StanzaFilter {
   protected final Class<S> stanzaType;

   public FlexibleStanzaTypeFilter(Class<S> packetType) {
      this.stanzaType = (Class)Objects.requireNonNull(packetType, "Type must not be null");
   }

   public FlexibleStanzaTypeFilter() {
      this.stanzaType = (Class)((ParameterizedType)this.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
   }

   public final boolean accept(Stanza packet) {
      return this.stanzaType.isInstance(packet) ? this.acceptSpecific(packet) : false;
   }

   protected abstract boolean acceptSpecific(S var1);

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