StringBuffer rowSymbols = symbolBufs.get(rowIndex);
// convert the mesquite character state to treebase state:
long statesLong = categoricalData.getState(pColIndex, rowIndex);
DiscreteMatrixElementJDBC element = new DiscreteMatrixElementJDBC();
if (categoricalData.isInapplicable(pColIndex, rowIndex)) {
// gap:
element.setGap((short) 1);
// symbol = pGapSymbol;
rowSymbols.append(pGapSymbol);
} else if (!categoricalData.isUnassigned(pColIndex, rowIndex)) {
// not missing :
// element = new DiscreteMatrixElementJDBC();
int[] states = CategoricalState.expand(statesLong);
if (states.length > 1) {
// multiple states, create a compound element.
// The original single element "element" is still used as a place holder.
CompoundElementJDBC compoundElement = new CompoundElementJDBC();
addDiscreteStateIds(
states,
pColIndex,
categoricalData,
rowSymbols,
stateSymbolToIdMap,
compoundElement);
compoundElement.setColIndex(pColIndex);
compoundElement.setRowIndex(rowIndex);
pMatrixJDBC.getCompoundElements().add(compoundElement);
} else { // XXX: Can the number of states be 0? If so, we need a guard condition here 20090121 MJD
// single state, use single element:
//String stateName = categoricalData.getStateName(pColIndex, states[0]);
char aSymbol = categoricalData.getSymbol(states[0]);
rowSymbols.append(aSymbol);
findDiscreteStateId(
stateSymbolToIdMap,
aSymbol,
pGapSymbol,
pMissingSymbol,
element);
}
} else {
rowSymbols.append(pMissingSymbol);
}
element.setElementOrder(pColIndex);
element.setMatrixRowID(rowIds[rowIndex]);
element.setMatrixColID(pColId);
pElements.add(element);
}
}