001/**
002 *
003 * Copyright 2015 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.muc.filter;
018
019import org.jivesoftware.smack.filter.StanzaFilter;
020import org.jivesoftware.smack.packet.Stanza;
021import org.jivesoftware.smackx.muc.packet.MUCUser;
022
023public class MUCUserStatusCodeFilter implements StanzaFilter {
024
025    public static final MUCUserStatusCodeFilter STATUS_110_PRESENCE_TO_SELF = new MUCUserStatusCodeFilter(
026                    MUCUser.Status.PRESENCE_TO_SELF_110);
027
028    private final MUCUser.Status status;
029
030    public MUCUserStatusCodeFilter(MUCUser.Status status) {
031        this.status = status;
032    }
033
034    public MUCUserStatusCodeFilter(int statusCode) {
035        this(MUCUser.Status.create(statusCode));
036    }
037
038    @Override
039    public boolean accept(Stanza stanza) {
040        MUCUser mucUser = MUCUser.from(stanza);
041        if (mucUser == null) {
042            return false;
043        }
044        return mucUser.getStatus().contains(status);
045    }
046
047    @Override
048    public String toString() {
049        return getClass().getSimpleName() + ": status=" + status;
050    }
051}