| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evolution.datatype; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class TwoStates extends DataType { |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public static final String DESCRIPTION = "binary"; |
| 42 |
public static final int TYPE = TWO_STATES; |
| 43 |
public static final TwoStates INSTANCE = new TwoStates(); |
| 44 |
|
| 45 |
public static final int ZERO_STATE = 0; |
| 46 |
public static final int ONE_STATE = 1; |
| 47 |
|
| 48 |
public static final int UNKNOWN_STATE = 2; |
| 49 |
public static final int GAP_STATE = 3; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static final char[] TWOSTATE_CHARS = |
| 55 |
{ '0','1', UNKNOWN_CHARACTER,GAP_CHARACTER}; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public static final String[] TWOSTATE_AMBIGUITIES = { |
| 61 |
|
| 62 |
"0", "1", "01", "01" |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
private TwoStates() { |
| 69 |
stateCount = 2; |
| 70 |
ambiguousStateCount = 4; |
| 71 |
} |
| 72 |
|
| 73 |
@Override |
| 74 |
public char[] getValidChars() { |
| 75 |
return TWOSTATE_CHARS; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public int getState(char c) |
| 80 |
{ |
| 81 |
switch (c) |
| 82 |
{ |
| 83 |
case '0': |
| 84 |
return 0; |
| 85 |
case '1': |
| 86 |
return 1; |
| 87 |
case UNKNOWN_CHARACTER: |
| 88 |
return 2; |
| 89 |
case GAP_CHARACTER: |
| 90 |
return 3; |
| 91 |
default: |
| 92 |
return 2; |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public char getChar(int state) { |
| 104 |
return TWOSTATE_CHARS[state]; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public int[] getStates(int state) { |
| 112 |
|
| 113 |
String stateString = TWOSTATE_AMBIGUITIES[state]; |
| 114 |
int[] states = new int[stateString.length()]; |
| 115 |
for (int i = 0; i < stateString.length(); i++) { |
| 116 |
states[i] = getState(stateString.charAt(i)); |
| 117 |
} |
| 118 |
|
| 119 |
return states; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public boolean[] getStateSet(int state) { |
| 126 |
|
| 127 |
boolean[] stateSet = new boolean[stateCount]; |
| 128 |
if (state < 2) { |
| 129 |
stateSet[1-state] = false; |
| 130 |
stateSet[state] = true; |
| 131 |
} else { |
| 132 |
stateSet[0] = true; |
| 133 |
stateSet[1] = true; |
| 134 |
} |
| 135 |
|
| 136 |
return stateSet; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public String getDescription() { |
| 145 |
return DESCRIPTION; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
public int getType() { |
| 154 |
return TYPE; |
| 155 |
} |
| 156 |
|
| 157 |
} |