private static String collapse(StaticPropertyOracle... oracles) {
// The map used to create the string key
SortedMap<String, SortedSet<String>> collapsedPropertyMap = new TreeMap<String, SortedSet<String>>();
for (StaticPropertyOracle oracle : oracles) {
for (int i = 0, j = oracle.getOrderedProps().length; i < j; i++) {
BindingProperty prop = oracle.getOrderedProps()[i];
String value = oracle.getOrderedPropValues()[i];
boolean isCollapsed = false;
// Iterate over the equivalence sets defined in the property
for (Set<String> equivalenceSet : prop.getCollapsedValues()) {
if (equivalenceSet.contains(value)) {
/*
* If we find a set that contains the current value, add all the
* values in the set. This accounts for the transitive nature of
* equality.
*/
SortedSet<String> toAdd = collapsedPropertyMap.get(prop.getName());
if (toAdd == null) {
toAdd = new TreeSet<String>();
collapsedPropertyMap.put(prop.getName(), toAdd);
isCollapsed = true;
}
toAdd.addAll(equivalenceSet);
}
}
if (!isCollapsed) {
// For "hard" properties, add the singleton value
collapsedPropertyMap.put(prop.getName(), new TreeSet<String>(
Arrays.asList(value)));
}
}
}
return collapsedPropertyMap.toString();