View Javadoc
1   /**
2    * This file Copyright (c) 2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.poc.customer;
35  
36  import java.io.Serializable;
37  import java.time.LocalDate;
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  /**
42   * A entity object, like in any other Java application. In a typical real world
43   * application this could for example be a JPA entity.
44   */
45  public class Customer implements Serializable, Cloneable {
46  
47      private Long id;
48  
49      private String firstName = "";
50  
51      private String lastName = "";
52  
53      private LocalDate birthDate;
54  
55      private CustomerStatus status;
56  
57      private String email = "";
58  
59      private List<Customer> children = new ArrayList<>();
60  
61      public Long getId() {
62          return id;
63      }
64  
65      public void setId(Long id) {
66          this.id = id;
67      }
68  
69      /**
70       * Get the value of email
71       *
72       * @return the value of email
73       */
74      public String getEmail() {
75          return email;
76      }
77  
78      /**
79       * Set the value of email
80       *
81       * @param email
82       *            new value of email
83       */
84      public void setEmail(String email) {
85          this.email = email;
86      }
87  
88      /**
89       * Get the value of status
90       *
91       * @return the value of status
92       */
93      public CustomerStatus getStatus() {
94          return status;
95      }
96  
97      /**
98       * Set the value of status
99       *
100      * @param status
101      *            new value of status
102      */
103     public void setStatus(CustomerStatus status) {
104         this.status = status;
105     }
106 
107     /**
108      * Get the value of birthDate
109      *
110      * @return the value of birthDate
111      */
112     public LocalDate getBirthDate() {
113         return birthDate;
114     }
115 
116     /**
117      * Set the value of birthDate
118      *
119      * @param birthDate
120      *            new value of birthDate
121      */
122     public void setBirthDate(LocalDate birthDate) {
123         this.birthDate = birthDate;
124     }
125 
126     /**
127      * Get the value of lastName
128      *
129      * @return the value of lastName
130      */
131     public String getLastName() {
132         return lastName;
133     }
134 
135     /**
136      * Set the value of lastName
137      *
138      * @param lastName
139      *            new value of lastName
140      */
141     public void setLastName(String lastName) {
142         this.lastName = lastName;
143     }
144 
145     /**
146      * Get the value of firstName
147      *
148      * @return the value of firstName
149      */
150     public String getFirstName() {
151         return firstName;
152     }
153 
154     /**
155      * Set the value of firstName
156      *
157      * @param firstName
158      *            new value of firstName
159      */
160     public void setFirstName(String firstName) {
161         this.firstName = firstName;
162     }
163 
164     public boolean isPersisted() {
165         return id != null;
166     }
167 
168     public List<Customer> getChildren() {
169         return children;
170     }
171 
172     public void setChildren(List<Customer> children) {
173         this.children = children;
174     }
175 
176     @Override
177     public boolean equals(Object obj) {
178         if (this == obj) {
179             return true;
180         }
181         if (this.id == null) {
182             return false;
183         }
184 
185         if (obj instanceof Customer && obj.getClass().equals(getClass())) {
186             return this.id.equals(((Customer) obj).id);
187         }
188 
189         return false;
190     }
191 
192     @Override
193     public int hashCode() {
194         int hash = 5;
195         hash = 43 * hash + (id == null ? 0 : id.hashCode());
196         return hash;
197     }
198 
199     @Override
200     public Customer clone() throws CloneNotSupportedException {
201         return (Customer) super.clone();
202     }
203 
204     @Override
205     public String toString() {
206         return firstName + " " + lastName;
207     }
208 }