001/* $Id: Employee.java 1102402 2011-05-12 18:03:26Z simonetripodi $
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.commons.digester3.annotations.employee;
019
020import java.util.ArrayList;
021import java.util.List;
022
023import org.apache.commons.digester3.annotations.rules.ObjectCreate;
024import org.apache.commons.digester3.annotations.rules.SetProperty;
025
026/**
027 * @since 2.1
028 */
029@ObjectCreate( pattern = "employee" )
030public class Employee
031{
032
033    private final List<Address> addresses = new ArrayList<Address>();
034
035    @SetProperty( pattern = "employee", attributeName = "name" )
036    private String firstName;
037
038    @SetProperty( pattern = "employee", attributeName = "surname" )
039    private String lastName;
040
041    public void addAddress( Address address )
042    {
043        this.addresses.add( address );
044    }
045
046    public String getFirstName()
047    {
048        return this.firstName;
049    }
050
051    public void setFirstName( String firstName )
052    {
053        this.firstName = firstName;
054    }
055
056    public String getLastName()
057    {
058        return this.lastName;
059    }
060
061    public void setLastName( String lastName )
062    {
063        this.lastName = lastName;
064    }
065
066    public List<Address> getAddresses()
067    {
068        return this.addresses;
069    }
070
071    @Override
072    public boolean equals( Object obj )
073    {
074        if ( this == obj )
075            return true;
076        if ( obj == null )
077            return false;
078        if ( getClass() != obj.getClass() )
079            return false;
080        Employee other = (Employee) obj;
081        if ( this.addresses == null )
082        {
083            if ( other.getAddresses() != null )
084                return false;
085        }
086        else if ( !this.addresses.equals( other.getAddresses() ) )
087            return false;
088        if ( this.firstName == null )
089        {
090            if ( other.getFirstName() != null )
091                return false;
092        }
093        else if ( !this.firstName.equals( other.getFirstName() ) )
094            return false;
095        if ( this.lastName == null )
096        {
097            if ( other.getLastName() != null )
098                return false;
099        }
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}