NIHVIVO-2573 Merge r7935 from nihvivo-rel-1.2 branch: Improved the implementation of the solution in r7931/7932

This commit is contained in:
ryounes 2011-05-04 01:18:34 +00:00
parent 7b1ed1bec6
commit cab4c1edbd

View file

@ -124,9 +124,8 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
logData(statementData); logData(statementData);
} }
// Compile a list of the statements with less specific subclasses, which should be removed // Compile a list of the statements with most specific subclasses; others will be removed
// from the statement data List<Map<String, String>> filteredList = new ArrayList<Map<String, String>>();
List<Map<String, String>> statementsToRemove = new ArrayList<Map<String, String>>();
Set<String> processedObjects = new HashSet<String>(); Set<String> processedObjects = new HashSet<String>();
for (Map<String, String> outerMap : statementData) { for (Map<String, String> outerMap : statementData) {
String objectUri = outerMap.get(objectVariableName); String objectUri = outerMap.get(objectVariableName);
@ -142,16 +141,15 @@ public class CollatedObjectPropertyTemplateModel extends ObjectPropertyTemplateM
} }
// Sort the data for this object from most to least specific subclass, with nulls at end // Sort the data for this object from most to least specific subclass, with nulls at end
Collections.sort(dataForThisObject, new SubclassComparator(wdf)); Collections.sort(dataForThisObject, new SubclassComparator(wdf));
dataForThisObject.remove(0); // Keep only the first one (most specific subclass) filteredList.add(dataForThisObject.get(0));
statementsToRemove.addAll(dataForThisObject);
} }
// We remove statements from the original list, rather than returning a new list, // Use retainAll() rather than clear() plus addAll() in order to retain the subclass ordering
// in order to preserve the subclass orderings, since the collation depends on the // of statementData. Otherwise the list is now ordered by author, whereas collate() assumes
// statements being ordered first by subclass. // the list is ordered by subclass.
for (Map<String, String> map : statementsToRemove) { //statementData.clear();
statementData.remove(map); //statementData.addAll(filteredList);
} statementData.retainAll(filteredList);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Data after subclass filtering"); log.debug("Data after subclass filtering");