Source:
<code>public static BasicEntityMemento.Builder newEntityMementoBuilder(Entity entity) { BasicEntityMemento.Builder builder = BasicEntityMemento.builder(); builder.id = entity.getId(); builder.displayName = entity.getDisplayName(); builder.type = entity.getClass().getName(); builder.isTopLevelApp = (entity instanceof Application && entity.getParent() == null); Map<ConfigKey<?>, Object> localConfig = ((EntityInternal)entity).getConfigMap().getLocalConfig(); for (Map.Entry<ConfigKey<?>, Object> entry : localConfig.entrySet()) { ConfigKey<?> key = checkNotNull(entry.getKey(), localConfig); Object value = entry.getValue(); if (value instanceof Task) { <START> if (((Task)value).isDone()) { <END> if (((Task)value).isError()) { value = null; } else { value = ((Task)value).getUnchecked(); } } else { value = null; } } builder.config.put(key, value); } Map<AttributeSensor, Object> allAttributes = ((EntityInternal)entity).getAllAttributes(); for (Map.Entry<AttributeSensor, Object> entry : allAttributes.entrySet()) { AttributeSensor<?> key = checkNotNull(entry.getKey(), allAttributes); Object value = entry.getValue(); builder.attributes.put((AttributeSensor<?>)key, value); } for (Location location : entity.getLocations()) { builder.locations.add(location.getId()); } for (Entity child : entity.getChildren()) { builder.children.add(child.getId()); } Entity parentEntity = entity.getParent(); builder.parent = (parentEntity != null) ? parentEntity.getId() : null; if (entity instanceof Group) { for (Entity member : ((Group)entity).getMembers()) { builder.members.add(member.getId()); } } return builder; }</code><technical_language>Task task = (Task) value; if (task.isDone() && !task.isError()) { = task.getUnchecked(); } else { // TODO record a completed errored task? = null; }</technical_language>

Target:
public static BasicEntityMemento.Builder newEntityMementoBuilder(Entity entity) { BasicEntityMemento.Builder builder = BasicEntityMemento.builder(); builder.id = entity.getId(); builder.displayName = entity.getDisplayName(); builder.type = entity.getClass().getName(); builder.isTopLevelApp = (entity instanceof Application && entity.getParent() == null); Map<ConfigKey<?>, Object> localConfig = ((EntityInternal)entity).getConfigMap().getLocalConfig(); for (Map.Entry<ConfigKey<?>, Object> entry : localConfig.entrySet()) { ConfigKey<?> key = checkNotNull(entry.getKey(), localConfig); Object value = entry.getValue(); if (value instanceof Task) { Task task = (Task) value; if (task.isDone() && !task.isError()) { value = task.getUnchecked(); } else { value = null; } } builder.config.put(key, value); } Map<AttributeSensor, Object> allAttributes = ((EntityInternal)entity).getAllAttributes(); for (Map.Entry<AttributeSensor, Object> entry : allAttributes.entrySet()) { AttributeSensor<?> key = checkNotNull(entry.getKey(), allAttributes); Object value = entry.getValue(); builder.attributes.put((AttributeSensor<?>)key, value); } for (Location location : entity.getLocations()) { builder.locations.add(location.getId()); } for (Entity child : entity.getChildren()) { builder.children.add(child.getId()); } Entity parentEntity = entity.getParent(); builder.parent = (parentEntity != null) ? parentEntity.getId() : null; if (entity instanceof Group) { for (Entity member : ((Group)entity).getMembers()) { builder.members.add(member.getId()); } } return builder; }