2015-09-07 11:44:36 -06:00
|
|
|
// typeinfo/Staff.java
|
2015-12-15 11:47:04 -08:00
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
2015-06-15 17:47:35 -07:00
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class Staff extends ArrayList<Position> {
|
|
|
|
public void add(String title, Person person) {
|
|
|
|
add(new Position(title, person));
|
|
|
|
}
|
|
|
|
public void add(String... titles) {
|
|
|
|
for(String title : titles)
|
|
|
|
add(new Position(title));
|
|
|
|
}
|
|
|
|
public Staff(String... titles) { add(titles); }
|
|
|
|
public boolean positionAvailable(String title) {
|
|
|
|
for(Position position : this)
|
|
|
|
if(position.getTitle().equals(title) &&
|
2015-12-15 11:47:04 -08:00
|
|
|
position.getPerson().empty)
|
2015-06-15 17:47:35 -07:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public void fillPosition(String title, Person hire) {
|
|
|
|
for(Position position : this)
|
|
|
|
if(position.getTitle().equals(title) &&
|
2015-12-15 11:47:04 -08:00
|
|
|
position.getPerson().empty) {
|
2015-06-15 17:47:35 -07:00
|
|
|
position.setPerson(hire);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw new RuntimeException(
|
|
|
|
"Position " + title + " not available");
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Staff staff = new Staff("President", "CTO",
|
|
|
|
"Marketing Manager", "Product Manager",
|
|
|
|
"Project Lead", "Software Engineer",
|
|
|
|
"Software Engineer", "Software Engineer",
|
|
|
|
"Software Engineer", "Test Engineer",
|
|
|
|
"Technical Writer");
|
|
|
|
staff.fillPosition("President",
|
|
|
|
new Person("Me", "Last", "The Top, Lonely At"));
|
|
|
|
staff.fillPosition("Project Lead",
|
|
|
|
new Person("Janet", "Planner", "The Burbs"));
|
|
|
|
if(staff.positionAvailable("Software Engineer"))
|
|
|
|
staff.fillPosition("Software Engineer",
|
|
|
|
new Person("Bob", "Coder", "Bright Light City"));
|
|
|
|
System.out.println(staff);
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2015-12-15 11:47:04 -08:00
|
|
|
[Position: President, Employee: Me Last The Top, Lonely At,
|
|
|
|
Position: CTO, Employee: <Empty>, Position: Marketing
|
|
|
|
Manager, Employee: <Empty>, Position: Product Manager,
|
|
|
|
Employee: <Empty>, Position: Project Lead, Employee: Janet
|
|
|
|
Planner The Burbs, Position: Software Engineer, Employee:
|
|
|
|
Bob Coder Bright Light City, Position: Software Engineer,
|
|
|
|
Employee: <Empty>, Position: Software Engineer, Employee:
|
|
|
|
<Empty>, Position: Software Engineer, Employee: <Empty>,
|
|
|
|
Position: Test Engineer, Employee: <Empty>, Position:
|
|
|
|
Technical Writer, Employee: <Empty>]
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|