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);
}
}
}
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;
}
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;
}
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);
}
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);
}
}
}
Aggregations