View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.newsletter.business.topic;
35  
36  import fr.paris.lutece.plugins.newsletter.service.topic.NewsletterTopicService;
37  
38  import org.apache.commons.lang3.StringUtils;
39  
40  /**
41   * Class to describe a topic of a newsletter. this class implements the {@link java.lang.Comparable Comparable} interface.
42   */
43  public class NewsletterTopic implements Comparable<NewsletterTopic>
44  {
45      private int _nId;
46      private int _nIdNewsletter;
47      private String _strTopicTypeCode;
48      private String _strTitle;
49      private int _nOrder;
50      private int _nSection;
51  
52      /**
53       * Get the id of this newsletter topic
54       * 
55       * @return The id of this newsletter topic
56       */
57      public int getId( )
58      {
59          return _nId;
60      }
61  
62      /**
63       * Set the id of this newsletter topic
64       * 
65       * @param nId
66       *            The id of this newsletter topic
67       */
68      public void setId( int nId )
69      {
70          this._nId = nId;
71      }
72  
73      /**
74       * Get the id of the newsletter associated with this newsletter topic
75       * 
76       * @return the id of the newsletter associated with this newsletter topic
77       */
78      public int getIdNewsletter( )
79      {
80          return _nIdNewsletter;
81      }
82  
83      /**
84       * Set the id of the newsletter associated with this newsletter topic
85       * 
86       * @param nIdNewsletter
87       *            the id of the newsletter
88       */
89      public void setIdNewsletter( int nIdNewsletter )
90      {
91          this._nIdNewsletter = nIdNewsletter;
92      }
93  
94      /**
95       * Get the name of the topic type of this newsletter topic
96       * 
97       * @return The name of the topic type of this newsletter topic
98       */
99      public String getTopicTypeCode( )
100     {
101         return _strTopicTypeCode;
102     }
103 
104     /**
105      * Get the name of the topic type associated with this topic
106      * 
107      * @return the name of the topic type associated with this topic
108      */
109     public String getTopicTypeName( )
110     {
111         return NewsletterTopicService.getService( ).getTopicTypeName( getTopicTypeCode( ) );
112     }
113 
114     /**
115      * Set the name of the topic type of this newsletter topic
116      * 
117      * @param strTopicTypeCode
118      *            The name of the topic type of this newsletter topic
119      */
120     public void setTopicTypeCode( String strTopicTypeCode )
121     {
122         _strTopicTypeCode = strTopicTypeCode;
123     }
124 
125     /**
126      * Get the title of this newsletter topic
127      * 
128      * @return The title of this newsletter topic
129      */
130     public String getTitle( )
131     {
132         return _strTitle;
133     }
134 
135     /**
136      * Set the title of this newsletter topic
137      * 
138      * @param strTitle
139      *            The title of this newsletter topic
140      */
141     public void setTitle( String strTitle )
142     {
143         this._strTitle = strTitle;
144     }
145 
146     /**
147      * Get the order of the newsletter topic
148      * 
149      * @return The order of the newsletter topic
150      */
151     public int getOrder( )
152     {
153         return _nOrder;
154     }
155 
156     /**
157      * Set the order of the newsletter topic
158      * 
159      * @param nOrder
160      *            The order of the newsletter topic
161      */
162     public void setOrder( int nOrder )
163     {
164         this._nOrder = nOrder;
165     }
166 
167     /**
168      * Get the section of the topic
169      * 
170      * @return The section of the topic
171      */
172     public int getSection( )
173     {
174         return _nSection;
175     }
176 
177     /**
178      * Set the section of the topic
179      * 
180      * @param nSection
181      *            The section of the topic
182      */
183     public void setSection( int nSection )
184     {
185         this._nSection = nSection;
186     }
187 
188     /**
189      * {@inheritDoc}
190      */
191     @Override
192     public int compareTo( NewsletterTopic o )
193     {
194         int nRes = 0;
195         if ( getIdNewsletter( ) > o.getIdNewsletter( ) )
196         {
197             nRes = 1;
198         }
199         else
200         {
201             if ( nRes == 0 && getIdNewsletter( ) < o.getIdNewsletter( ) )
202             {
203                 nRes = -1;
204             }
205             else
206             {
207                 if ( nRes == 0 && getSection( ) > o.getSection( ) )
208                 {
209                     nRes = 1;
210                 }
211                 if ( nRes == 0 && getSection( ) < o.getSection( ) )
212                 {
213                     nRes = -1;
214                 }
215                 if ( nRes == 0 && getOrder( ) > o.getOrder( ) )
216                 {
217                     nRes = 1;
218                 }
219                 if ( nRes == 0 && getOrder( ) < o.getOrder( ) )
220                 {
221                     nRes = -1;
222                 }
223             }
224         }
225 
226         // If they have the same section and order, then it has to be the same object, so they should be equal
227         return nRes;
228     }
229 
230     /**
231      * {@inheritDoc}
232      */
233     @Override
234     public int hashCode( )
235     {
236         final int prime = 31;
237         int result = 1;
238         result = prime * result + _nSection;
239         result = prime * result + _nId;
240         result = prime * result + _nIdNewsletter;
241         result = prime * result + _nOrder;
242         result = prime * result + ( ( _strTopicTypeCode == null ) ? 0 : _strTopicTypeCode.hashCode( ) );
243         return result;
244     }
245 
246     /**
247      * {@inheritDoc}
248      */
249     @Override
250     public boolean equals( Object o )
251     {
252         if ( !( o instanceof NewsletterTopic ) )
253         {
254             return false;
255         }
256         NewsletterTopic./../../fr/paris/lutece/plugins/newsletter/business/topic/NewsletterTopic.html#NewsletterTopic">NewsletterTopic otherTopic = (NewsletterTopic) o;
257         return getId( ) == otherTopic.getId( ) && getIdNewsletter( ) == otherTopic.getIdNewsletter( ) && getSection( ) == otherTopic.getSection( )
258                 && getOrder( ) == otherTopic.getOrder( ) && StringUtils.equals( getTopicTypeCode( ), otherTopic.getTopicTypeCode( ) );
259     }
260 
261 }