Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions java/com/aa/act/interview/org/Organization.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public abstract class Organization {

private Position root;
private int identifier = 0;

public Organization() {
root = createOrganization();
Expand All @@ -20,8 +21,9 @@ public Organization() {
* @return the newly filled position or empty if no position has that title
*/
public Optional<Position> hire(Name person, String title) {
//your code here
return Optional.empty();
addToOrgainization(root, new Employee(identifier, person), title);
identifier++;
return Optional.of(root);
}

@Override
Expand All @@ -36,4 +38,24 @@ private String printOrganization(Position pos, String prefix) {
}
return sb.toString();
}

/**
* Recursively iterates through the organization chart to add newly hired employees to it
*
* @param startPosition - the position on the organization chart this iteration is starting at
* @param employee
* @param employeeTitle
*/
private void addToOrgainization(Position startPosition, Employee employee, String employeeTitle) {
if(startPosition.getTitle().equals(employeeTitle)) {
startPosition.setEmployee(Optional.of(employee));
} else {
if(startPosition.getDirectReports() != null && startPosition.getDirectReports().size() !=0) {
for(Position position : startPosition.getDirectReports()) {
addToOrgainization(position, employee, employeeTitle);
}
}
}
}
}