001    /**
002     *
003     * Copyright 2003-2006 The Apache Software Foundation
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     */
017    
018    package javax.mail.search;
019    
020    import javax.mail.Address;
021    
022    /**
023     * Term that compares two addresses.
024     *
025     * @version $Rev: 421852 $ $Date: 2006-07-14 03:02:19 -0700 (Fri, 14 Jul 2006) $
026     */
027    public abstract class AddressTerm extends SearchTerm {
028        /**
029         * The address.
030         */
031        protected Address address;
032    
033        /**
034         * Constructor taking the address for this term.
035         * @param address the address
036         */
037        protected AddressTerm(Address address) {
038            this.address = address;
039        }
040    
041        /**
042         * Return the address of this term.
043         *
044         * @return the addre4ss
045         */
046        public Address getAddress() {
047            return address;
048        }
049    
050        /**
051         * Match to the supplied address.
052         *
053         * @param address the address to match with
054         * @return true if the addresses match
055         */
056        protected boolean match(Address address) {
057            return this.address.equals(address);
058        }
059    
060        public boolean equals(Object other) {
061            if (this == other) return true;
062            if (other instanceof AddressTerm == false) return false;
063    
064            return address.equals(((AddressTerm) other).address);
065        }
066    
067        public int hashCode() {
068            return address.hashCode();
069        }
070    }