Search in sources :

Example 1 with InstanceCollection2

use of eu.esdihumboldt.hale.common.instance.model.ext.InstanceCollection2 in project hale by halestudio.

the class FilteredInstanceCollection method applyFilter.

/**
 * Create an instance collection that applies a filter to the given instance
 * collection.
 *
 * @param instances the instance collection to filter
 * @param filter the filter
 * @return the filtered instance collection
 */
public static InstanceCollection applyFilter(InstanceCollection instances, Filter filter) {
    if (filter instanceof TypeFilter && instances instanceof InstanceCollection2) {
        /*
			 * For type filters check if we can make use of fan-out.
			 */
        InstanceCollection2 instances2 = (InstanceCollection2) instances;
        if (instances2.supportsFanout()) {
            TypeDefinition type = ((TypeFilter) filter).getType();
            InstanceCollection result = instances2.fanout().get(type);
            if (result == null) {
                result = EmptyInstanceCollection.INSTANCE;
            }
            return result;
        }
    }
    // create a filtered collection
    return new FilteredInstanceCollection(instances, filter);
}
Also used : EmptyInstanceCollection(eu.esdihumboldt.hale.common.instance.model.ext.helper.EmptyInstanceCollection) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) InstanceCollection2(eu.esdihumboldt.hale.common.instance.model.ext.InstanceCollection2) TypeFilter(eu.esdihumboldt.hale.common.instance.model.TypeFilter) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Aggregations

InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)1 TypeFilter (eu.esdihumboldt.hale.common.instance.model.TypeFilter)1 InstanceCollection2 (eu.esdihumboldt.hale.common.instance.model.ext.InstanceCollection2)1 EmptyInstanceCollection (eu.esdihumboldt.hale.common.instance.model.ext.helper.EmptyInstanceCollection)1 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)1