Worker#

A project resource that can be assigned, together with its skill values. Workers go into Pool.workers, which SkillLayer.slots reads. Create one with new Worker() and the fluent withX setters.

Declaration#

public class Worker extends ValueRecord implements DeepCloneable<Worker>

Constructors#

Worker()#

public Worker()

Creates a worker with resource set to null and an empty skills list. Set resource before passing the worker on.

Fields#

Field Type Default Description
resource Id null Id of a resource in the project's accepted state. Required. When the worker satisfies a requirement, this id goes into the slot's allowed list.
skills Vec<Skill> empty The worker's skill values, one Skill per skill id. For how a skill missing from the list compares, see SkillMatch.

resource must name a resource of the project and appear only once in the pool. Skill ids must be unique within skills, and each value must be finite. SkillLayer.slots and SkillLayer.validatePool check this and throw MatchException.Invalid at pool.workers[i].resource, pool.workers[i].skills[j].id or pool.workers[i].skills[j].value. See Errors.

Methods#

withResource#

public Worker withResource(Id value)

Sets resource and returns this worker.

withSkills#

public Worker withSkills(Vec<Skill> value)
public Worker withSkills(java.util.Collection<? extends Skill> value)

Sets skills and returns this worker. The Vec overload stores the given list itself. The Collection overload copies the elements into a new Vec, so List.of(...) works; null sets the field to null.

deepClone#

public Worker deepClone()

Returns a deep copy. The skills list and every Skill in it are copied, so nothing is shared with the original. resource is an immutable Id and is shared.

copy#

public Worker copy()

Returns a shallow copy. The copy holds the same skills list as the original.

equals, hashCode, toString#

Inherited from ValueRecord. Two workers are equal when resource is equal and skills holds equal skills in the same order. toString() lists the fields, as in Worker{resource=ann, skills=[…]}.

Example#

import java.util.List;
import org.dhtmlx.plen.*;

public class WorkerExample {
  public static void main(String[] args) throws Exception {
    Worker ann = new Worker()
        .withResource(Id.str("ann"))
        .withSkills(List.of(
            new Skill().withId(Id.str("frontend")),
            new Skill().withId(Id.str("qa")).withValue(2)));

    // No skills: every skill counts as 0 for this worker.
    Worker bob = new Worker().withResource(Id.str("bob"));

    Pool pool = new Pool().withWorkers(List.of(ann, bob));
    System.out.println(pool.workers.size()); // 2
  }
}