001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.newsletter;
029
030/**
031 * Simple implementation of interface {@link I_CmsNewsletterRecipient}, with
032 * {@link I_CmsNewsletterRecipient#isSubscriber(org.opencms.newsletter.I_CmsNewsletterContent)} always returning true.<p>
033 *
034 * @since 6.0.2
035 *
036 */
037public class CmsSimpleNewsletterRecipient implements I_CmsNewsletterRecipient {
038
039    /** The email address of this recipient. */
040    private String m_email;
041
042    /** The firstname of this recipient. */
043    private String m_firstname;
044
045    /** The lastname of this recipient. */
046    private String m_lastname;
047
048    /** The nicename of this recipient. */
049    private String m_name;
050
051    /**
052     * Creates a new CmsSimpleNewsletterRecipient.<p>
053     *
054     * @param email the email address to be sent
055     * @param name the nicename of the recipient
056     */
057    public CmsSimpleNewsletterRecipient(String email, String name) {
058
059        m_email = email;
060        m_name = name;
061    }
062
063    /**
064     * Creates a new CmsSimpleNewsletterRecipient.<p>
065     *
066     * @param email the email address to be sent
067     * @param firstname the firstname of the recipient
068     * @param lastname the newsletter recipient's lastname
069     */
070    public CmsSimpleNewsletterRecipient(String email, String firstname, String lastname) {
071
072        m_email = email;
073        m_firstname = firstname;
074        m_lastname = lastname;
075        m_name = firstname + ' ' + lastname;
076    }
077
078    /**
079     *
080     * @see java.lang.Object#equals(java.lang.Object)
081     */
082    @Override
083    public boolean equals(Object obj) {
084
085        if (!(obj instanceof CmsSimpleNewsletterRecipient)) {
086            return false;
087        }
088        CmsSimpleNewsletterRecipient recipient = (CmsSimpleNewsletterRecipient)obj;
089        if (getEmail() != recipient.getEmail()) {
090            return false;
091        }
092        if (!getName().equals(recipient.getName())) {
093            return false;
094        }
095        return true;
096    }
097
098    /**
099     * @see org.opencms.newsletter.I_CmsNewsletterRecipient#getEmail()
100     */
101    public String getEmail() {
102
103        return m_email;
104    }
105
106    /**
107     * @see org.opencms.newsletter.I_CmsNewsletterRecipient#getFirstname()
108     */
109    public String getFirstname() {
110
111        return m_firstname;
112    }
113
114    /**
115     * @see org.opencms.newsletter.I_CmsNewsletterRecipient#getFullName()
116     */
117    public String getFullName() {
118
119        return m_name;
120    }
121
122    /**
123     * @see org.opencms.newsletter.I_CmsNewsletterRecipient#getLastname()
124     */
125    public String getLastname() {
126
127        return m_lastname;
128    }
129
130    /**
131     * Returns the name of the recipient.<p>
132     *
133     * @return the name of the recipient.
134     */
135    public String getName() {
136
137        return m_name;
138    }
139
140    /**
141     *
142     * @see java.lang.Object#hashCode()
143     */
144    @Override
145    public int hashCode() {
146
147        return m_email.hashCode() + m_firstname.hashCode() + m_lastname.hashCode() + m_name.hashCode();
148    }
149
150    /**
151     * @see org.opencms.newsletter.I_CmsNewsletterRecipient#isSubscriber(org.opencms.newsletter.I_CmsNewsletterContent)
152     */
153    public boolean isSubscriber(I_CmsNewsletterContent content) {
154
155        return true;
156    }
157
158    /**
159     * Set the email address of this recepient.<p>
160     *
161     * @param email the email address of this recepient to set.
162     */
163    protected void setEmail(String email) {
164
165        m_email = email;
166    }
167}