// collect all the inputs and all the outputs in 2 Hashtables
Hashtable mergedInputs = new Hashtable();
Hashtable mergedOutputs = new Hashtable();
Iterator allList = allCapabilities.iterator();
while (allList.hasNext()) {
Capability entry = (Capability) allList.next();
// get inputs/outputs for this entry
TypeOrFeature[] entryInps = entry.getInputs();
TypeOrFeature[] entryOuts = entry.getOutputs();
// add/merge inputs in Hashtable
for (int i = 0; i < entryInps.length; i++) {
TypeOrFeature nextTof = entryInps[i];
String name = nextTof.getName();
TypeOrFeature prevTof = (TypeOrFeature) mergedInputs.get(name);
if (prevTof != null) {
// choose next or prev, if it's 'type'
if (prevTof.isType()) {
// leave more general one
if (!prevTof.isAllAnnotatorFeatures() && nextTof.isAllAnnotatorFeatures())
mergedInputs.put(name, nextTof);
}
} else
// add next ToF
mergedInputs.put(name, nextTof);
}
// add/merge outputs in Hashtable
for (int i = 0; i < entryOuts.length; i++) {
TypeOrFeature nextTof = entryOuts[i];
String name = nextTof.getName();
TypeOrFeature prevTof = (TypeOrFeature) mergedOutputs.get(name);
if (prevTof != null) {
// choose next or prev, if it's 'type'
if (prevTof.isType()) {
// leave more general one
if (!prevTof.isAllAnnotatorFeatures() && nextTof.isAllAnnotatorFeatures())
mergedOutputs.put(name, nextTof);
}
} else
// add next ToF
mergedOutputs.put(name, nextTof);
}
}
// create merged Capability object and add merged inputs/outputs
Capability mergedCapability = rsFactory.createCapability();
// add merged inputs
Enumeration inpsList = mergedInputs.keys();
while (inpsList.hasMoreElements()) {
String name = (String) inpsList.nextElement();
TypeOrFeature tof = (TypeOrFeature) mergedInputs.get(name);
if (tof.isType())
mergedCapability.addInputType(name, tof.isAllAnnotatorFeatures());
else
mergedCapability.addInputFeature(name);
}
// add merged outputs
Enumeration outsList = mergedOutputs.keys();
while (outsList.hasMoreElements()) {
String name = (String) outsList.nextElement();
TypeOrFeature tof = (TypeOrFeature) mergedOutputs.get(name);
if (tof.isType())
mergedCapability.addOutputType(name, tof.isAllAnnotatorFeatures());
else
mergedCapability.addOutputFeature(name);
}
// put merged Capability in the array
Capability[] mergedArray = new Capability[1];
mergedArray[0] = mergedCapability;
return mergedArray;