ResourceData#

A resource that assignments book: its id, its capacity and an optional working calendar. Put resources in ProjectData.resources and reference them from AssignmentData.resource. Create one with new ResourceData() and the fluent withX setters, or decode JSON with Decode.fromJson.

Declaration#

public class ResourceData extends ValueRecord implements DeepCloneable<ResourceData>

Constructors#

ResourceData()#

public ResourceData()

Creates a resource with every field null. Set id before passing it on.

Fields#

Field Type Default Description
id Id null Resource id. Required, and unique among the project's resources.
capacity Double null Units available per time unit, in assignment value units (1.0 = 100 %). null uses SchedulingConfig.defaultResourceCapacity (default 1.0). Must be finite and >= 0.
calendarId Id null Working calendar of the resource. Used in CalendarMode.RESOURCE (the default), where it must name a calendar in ProjectData.calendars. null means the resource has no calendar of its own.

In CalendarMode.RESOURCE an assignment of this resource works on the resource calendar intersected with the task calendar. In the TASK and TASK_INHERITED modes the engine doesn't read calendarId, and only its format is checked. See Working-time calendars.

Methods#

withId, withCapacity, withCalendarId#

public ResourceData withId(Id value)
public ResourceData withCapacity(Double value)
public ResourceData withCalendarId(Id value)

Each setter assigns its field and returns this instance.

Returns - this ResourceData.

deepClone#

public ResourceData deepClone()

Returns a new ResourceData with the same field values.

Returns - a new ResourceData.

copy#

public ResourceData copy()

Returns a shallow copy of this instance.

Returns - a new ResourceData with the same field values.

equals, hashCode, toString#

public boolean equals(Object other)
public int hashCode()
public String toString()

Inherited from ValueRecord. Two ResourceData are equal when all three fields are equal. toString() lists the fields.

Validation#

The calls that take a ProjectData check its resources. A failure throws an InputException at the field's path:

Path When
resources[i].id Another resource has the same id.
resources[i].capacity capacity is negative or not finite.
resources[i].calendar_id In CalendarMode.RESOURCE, calendarId names no calendar.

With Validation.REPAIR, a duplicate id replaces the earlier resource at the earlier position and adds a repair note.

To change a resource of a solved project, use ResourceUpdate.

Example#

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

public class ResourceDataExample {
  public static void main(String[] args) throws Exception {
    Moment monday = Moment.fromYmdHm(2026, 1, 5, 8, 0);

    CalendarData mornings = new CalendarData()
        .withId(Id.str("mornings"))
        .withWorktime(new Worktime().withHours(List.of(new TimeRange(8 * 60, 12 * 60))));

    ResourceData anna = new ResourceData()
        .withId(Id.str("anna"))
        .withCapacity(0.5)
        .withCalendarId(Id.str("mornings"));

    ProjectData data = new ProjectData()
        .withConfig(new SchedulingConfig().withDurationUnit(TimeUnit.HOUR))
        .withCalendars(List.of(mornings))
        .withTasks(List.of(
            new TaskData(Id.str("review")).withStartDate(monday).withDuration(8.0)))
        .withResources(List.of(anna))
        .withAssignments(List.of(
            new AssignmentData()
                .withTask(Id.str("review"))
                .withResource(Id.str("anna"))
                .withValue(0.5)));

    ScheduleResult result = Engine.schedule(data, new SolveOptions());

    for (Mutation update : result.updates) {
      System.out.println(update.id + ": " + update.startDate + " - " + update.endDate);
    }
  }
}