Changes<TAdd, TUpdate>#

The edits to one record kind: records to add, partial updates and IDs to remove. Each SchedulingChanges 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#

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, LinkAdd, ResourceData or AssignmentData.
TUpdate The partial update record: TaskUpdate, LinkUpdate, ResourceUpdate or AssignmentUpdate.

Both type arguments implement DeepCloneable<T>, so deepClone() can copy every record in the lists.

Constructors#

Changes()#

public Changes()

Creates an instance with all three lists empty.

Fields#

Field Type Default Description
add Vec<TAdd> empty Records to add. The ID of each record must not exist yet. A LinkAdd or AssignmentData with a null ID gets a generated one.
update Vec<TUpdate> empty Partial updates. Each record names an existing ID. Its Patch<T> fields keep, clear or set each value.
remove Vec<Id> empty IDs of existing records to remove.

Each list entry is one operation. In ApplyReport, 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 lists them. For the order in which the lists run, see SchedulingChanges.

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#

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#

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#

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#

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 values, which are immutable.

Returns - a new, independent Changes.

copy#

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#

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

Inherited from ValueRecord. 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:

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]
    }
  }
}