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  
19  package org.apache.commons.digester3;
20  
21  import java.util.ArrayList;
22  
23  /**
24   * Bean for Digester testing.
25   */
26  
27  public class Employee
28  {
29  
30      public Employee()
31      {
32          this( "My First Name", "My Last Name" );
33      }
34  
35      public Employee( String firstName, String lastName )
36      {
37          super();
38          setFirstName( firstName );
39          setLastName( lastName );
40      }
41  
42      private ArrayList<Address> addresses = new ArrayList<Address>();
43  
44      public void addAddress( Address address )
45      {
46          addresses.add( address );
47      }
48  
49      public Address getAddress( String type )
50      {
51          for ( Address address : addresses )
52          {
53              if ( type.equals( address.getType() ) )
54                  return ( address );
55          }
56          return ( null );
57      }
58  
59      public void removeAddress( Address address )
60      {
61          addresses.remove( address );
62      }
63  
64      private String firstName = null;
65  
66      public String getFirstName()
67      {
68          return ( this.firstName );
69      }
70  
71      public void setFirstName( String firstName )
72      {
73          this.firstName = firstName;
74      }
75  
76      private String lastName = null;
77  
78      public String getLastName()
79      {
80          return ( this.lastName );
81      }
82  
83      public void setLastName( String lastName )
84      {
85          this.lastName = lastName;
86      }
87  
88      // this is to allow testing of primitive convertion
89      private int age;
90  
91      private boolean active;
92  
93      private float salary;
94  
95      public int getAge()
96      {
97          return age;
98      }
99  
100     public void setAge( int age )
101     {
102         this.age = age;
103     }
104 
105     public boolean isActive()
106     {
107         return active;
108     }
109 
110     public void setActive( boolean active )
111     {
112         this.active = active;
113     }
114 
115     public float getSalary()
116     {
117         return salary;
118     }
119 
120     public void setSalary( float salary )
121     {
122         this.salary = salary;
123     }
124 
125     @Override
126     public String toString()
127     {
128         StringBuilder sb = new StringBuilder( "Employee[" );
129         sb.append( "firstName=" );
130         sb.append( firstName );
131         sb.append( ", lastName=" );
132         sb.append( lastName );
133         sb.append( "]" );
134         return ( sb.toString() );
135     }
136 
137 }