Pool#

The workers that SkillLayer.slots may put on tasks. Each worker is a project resource with its skills. Create one with new Pool(), fill it with withWorkers(...), and pass it to SkillLayer.slots together with the requirements.

Declaration#

public class Pool extends ValueRecord implements DeepCloneable<Pool>

Constructors#

Pool()#

public Pool()

Creates an empty pool: workers is an empty Vec.

Fields#

Field Type Default Description
workers Vec<Worker> empty The workers, in preference order.

workers#

public Vec<Worker> workers = new Vec<Worker>();

The order is the preference order: a slot's allowed list keeps the workers in pool order, and that order breaks ties between equally scored candidates.

Each worker must name a resource of the project, and a resource can appear only once. SkillLayer.slots and SkillLayer.validatePool check this and throw MatchException.Invalid with a pool.workers[i]… path; see Errors.

Methods#

withWorkers#

public Pool withWorkers(Vec<Worker> value)
public Pool withWorkers(java.util.Collection<? extends Worker> value)

Sets workers and returns this pool. 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 Pool deepClone()

Returns a deep copy. The workers list and every Worker in it are copied, so nothing is shared with the original.

copy#

public Pool copy()

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

equals, hashCode, toString#

Inherited from ValueRecord. Two pools are equal when workers holds equal workers in the same order. toString() returns Pool{workers=[…]}.

Example#

Three workers. ann comes first, so she's preferred over bob when both fit a slot equally well.

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

public class PoolExample {
  public static void main(String[] args) throws Exception {
    Pool pool = new Pool().withWorkers(List.of(
        new Worker().withResource(Id.str("ann"))
            .withSkills(List.of(new Skill().withId(Id.str("backend")).withValue(3))),
        new Worker().withResource(Id.str("bob"))
            .withSkills(List.of(
                new Skill().withId(Id.str("backend")).withValue(2),
                new Skill().withId(Id.str("frontend")))),
        new Worker().withResource(Id.str("cid"))
            .withSkills(List.of(new Skill().withId(Id.str("frontend"))))));

    System.out.println(pool.workers.size()); // 3
  }
}