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
23 changes: 21 additions & 2 deletions java/com/aa/act/interview/org/Organization.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
package com.aa.act.interview.org;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class Organization {

private Position root;
private AtomicInteger employeeCounter; // Unique identifier for new employees

public Organization() {
root = createOrganization();
employeeCounter = new AtomicInteger(0); // Initialize employee counter
}

protected abstract Position createOrganization();

/**
* hire the given person as an employee in the position that has that title
*
* @param person
* @param title
* @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 hire(root, person, title);
}

private Optional<Position> hire(Position position, Name person, String title) {
if(position.getTitle().equals(title) && !position.isFilled()) {
Employee newEmployee = new Employee(employeeCounter.incrementAndGet(), person);
position.setEmployee(Optional.of(newEmployee));
return Optional.of(position);
}

for(Position report : position.getDirectReports()) {
Optional<Position> result = hire(report, person, title);
if(result.isPresent()) {
return result;
}
}

return Optional.empty();
}

Expand Down