use of eu.esdihumboldt.hale.common.align.model.impl.DefaultType in project hale by halestudio.
the class EntityDefinitionServiceImpl method replace.
/**
* Creates a new ListMultimap with all occurrences of originalDef replaced
* by newDef. newDef must be a sibling of originalDef.
*
* @param entities the original list
* @param originalDef the entity definition to be replaced
* @param newDef the entity definition to use
* @return a new list
*/
private ListMultimap<String, ? extends Entity> replace(ListMultimap<String, ? extends Entity> entities, EntityDefinition originalDef, EntityDefinition newDef) {
ListMultimap<String, Entity> newList = ArrayListMultimap.create();
for (Entry<String, ? extends Entity> entry : entities.entries()) {
EntityDefinition entryDef = entry.getValue().getDefinition();
Entity newEntry;
if (AlignmentUtil.isParent(originalDef, entryDef)) {
if (entry.getValue() instanceof Type) {
// entry is a Type, so the changed Definition must be a
// Type, too.
newEntry = new DefaultType((TypeEntityDefinition) newDef);
} else if (entry.getValue() instanceof Property) {
// entry is a Property, check changed Definition.
if (originalDef.getPropertyPath().isEmpty()) {
// Type changed.
newEntry = new DefaultProperty(new PropertyEntityDefinition(newDef.getType(), entryDef.getPropertyPath(), entryDef.getSchemaSpace(), newDef.getFilter()));
} else {
// Some element of the property path changed.
List<ChildContext> newPath = new ArrayList<ChildContext>(entryDef.getPropertyPath());
int lastIndexOfChangedDef = newDef.getPropertyPath().size() - 1;
newPath.set(lastIndexOfChangedDef, newDef.getPropertyPath().get(lastIndexOfChangedDef));
newEntry = new DefaultProperty(new PropertyEntityDefinition(entryDef.getType(), newPath, entryDef.getSchemaSpace(), entryDef.getFilter()));
}
} else {
throw new IllegalStateException("Entity is neither a Type nor a Property.");
}
} else {
newEntry = entry.getValue();
}
newList.put(entry.getKey(), newEntry);
}
return newList;
}
Aggregations