View Javadoc

1   /* $Id: Employee.java 1102402 2011-05-12 18:03:26Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.digester3.annotations.employee;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.apache.commons.digester3.annotations.rules.ObjectCreate;
24  import org.apache.commons.digester3.annotations.rules.SetProperty;
25  
26  /**
27   * @since 2.1
28   */
29  @ObjectCreate( pattern = "employee" )
30  public class Employee
31  {
32  
33      private final List<Address> addresses = new ArrayList<Address>();
34  
35      @SetProperty( pattern = "employee", attributeName = "name" )
36      private String firstName;
37  
38      @SetProperty( pattern = "employee", attributeName = "surname" )
39      private String lastName;
40  
41      public void addAddress( Address address )
42      {
43          this.addresses.add( address );
44      }
45  
46      public String getFirstName()
47      {
48          return this.firstName;
49      }
50  
51      public void setFirstName( String firstName )
52      {
53          this.firstName = firstName;
54      }
55  
56      public String getLastName()
57      {
58          return this.lastName;
59      }
60  
61      public void setLastName( String lastName )
62      {
63          this.lastName = lastName;
64      }
65  
66      public List<Address> getAddresses()
67      {
68          return this.addresses;
69      }
70  
71      @Override
72      public boolean equals( Object obj )
73      {
74          if ( this == obj )
75              return true;
76          if ( obj == null )
77              return false;
78          if ( getClass() != obj.getClass() )
79              return false;
80          Employee other = (Employee) obj;
81          if ( this.addresses == null )
82          {
83              if ( other.getAddresses() != null )
84                  return false;
85          }
86          else if ( !this.addresses.equals( other.getAddresses() ) )
87              return false;
88          if ( this.firstName == null )
89          {
90              if ( other.getFirstName() != null )
91                  return false;
92          }
93          else if ( !this.firstName.equals( other.getFirstName() ) )
94              return false;
95          if ( this.lastName == null )
96          {
97              if ( other.getLastName() != null )
98                  return false;
99          }
100         else if ( !this.lastName.equals( other.getLastName() ) )
101             return false;
102         return true;
103     }
104 
105     @Override
106     public String toString()
107     {
108         return "Employee [addresses=" + addresses + ", firstName=" + firstName + ", lastName=" + lastName + "]";
109     }
110 
111 }