Lines 1-10
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 1998, 2009 Oracle. All rights reserved. |
2 |
* Copyright (c) 1998, 2009 Oracle. All rights reserved. |
3 |
* This program and the accompanying materials are made available under the |
3 |
* This program and the accompanying materials are made available under the |
4 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
4 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
5 |
* which accompanies this distribution. |
5 |
* which accompanies this distribution. |
6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
7 |
* and the Eclipse Distribution License is available at |
7 |
* and the Eclipse Distribution License is available at |
8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
9 |
* |
9 |
* |
10 |
* Contributors: |
10 |
* Contributors: |
Lines 15-152
Link Here
|
15 |
import java.util.Vector; |
15 |
import java.util.Vector; |
16 |
|
16 |
|
17 |
public class Employee { |
17 |
public class Employee { |
|
|
18 |
|
18 |
public static final int DEFAULT_ID = 123; |
19 |
public static final int DEFAULT_ID = 123; |
19 |
|
20 |
|
20 |
// Factory method |
|
|
21 |
public static Employee getInstance() { |
22 |
return new Employee(DEFAULT_ID, new Vector(), "Doe"); |
23 |
} |
24 |
|
25 |
private int id; |
21 |
private int id; |
26 |
private Vector tasks; // of type <String> |
22 |
private Vector tasks; |
27 |
//private String firstName; |
23 |
private String firstName; |
28 |
private String lastName; |
24 |
private String lastName; |
29 |
|
25 |
|
30 |
//public String getFirstName() { |
|
|
31 |
// return firstName; |
32 |
//} |
33 |
|
34 |
private boolean isSetTasks = false; |
26 |
private boolean isSetTasks = false; |
35 |
|
27 |
|
36 |
//public void setFirstName(String firstName) { |
28 |
// ============================================== |
37 |
// no unset for now |
|
|
38 |
// isSetFirstName = true; |
39 |
// this.firstName = firstName; |
40 |
//} |
41 |
|
29 |
|
42 |
public Employee() { |
30 |
public Employee() { |
43 |
super(); |
31 |
super(); |
44 |
//tasks = new Vector(); |
32 |
setTasks(new Vector()); |
|
|
33 |
isSetTasks = true; |
45 |
} |
34 |
} |
46 |
|
35 |
|
47 |
public Employee(int id) { |
36 |
public Employee(int id) { |
48 |
super(); |
37 |
super(); |
49 |
//tasks = new Vector(); |
|
|
50 |
//isSetTasks = true; |
51 |
this.id = id; |
38 |
this.id = id; |
|
|
39 |
setTasks(new Vector()); |
52 |
} |
40 |
} |
53 |
|
41 |
|
54 |
public Employee(int id, Vector aVector, String lastName) { |
42 |
public Employee(int id, Vector aVector, String lastName) { |
55 |
super(); |
43 |
super(); |
56 |
this.id = id; |
44 |
this.id = id; |
57 |
setTasks(aVector); |
45 |
setTasks(aVector); |
58 |
//this.firstName = firstName; |
|
|
59 |
this.lastName = lastName; |
46 |
this.lastName = lastName; |
60 |
} |
47 |
} |
61 |
|
48 |
|
|
|
49 |
// Factory method |
50 |
public static Employee getInstance() { |
51 |
return new Employee(DEFAULT_ID, new Vector(), "Doe"); |
52 |
} |
53 |
|
54 |
// ============================================== |
55 |
|
56 |
public int getId() { |
57 |
return id; |
58 |
} |
59 |
|
60 |
public void setId(int id) { |
61 |
this.id = id; |
62 |
} |
63 |
|
64 |
public String getFirstName() { |
65 |
return firstName; |
66 |
} |
67 |
|
68 |
public void setFirstName(String firstName) { |
69 |
this.firstName = firstName; |
70 |
} |
71 |
|
72 |
public String getLastName() { |
73 |
return lastName; |
74 |
} |
75 |
|
76 |
public void setLastName(String lastName) { |
77 |
this.lastName = lastName; |
78 |
} |
79 |
|
80 |
public Vector getTasks() { |
81 |
return tasks; |
82 |
} |
83 |
|
84 |
public void setTasks(Vector tasks) { |
85 |
this.tasks = tasks; |
86 |
isSetTasks = (tasks == null) ? false : true; |
87 |
} |
88 |
|
89 |
public boolean isSetTasks() { |
90 |
return isSetTasks; |
91 |
} |
92 |
|
62 |
// override default equals |
93 |
// override default equals |
63 |
public boolean equals(Object object) { |
94 |
public boolean equals(Object object) { |
64 |
if (!(object instanceof Employee)) { |
95 |
if (!(object instanceof Employee)) { |
65 |
return false; |
96 |
return false; |
66 |
} |
97 |
} |
67 |
Employee employeeObject = (Employee)object; |
98 |
Employee employeeObject = (Employee) object; |
68 |
if (getId() != employeeObject.getId()) { |
99 |
if (getId() != employeeObject.getId()) { |
69 |
return false; |
100 |
return false; |
70 |
} |
101 |
} |
71 |
if ((employeeObject.getLastName() == null) && (getLastName() != null)) { |
102 |
if ((employeeObject.getLastName() == null) && (getLastName() != null)) { |
72 |
return false; |
103 |
return false; |
73 |
} |
104 |
} |
74 |
//if ((employeeObject.getFirstName() == null) && (getFirstName() != null)) { |
105 |
if ((employeeObject.getFirstName() == null) && (getFirstName() != null)) { |
75 |
// return false; |
106 |
return false; |
76 |
//} |
107 |
} |
77 |
if ((employeeObject.getLastName() != null) && (getLastName() == null)) { |
108 |
if ((employeeObject.getLastName() != null) && (getLastName() == null)) { |
78 |
return false; |
109 |
return false; |
79 |
} |
110 |
} |
80 |
//if ((employeeObject.getFirstName() != null) && (getFirstName() == null)) { |
111 |
if ((employeeObject.getFirstName() != null) && (getFirstName() == null)) { |
81 |
// return false; |
|
|
82 |
//} |
83 |
//if ((getFirstName() != null) && (employeeObject.getFirstName() != null) && !getFirstName().equals(employeeObject.getFirstName())) { |
84 |
// return false; |
85 |
//} |
86 |
if ((getLastName() != null) && (employeeObject.getLastName() != null) && // |
87 |
!getLastName().equals(employeeObject.getLastName())) { |
88 |
return false; |
112 |
return false; |
89 |
} |
113 |
} |
|
|
114 |
if ((getFirstName() != null) && (employeeObject.getFirstName() != null) && !getFirstName().equals(employeeObject.getFirstName())) { |
115 |
return false; |
116 |
} |
117 |
if ((getLastName() != null) && (employeeObject.getLastName() != null) && !getLastName().equals(employeeObject.getLastName())) { |
118 |
return false; |
119 |
} |
90 |
if ((employeeObject.getTasks() == null) && (getTasks() != null)) { |
120 |
if ((employeeObject.getTasks() == null) && (getTasks() != null)) { |
91 |
return false; |
121 |
return false; |
92 |
} |
122 |
} |
93 |
if ((employeeObject.getTasks() != null) && (getTasks() == null)) { |
123 |
if ((employeeObject.getTasks() != null) && (getTasks() == null)) { |
94 |
return false; |
124 |
return false; |
95 |
} |
125 |
} |
96 |
if ((employeeObject.getTasks() != null) && (getTasks() != null) && // |
126 |
if ((employeeObject.getTasks() != null) && (getTasks() != null) && (!(employeeObject.getTasks() instanceof Vector) || !(getTasks() instanceof Vector))) { |
97 |
(!(employeeObject.getTasks() instanceof Vector) || !(getTasks() instanceof Vector))) { |
|
|
98 |
return false; |
127 |
return false; |
99 |
} |
128 |
} |
100 |
|
129 |
|
101 |
if((this.getId() == employeeObject.getId()) && // |
130 |
if((this.getId() == employeeObject.getId()) && // |
102 |
((this.getTasks()==null && employeeObject.getTasks()==null) || // |
131 |
((this.getTasks()==null && employeeObject.getTasks()==null) || // |
103 |
(this.getTasks().isEmpty() && employeeObject.getTasks().isEmpty()) || // |
132 |
(this.getTasks().isEmpty() && employeeObject.getTasks().isEmpty()) || // |
104 |
(this.getTasks().containsAll(employeeObject.getTasks()))) && // |
133 |
(this.getTasks().containsAll(employeeObject.getTasks()))) && // |
105 |
(this.getTasks().size() == employeeObject.getTasks().size())) { |
134 |
(this.getTasks().size() == employeeObject.getTasks().size())) { |
106 |
return true; |
135 |
return true; |
107 |
} |
136 |
} |
108 |
|
137 |
|
109 |
// todo handle : |
|
|
110 |
/*Expected: |
111 |
Employee(123,[null, write code, null],Doe) |
112 |
Actual: |
113 |
Employee(123,[write code],Doe) |
114 |
*/ |
115 |
return false; |
138 |
return false; |
116 |
} |
139 |
} |
117 |
|
140 |
|
118 |
public int getId() { |
141 |
// ============================================== |
119 |
return id; |
|
|
120 |
} |
121 |
|
142 |
|
122 |
public String getLastName() { |
143 |
public String toString() { |
123 |
return lastName; |
144 |
return "Employee(" + getId() + "," + firstName + "," + tasks + "," + lastName + ")"; |
124 |
} |
145 |
} |
125 |
|
146 |
|
126 |
public Vector getTasks() { |
147 |
} |
127 |
return tasks; |
|
|
128 |
} |
129 |
|
130 |
public boolean isSetTasks() { |
131 |
return isSetTasks; |
132 |
} |
133 |
|
134 |
public void setId(int id) { |
135 |
this.id = id; |
136 |
} |
137 |
|
138 |
public void setLastName(String lastName) { |
139 |
this.lastName = lastName; |
140 |
} |
141 |
|
142 |
public void setTasks(Vector tasks) { |
143 |
this.tasks = tasks; |
144 |
isSetTasks = true; |
145 |
} |
146 |
|
147 |
public String toString() { |
148 |
return "Employee(" + getId() + "," + //firstName + "," + |
149 |
tasks + "," + |
150 |
lastName + ")"; |
151 |
} |
152 |
} |