private Instance getChanges(
     Instance in, Function<Instance, Instance> oldFunction, boolean isInput) {
   if (in._isNew()) {
     return in.cloneInstance();
   }
   Instance old = oldFunction.apply(in);
   return prepareChanges(in, old, oldFunction, isInput);
 }
 /**
  * Allocates duplicate IDs to newly inserted instances in this organization to reference it from
  * other instance.
  *
  * @param in
  * @param entityId
  */
 private void allocateDuplicateId(Instance in, MutableLong entityId) {
   if (in == null) {
     return;
   }
   if (in._isNew()) {
     long nextId = IdProvider.prepareID(entityId.longValue(), 0, in._type(), true);
     in._setId(nextId);
     entityId.increment();
   }
   in._visit(
       (inst, isChild) -> {
         if (isChild) {
           allocateDuplicateId((Instance) inst, entityId);
         }
       });
 }