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


# ResourceData

A resource that assignments book: its id, its capacity and an optional working calendar. Put resources in [`ProjectData.resources`](<https://docs.dhtmlx.com/planning-engine/java/api/data/project-data.md>) and reference them from [`AssignmentData.resource`](<https://docs.dhtmlx.com/planning-engine/java/api/data/assignment-data.md>). Create one with `new ResourceData()` and the fluent `withX` setters, or decode JSON with [`Decode.fromJson`](<https://docs.dhtmlx.com/planning-engine/java/api/json/decode.md>).

## Declaration

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

## Constructors

### ResourceData()

```java
public ResourceData()
```

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

## Fields

| Field | Type | Default | Description |
|---|---|---|---|
| `id` | [`Id`](<https://docs.dhtmlx.com/planning-engine/java/api/data/id.md>) | `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`](<https://docs.dhtmlx.com/planning-engine/java/api/data/scheduling-config.md>) (default `1.0`). Must be finite and `>= 0`. |
| `calendarId` | `Id` | `null` | Working calendar of the resource. Used in [`CalendarMode.RESOURCE`](<https://docs.dhtmlx.com/planning-engine/java/api/data/calendar-mode.md>) (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](<https://docs.dhtmlx.com/planning-engine/java/scheduling/working-time-calendars.md>).

## Methods

### withId, withCapacity, withCalendarId

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

```java
public ResourceData deepClone()
```

Returns a new `ResourceData` with the same field values.

**Returns** - a new `ResourceData`.

### copy

```java
public ResourceData copy()
```

Returns a shallow copy of this instance.

**Returns** - a new `ResourceData` with the same field values.

### equals, hashCode, toString

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

Inherited from [`ValueRecord`](<https://docs.dhtmlx.com/planning-engine/java/api/support/value-record.md>). Two `ResourceData` are equal when all three fields are equal. `toString()` lists the fields.

## Validation

The calls that take a [`ProjectData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/project-data.md>) check its resources. A failure throws an [`InputException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/input-exception.md>) 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`](<https://docs.dhtmlx.com/planning-engine/java/api/project/validation.md>), 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`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/resource-update.md>).

## Example

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

## Related

- [`AssignmentData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/assignment-data.md>) - bookings of the resource
- [`CalendarData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/calendar-data.md>) - the resource's working calendar
- [`ResourceUpdate`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/resource-update.md>) - editing a resource in a live project
- [Resources and capacity](<https://docs.dhtmlx.com/planning-engine/java/resources-and-assignment/resources-and-assignments.md#resources-and-capacity>) - capacity and resource calendars
