001/** 002 * 003 * Copyright 2017 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.smack.filter; 018 019import org.jivesoftware.smack.packet.Stanza; 020import org.jxmpp.jid.Jid; 021 022public final class ToMatchesFilter extends AbstractFromToMatchesFilter { 023 024 public static final ToMatchesFilter MATCH_NO_TO_SET = create(null); 025 026 public ToMatchesFilter(Jid address, boolean ignoreResourcepart) { 027 super(address, ignoreResourcepart); 028 } 029 030 /** 031 * Creates a filter matching on the "to" field. If the filter address is bare, compares 032 * the filter address with the bare from address. Otherwise, compares the filter address 033 * with the full from address. 034 * 035 * @param address The address to filter for. If <code>null</code> is given, the stanza must not 036 * have a from address. 037 */ 038 public static ToMatchesFilter create(Jid address) { 039 return new ToMatchesFilter(address, address != null ? address.hasNoResource() : false) ; 040 } 041 042 /** 043 * Creates a filter matching on the "to" field. Compares the bare version of to and filter 044 * address. 045 * 046 * @param address The address to filter for. If <code>null</code> is given, the stanza must not 047 * have a from address. 048 */ 049 public static ToMatchesFilter createBare(Jid address) { 050 return new ToMatchesFilter(address, true); 051 } 052 053 /** 054 * Creates a filter matching on the "to" field. Compares the full version, if available, of to and filter 055 * address. 056 * 057 * @param address The address to filter for. If <code>null</code> is given, the stanza must not 058 * have a from address. 059 */ 060 public static ToMatchesFilter createFull(Jid address) { 061 return new ToMatchesFilter(address, false); 062 } 063 064 @Override 065 protected Jid getAddressToCompare(Stanza stanza) { 066 return stanza.getTo(); 067 } 068 069}