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


# Changes<TAdd, TUpdate>

The edits to one record kind: records to add, partial updates and IDs to remove. Each [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/scheduling-changes.md>) starts with an empty instance per record kind, and edits go into its lists.

| Field of `SchedulingChanges` | Type |
|---|---|
| `tasks` | `Changes<TaskData, TaskUpdate>` |
| `links` | `Changes<LinkAdd, LinkUpdate>` |
| `resources` | `Changes<ResourceData, ResourceUpdate>` |
| `assignments` | `Changes<AssignmentData, AssignmentUpdate>` |

## Declaration

```java
public class Changes<TAdd extends DeepCloneable<TAdd>, TUpdate extends DeepCloneable<TUpdate>>
    extends ValueRecord implements DeepCloneable<Changes<TAdd, TUpdate>>
```

| Type parameter | Description |
|---|---|
| `TAdd` | The full record to add: [`TaskData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/task-data.md>), [`LinkAdd`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/link-add.md>), [`ResourceData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/resource-data.md>) or [`AssignmentData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/assignment-data.md>). |
| `TUpdate` | The partial update record: [`TaskUpdate`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/task-update.md>), [`LinkUpdate`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/link-update.md>), [`ResourceUpdate`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/resource-update.md>) or [`AssignmentUpdate`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/assignment-update.md>). |

Both type arguments implement [`DeepCloneable<T>`](<https://docs.dhtmlx.com/planning-engine/java/api/data/deep-cloneable.md>), so `deepClone()` can copy every record in the lists.

## Constructors

### Changes()

```java
public Changes()
```

Creates an instance with all three lists empty.

## Fields

| Field | Type | Default | Description |
|---|---|---|---|
| `add` | [`Vec<TAdd>`](<https://docs.dhtmlx.com/planning-engine/java/api/support/vec.md>) | empty | Records to add. The ID of each record must not exist yet. A [`LinkAdd`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/link-add.md>) or [`AssignmentData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/assignment-data.md>) with a `null` ID gets a generated one. |
| `update` | [`Vec<TUpdate>`](<https://docs.dhtmlx.com/planning-engine/java/api/support/vec.md>) | empty | Partial updates. Each record names an existing ID. Its [`Patch<T>`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/patch.md>) fields keep, clear or set each value. |
| `remove` | [`Vec<Id>`](<https://docs.dhtmlx.com/planning-engine/java/api/support/vec.md>) | empty | IDs of existing records to remove. |

Each list entry is one operation. In [`ApplyReport`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/apply-report.md>), an operation's path is its group, its list and its index: `tasks.add[0]`, `links.remove[1]`, `assignments.update[2]`. An unknown ID in `update` or `remove`, or an ID in `add` that already exists, rejects that operation. Removing a record also removes the records that depend on it, and [`ApplyReport.effects`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/apply-report.md#changeeffects>) lists them. For the order in which the lists run, see [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/scheduling-changes.md>).

The lists are mutable, so entries can go straight into a field: `changes.tasks.update.add(new TaskUpdate(Id.num(1)).withDuration(Patch.of(3.0)))`. Keep the fields non-null: a `null` list makes the call that reads the change set throw `NullPointerException`.

## Methods

### withAdd

```java
public Changes<TAdd, TUpdate> withAdd(Vec<TAdd> value)
public Changes<TAdd, TUpdate> withAdd(java.util.Collection<? extends TAdd> value)
```

Sets `add` and returns this instance for chaining. The `Vec` overload stores the given list itself. The `Collection` overload copies the elements into a new `Vec`, so `List.of(...)` works.

**Returns** - this `Changes`.

### withUpdate

```java
public Changes<TAdd, TUpdate> withUpdate(Vec<TUpdate> value)
public Changes<TAdd, TUpdate> withUpdate(java.util.Collection<? extends TUpdate> value)
```

Sets `update` and returns this instance for chaining. The overloads behave as in `withAdd`.

**Returns** - this `Changes`.

### withRemove

```java
public Changes<TAdd, TUpdate> withRemove(Vec<Id> value)
public Changes<TAdd, TUpdate> withRemove(java.util.Collection<? extends Id> value)
```

Sets `remove` and returns this instance for chaining. The overloads behave as in `withAdd`.

**Returns** - this `Changes`.

### deepClone

```java
public Changes<TAdd, TUpdate> deepClone()
```

Returns a copy with new lists. Each record in `add` and `update` is deep-copied. `remove` holds the same [`Id`](<https://docs.dhtmlx.com/planning-engine/java/api/data/id.md>) values, which are immutable.

**Returns** - a new, independent `Changes`.

### copy

```java
public Changes<TAdd, TUpdate> copy()
```

Returns a shallow copy. The copy shares the three `Vec` instances with the original, so adding to a list of one shows up in the other.

**Returns** - a new `Changes` that shares its lists.

### 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 `Changes` are equal when their `add`, `update` and `remove` lists are equal. `toString()` lists the three fields, for logging.

## Example

Add, update and remove tasks in one change set:

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

public class ChangesExample {
  public static void main(String[] args) throws Exception {
    Moment monday = Moment.fromYmdHm(2026, 8, 10, 8, 0);
    ProjectData data = new ProjectData()
        .withTasks(List.of(
            new TaskData(Id.num(1)).withStartDate(monday).withDuration(2.0),
            new TaskData(Id.num(2)).withStartDate(monday).withDuration(1.0)));

    Project project = new Project();
    ScheduleResult solved = project.solve(data, new SolveOptions());

    SchedulingChanges changes = new SchedulingChanges().withBaselineId(solved.baselineId);
    changes.tasks.add.add(new TaskData(Id.num(3)).withStartDate(monday).withDuration(4.0));
    changes.tasks.update.add(new TaskUpdate(Id.num(1)).withDuration(Patch.of(3.0)));
    changes.tasks.remove.add(Id.num(2));

    ApplyReport report = project.apply(changes);
    for (AppliedOperation applied : report.applied) {
      System.out.println(applied.path); // tasks.remove[0], tasks.add[0], tasks.update[0]
    }
  }
}
```

## Related

- [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/scheduling-changes.md>) - the change set with one `Changes` per record kind
- [`Patch<T>`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/patch.md>) - the fields of the update records
- [`ApplyReport`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/apply-report.md>) - the operation paths and side effects after `apply`
- [Data Updates](<https://docs.dhtmlx.com/planning-engine/java/live-projects/editing-a-project.md#change-sets>) - building change sets
