Search in sources :

Example 1 with DeepIterableKey

use of eu.esdihumboldt.hale.common.instance.index.DeepIterableKey in project hale by halestudio.

the class IndexMergeHandler method addUnique.

/**
 * Apply instance property values to the merged result instance. Use the
 * "unique" strategy that only keeps unique values.
 *
 * @param result the result instance
 * @param instance the instance to merge with the result
 * @param property the name of the property that should be handled
 */
private void addUnique(MutableInstance result, Instance instance, QName property) {
    Object[] values = instance.getProperty(property);
    if (values == null || values.length <= 0) {
        return;
    }
    // collect unique values
    Object[] existingValues = result.getProperty(property);
    Set<DeepIterableKey> uniqueValues = new HashSet<>();
    if (existingValues != null) {
        for (Object value : existingValues) {
            uniqueValues.add(new DeepIterableKey(value));
        }
    }
    // add values not contained yet
    for (Object value : values) {
        DeepIterableKey key = new DeepIterableKey(value);
        if (uniqueValues.add(key)) {
            result.addProperty(property, value);
        }
    }
}
Also used : DeepIterableKey(eu.esdihumboldt.hale.common.instance.index.DeepIterableKey) HashSet(java.util.HashSet)

Example 2 with DeepIterableKey

use of eu.esdihumboldt.hale.common.instance.index.DeepIterableKey in project hale by halestudio.

the class IndexMergeHandler method allEqual.

@SuppressWarnings("unused")
private boolean allEqual(List<Object[]> list) {
    Iterator<Object[]> iter = list.iterator();
    // get first element
    DeepIterableKey first = new DeepIterableKey(iter.next());
    // compare rest to first
    while (iter.hasNext()) if (!first.equals(new DeepIterableKey(iter.next())))
        return false;
    return true;
}
Also used : DeepIterableKey(eu.esdihumboldt.hale.common.instance.index.DeepIterableKey)

Example 3 with DeepIterableKey

use of eu.esdihumboldt.hale.common.instance.index.DeepIterableKey in project hale by halestudio.

the class PropertiesMergeHandler method allEqual.

@SuppressWarnings("unused")
private boolean allEqual(List<Object[]> list) {
    Iterator<Object[]> iter = list.iterator();
    // get first element
    DeepIterableKey first = new DeepIterableKey(iter.next());
    // compare rest to first
    while (iter.hasNext()) if (!first.equals(new DeepIterableKey(iter.next())))
        return false;
    return true;
}
Also used : DeepIterableKey(eu.esdihumboldt.hale.common.instance.index.DeepIterableKey)

Example 4 with DeepIterableKey

use of eu.esdihumboldt.hale.common.instance.index.DeepIterableKey in project hale by halestudio.

the class PropertiesMergeHandler method getMergeKey.

@Override
protected DeepIterableKey getMergeKey(Instance instance, PropertiesMergeConfig mergeConfig) {
    if (mergeConfig.keyProperties.isEmpty()) {
        // merge all instances
        return DeepIterableKey.KEY_ALL;
    }
    List<Object> valueList = new ArrayList<Object>(mergeConfig.keyProperties.size());
    for (List<QName> propertyPath : mergeConfig.keyProperties) {
        // retrieve values from instance
        // XXX should nulls be listed?
        InstanceAccessor accessor = new InstanceAccessor(instance);
        for (QName name : propertyPath) {
            accessor.findChildren(name.getLocalPart(), Collections.singletonList(name.getNamespaceURI()));
        }
        valueList.add(accessor.list(true));
    }
    return new DeepIterableKey(valueList);
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) InstanceAccessor(eu.esdihumboldt.hale.common.instance.groovy.InstanceAccessor) DeepIterableKey(eu.esdihumboldt.hale.common.instance.index.DeepIterableKey)

Example 5 with DeepIterableKey

use of eu.esdihumboldt.hale.common.instance.index.DeepIterableKey in project hale by halestudio.

the class PropertiesMergeHandler method addUnique.

/**
 * Apply instance property values to the merged result instance. Use the
 * "unique" strategy that only keeps unique values.
 *
 * @param result the result instance
 * @param instance the instance to merge with the result
 * @param property the name of the property that should be handled
 */
private void addUnique(MutableInstance result, Instance instance, QName property) {
    Object[] values = instance.getProperty(property);
    if (values == null || values.length <= 0) {
        return;
    }
    // collect unique values
    Object[] existingValues = result.getProperty(property);
    Set<DeepIterableKey> uniqueValues = new HashSet<>();
    if (existingValues != null) {
        for (Object value : existingValues) {
            uniqueValues.add(new DeepIterableKey(value));
        }
    }
    // add values not contained yet
    for (Object value : values) {
        DeepIterableKey key = new DeepIterableKey(value);
        if (uniqueValues.add(key)) {
            result.addProperty(property, value);
        }
    }
}
Also used : DeepIterableKey(eu.esdihumboldt.hale.common.instance.index.DeepIterableKey) HashSet(java.util.HashSet)

Aggregations

DeepIterableKey (eu.esdihumboldt.hale.common.instance.index.DeepIterableKey)5 HashSet (java.util.HashSet)2 InstanceAccessor (eu.esdihumboldt.hale.common.instance.groovy.InstanceAccessor)1 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1