Class Worker

All Implemented Interfaces:
Serializable, Commented, ComprehensiveIdentification, Identified<Identification>, Named, Temporal<TimeCoordinate>
Direct Known Subclasses:
Artist, Doctor, Judge, JuryMember, Lawyer, Prosecutor

public class Worker extends EconomicAgent
Represents a worker within an Organization.

A worker is an EconomicAgent that has a specific job function, earns an income, and exists within a professional hierarchy of chiefs and subalterns.

* @version 6.1
Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
See Also:
  • Constructor Details

    • Worker

      public Worker(Individual individual, Organization organization, String function, Money annualIncome)
      Creates a new worker.
      Parameters:
      individual - the underlying biological or social individual.
      organization - the organization they work for.
      function - their job title or function.
      annualIncome - their yearly salary.
    • Worker

      public Worker(Individual individual, WorkSituation workSituation, String function, Organization organization)
      Legacy constructor for work situation compatibility.
  • Method Details

    • setFunction

      public void setFunction(String function)
      Sets the job function description.
      Parameters:
      function - the job title or description.
      Throws:
      IllegalArgumentException - if function is null or empty.
    • getAnnualIncome

      public Money getAnnualIncome()
      Returns the annual income of this worker.
      Returns:
      the yearly salary.
    • setAnnualIncome

      public void setAnnualIncome(Money annualIncome)
      Sets the annual income for this worker.
      Parameters:
      annualIncome - the new yearly salary.
      Throws:
      IllegalArgumentException - if income is null.
    • getWorkedHours

      public Quantity<Time> getWorkedHours()
      Returns the number of hours worked per year.
      Returns:
      the worked hours.
    • setWorkedHours

      public void setWorkedHours(Quantity<Time> workedHours)
      Sets the number of hours worked per year.
      Parameters:
      workedHours - the new hour count.
    • setWorkedHours

      public void setWorkedHours(double workedHours)
      Sets the number of hours worked per year.
      Parameters:
      workedHours - the new hour count in double (converted to Quantity).
    • hasChild

      public boolean hasChild()
      Checks if this worker has any subordinates.
      Returns:
      true if subalterns set is not empty.
    • hasChild

      public boolean hasChild(Worker child)
      Checks if a specific worker is an immediate subordinate.
      Parameters:
      child - the worker to check.
      Returns:
      true if the worker is in the subalterns set.
    • getSubalterns

      public Set<Worker> getSubalterns()
      Returns an unmodifiable set of immediate subordinates.
      Returns:
      the subalterns.
    • setSubalterns

      public void setSubalterns(Set<Worker> subalterns) throws IllegalArgumentException
      Sets the set of immediate subordinates.
      Parameters:
      subalterns - the subordinates to set.
      Throws:
      IllegalArgumentException - if subalterns set is null.
    • addSubaltern

      public void addSubaltern(Worker child) throws IllegalArgumentException
      Adds an immediate subordinate.
      Parameters:
      child - the worker to add.
      Throws:
      IllegalArgumentException - if the child is already a supervisor or self.
    • removeSubaltern

      public void removeSubaltern(Worker child)
      Removes an immediate subordinate.
      Parameters:
      child - the worker to remove.
    • hasChief

      public boolean hasChief()
      Checks if this worker has any immediate supervisors.
      Returns:
      true if chiefs set is not empty.
    • getChiefs

      public Set<Worker> getChiefs()
      Returns an unmodifiable set of immediate supervisors.
      Returns:
      the chiefs.
    • reparent

      public void reparent(Worker oldParent, Worker newParent)
      Change a supervisor for this worker.
      Parameters:
      oldParent - the current supervisor to remove.
      newParent - the new supervisor to add.
    • getLeaders

      public Set<Worker> getLeaders()
      Returns the set of workers at the top of the hierarchy for this worker.
      Returns:
      the top-level bosses.
    • getCoWorkers

      public Set<Worker> getCoWorkers()
      Returns workers having the same immediate supervisors.
      Returns:
      the set of coworkers.
    • getCommonRoot

      public static Worker getCommonRoot(Worker w1, Worker w2)
      Finds the lowest common supervisor for two workers.
      Parameters:
      w1 - first worker.
      w2 - second worker.
      Returns:
      the common root worker, or null.
    • getLineage

      public static List<Worker> getLineage(Worker root, Worker target)
      Returns the workers path from a root to a target worker.
      Parameters:
      root - the starting worker.
      target - the destination worker.
      Returns:
      the list representing the path.
    • extractTree

      public static Tree<Worker> extractTree(Worker w1, Worker w2)
      Creates a tree structure representing the hierarchy between two workers.
      Parameters:
      w1 - first worker.
      w2 - second worker.
      Returns:
      the tree of workers.
    • getAllSubalterns

      public Set<Worker> getAllSubalterns()
      Returns all subordinates at any depth.
      Returns:
      the set of all subalterns.
    • getSubalternsAtLevelK

      public Set<Worker> getSubalternsAtLevelK(int k)
      Returns all subordinates at a specific depth level.
      Parameters:
      k - the depth level (0 for self, 1 for immediate subalterns, etc.).
      Returns:
      the set of workers at depth k.
    • hasDistantSubaltern

      public boolean hasDistantSubaltern(Worker target)
      Checks if a worker is a subordinate at any depth.
      Parameters:
      target - the worker to search for.
      Returns:
      true if found in the hierarchy.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Role
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Role
    • getOrganization

      public Organization getOrganization()
      Returns the organization this worker is employed by.
      Returns:
      the organization.
    • setOrganization

      public void setOrganization(Organization organization)
      Sets the organization for this worker.
      Parameters:
      organization - the new employer.