[Canonical page](<https://docs.dhtmlx.com/planning-engine/java/api/assign/worker/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# Worker

A project resource that can be assigned, together with its skill values. Workers go into [`Pool.workers`](<https://docs.dhtmlx.com/planning-engine/java/api/assign/pool.md#workers>), which [`SkillLayer.slots`](<https://docs.dhtmlx.com/planning-engine/java/api/skill-layer-slots.md>) reads. Create one with `new Worker()` and the fluent `withX` setters.

## Declaration

```java
public class Worker extends ValueRecord implements DeepCloneable<Worker>
```

## Constructors

### Worker()

```java
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`](<https://docs.dhtmlx.com/planning-engine/java/api/data/id.md>) | `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`](<https://docs.dhtmlx.com/planning-engine/java/api/suggest/slot.md>) list. |
| `skills` | [`Vec`](<https://docs.dhtmlx.com/planning-engine/java/api/support/vec.md>)`<`[`Skill`](<https://docs.dhtmlx.com/planning-engine/java/api/assign/skill.md>)`>` | empty | The worker's skill values, one `Skill` per skill id. For how a skill missing from the list compares, see [`SkillMatch`](<https://docs.dhtmlx.com/planning-engine/java/api/assign/requirement.md#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`](<https://docs.dhtmlx.com/planning-engine/java/api/skill-layer-slots.md>) and [`SkillLayer.validatePool`](<https://docs.dhtmlx.com/planning-engine/java/api/skill-layer-slots.md#skilllayervalidatepool>) check this and throw [`MatchException.Invalid`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/match-exception.md>) at `pool.workers[i].resource`, `pool.workers[i].skills[j].id` or `pool.workers[i].skills[j].value`. See [Errors](<https://docs.dhtmlx.com/planning-engine/java/api/skill-layer-slots.md#errors>).

## Methods

### withResource

```java
public Worker withResource(Id value)
```

Sets `resource` and returns this worker.

### withSkills

```java
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

```java
public Worker deepClone()
```

Returns a deep copy. The `skills` list and every [`Skill`](<https://docs.dhtmlx.com/planning-engine/java/api/assign/skill.md>) in it are copied, so nothing is shared with the original. `resource` is an immutable `Id` and is shared.

### copy

```java
public Worker copy()
```

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

### equals, hashCode, toString

Inherited from [`ValueRecord`](<https://docs.dhtmlx.com/planning-engine/java/api/support/value-record.md>). 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

```java
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
  }
}
```

## Related

- [`Pool`](<https://docs.dhtmlx.com/planning-engine/java/api/assign/pool.md>) - the list of workers
- [`Skill`](<https://docs.dhtmlx.com/planning-engine/java/api/assign/skill.md>) - one skill value of a worker
- [`SkillLayer.slots`](<https://docs.dhtmlx.com/planning-engine/java/api/skill-layer-slots.md>) - the call that reads the workers
- [`MatchException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/match-exception.md>) - thrown for an invalid worker
- [Skills and requirements](<https://docs.dhtmlx.com/planning-engine/java/resources-and-assignment/skills-and-requirements.md#pools-and-skills>) - building a pool of workers
