package org.jivesoftware.smack.filter;

import org.jivesoftware.smack.packet.Message;

public class MessageTypeFilter extends FlexibleStanzaTypeFilter<Message> {
   public static final StanzaFilter NORMAL;
   public static final StanzaFilter CHAT;
   public static final StanzaFilter GROUPCHAT;
   public static final StanzaFilter HEADLINE;
   public static final StanzaFilter ERROR;
   public static final StanzaFilter NORMAL_OR_CHAT;
   public static final StanzaFilter NORMAL_OR_CHAT_OR_HEADLINE;
   private final Message.Type type;

   private MessageTypeFilter(Message.Type type) {
      super(Message.class);
      this.type = type;
   }

   protected boolean acceptSpecific(Message message) {
      return message.getType() == this.type;
   }

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

   static {
      NORMAL = new MessageTypeFilter(Message.Type.normal);
      CHAT = new MessageTypeFilter(Message.Type.chat);
      GROUPCHAT = new MessageTypeFilter(Message.Type.groupchat);
      HEADLINE = new MessageTypeFilter(Message.Type.headline);
      ERROR = new MessageTypeFilter(Message.Type.error);
      NORMAL_OR_CHAT = new OrFilter(new StanzaFilter[]{NORMAL, CHAT});
      NORMAL_OR_CHAT_OR_HEADLINE = new OrFilter(new StanzaFilter[]{NORMAL_OR_CHAT, HEADLINE});
   }
}
