|
6 | 6 | import java.util.Map; |
7 | 7 |
|
8 | 8 | import org.nexml.model.Character; |
| 9 | +import org.nexml.model.CharacterState; |
9 | 10 | import org.nexml.model.MatrixCell; |
10 | 11 | import org.nexml.model.MatrixRow; |
11 | 12 | import org.w3c.dom.Document; |
@@ -55,15 +56,27 @@ protected MatrixRowImpl(Document document,MatrixImpl<T> matrix) { |
55 | 56 | * the <otus/> element) |
56 | 57 | * @author rvosa |
57 | 58 | */ |
58 | | - protected MatrixRowImpl(Document document, Element element) { |
| 59 | + protected MatrixRowImpl(Document document, Element element, MatrixImpl<T> matrix, boolean continuous) { |
59 | 60 | super(document, element); |
| 61 | + mMatrix = matrix; |
60 | 62 | List<Element> seqElements = getChildrenByTagName(element, "seq"); |
61 | 63 | if ( ! seqElements.isEmpty() ) { |
62 | 64 | mSeqElement = seqElements.get(0); |
63 | 65 | } |
64 | 66 | List<Element> cellElements = getChildrenByTagName(element, "cell"); |
65 | 67 | for ( Element cellElement : cellElements ) { |
| 68 | + Character character = findCharacter(cellElement.getAttribute("char")); |
| 69 | + Object value; |
| 70 | + if (continuous) { |
| 71 | + value = Double.parseDouble(cellElement.getAttribute("state")); |
| 72 | + |
| 73 | + } else { |
| 74 | + value = findState(cellElement.getAttribute("state"), character); |
| 75 | + } |
| 76 | + mStateForCharacter.put(character, (T)value); |
66 | 77 | MatrixCellImpl<T> cell = new MatrixCellImpl<T>(getDocument(),cellElement); |
| 78 | + cell.setValue((T)value); |
| 79 | + mCellForCharacter.put(character, cell); |
67 | 80 | mMatrixCell.add(cell); |
68 | 81 | } |
69 | 82 | } |
@@ -195,5 +208,23 @@ public String getSeq() { |
195 | 208 | private MatrixImpl<T> getMatrix() { |
196 | 209 | return mMatrix; |
197 | 210 | } |
| 211 | + |
| 212 | + private Character findCharacter(String id) { |
| 213 | + for (Character character : getMatrix().getCharacters()) { |
| 214 | + if (character.getId().equals(id)) { |
| 215 | + return character; |
| 216 | + } |
| 217 | + } |
| 218 | + return null; |
| 219 | + } |
| 220 | + |
| 221 | + private CharacterState findState(String id, Character character) { |
| 222 | + for (CharacterState state : character.getCharacterStateSet().getCharacterStates()) { |
| 223 | + if (state.getId().equals(id)) { |
| 224 | + return state; |
| 225 | + } |
| 226 | + } |
| 227 | + return null; |
| 228 | + } |
198 | 229 |
|
199 | 230 | } |
0 commit comments