Search in sources :

Example 16 with DefaultType

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;
}
Also used : Entity(eu.esdihumboldt.hale.common.align.model.Entity) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) PropertyEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition) ChildContext(eu.esdihumboldt.hale.common.align.model.ChildContext) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Property(eu.esdihumboldt.hale.common.align.model.Property) DefaultProperty(eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)

Aggregations

DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)16 TypeEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition)15 Type (eu.esdihumboldt.hale.common.align.model.Type)14 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)12 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)6 PropertyEntityDefinition (eu.esdihumboldt.hale.common.align.model.impl.PropertyEntityDefinition)6 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)6 Cell (eu.esdihumboldt.hale.common.align.model.Cell)5 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)5 DefaultAlignment (eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)4 DefaultProperty (eu.esdihumboldt.hale.common.align.model.impl.DefaultProperty)4 DefaultSchema (eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchema)4 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)4 BufferedOutputStream (java.io.BufferedOutputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4