- * @param pos int -1, 0-length of visible region, or greater to append new ops (with insertions in between)\r
- * @param op char\r
- * @param range int\r
- public void addOperationAt(int pos, char op, int range)\r
- {\r
- int cursor = -1; // mark the position for the current operation being edited.\r
- int o = 0;\r
- boolean last_d = false; // previous op was a deletion.\r
- if (pos < -1)\r
- throw new Error("pos<-1 is not supported.");\r
- while (o<length) {\r
- if (operation[o] != D)\r
- {\r
- if ( (cursor + this.range[o]) < pos)\r
- {\r
- cursor += this.range[o];\r
- o++;\r
- last_d=false;\r
- }\r
- else\r
- {\r
- break;\r
- }\r
- }\r
- else {\r
- last_d=true;\r
- o++;\r
- }\r
- }\r
- if (o==length) {\r
- // must insert more operations before pos\r
- if (pos-cursor>0)\r
- addInsertion(pos-cursor);\r
- // then just add the new operation. Regardless of what it is.\r
- addOperation(op, range);\r
- } else {\r
- int diff = pos - cursor;\r
-\r
- int e_length = length-o; // new edit operation array length.\r
- // diff<0 - can only happen before first insertion or match. - affects op and all following\r
- // dif==0 - only when at first position of existing op -\r
- // diff>0 - must preserve some existing operations\r
- int[] e_range = new int[e_length];\r
- System.arraycopy(this.range, o, e_range, 0, e_length);\r
- char[] e_op = new char[e_length];\r
- System.arraycopy(this.operation, o, e_op, 0, e_length);\r
- length = o; // can now use add_operation to extend list.\r
- int e_o=0; // current operation being edited.\r
- switch (op) {\r
- case M:\r
- switch (e_op[e_o])\r
- {\r
- case M:\r
- if (last_d && diff <= 0)\r
- {\r
- // reduce D's, if possible\r
- if (range<=this.range[o-1]) {\r
- this.range[o - 1] -= range;\r
- } else {\r
- this.range[o-1]=0;\r
- }\r
- if (this.range[o-1]==0)\r
- o--; // lose this op.\r
- }\r
- e_range[e_o] += range; // just add more matched residues\r
- break;\r
- case I:\r
- // change from insertion to match\r
- if (last_d && diff<=0)\r
- {\r
- // reduce D's, if possible\r
- if (range<=this.range[o-1]) {\r
- this.range[o - 1] -= range;\r
- } else {\r
- this.range[o-1]=0;\r
- }\r
- if (this.range[o-1]==0)\r
- o--; // lose this op.\r
- }\r
- e_range[e_o]\r
- break;\r
- default:\r
- throw new Inp\r
- }\r
-\r
- break;\r
- case I:\r
- break;\r
- case D:\r
- }\r
- break;\r
- default:\r
- throw new Error("Implementation Error: Unknown operation in addOperation!");\r
- }\r
- // finally, add remaining ops.\r
- while (e_o<e_length) {\r
- addOperation(e_op[e_o], e_range[e_o]);\r
- e_o++;\r
- }\r
- }\r
- }\r
-**/\r
+ * \r
+ * @param pos\r
+ * int -1, 0-length of visible region, or greater to append new ops\r
+ * (with insertions in between)\r
+ * @param op\r
+ * char\r
+ * @param range\r
+ * int public void addOperationAt(int pos, char op, int range) { int\r
+ * cursor = -1; // mark the position for the current operation being\r
+ * edited. int o = 0; boolean last_d = false; // previous op was a\r
+ * deletion. if (pos < -1) throw new\r
+ * Error("pos<-1 is not supported."); while (o<length) { if\r
+ * (operation[o] != D) { if ( (cursor + this.range[o]) < pos) {\r
+ * cursor += this.range[o]; o++; last_d=false; } else { break; } }\r
+ * else { last_d=true; o++; } } if (o==length) { // must insert more\r
+ * operations before pos if (pos-cursor>0) addInsertion(pos-cursor);\r
+ * // then just add the new operation. Regardless of what it is.\r
+ * addOperation(op, range); } else { int diff = pos - cursor;\r
+ * \r
+ * int e_length = length-o; // new edit operation array length. //\r
+ * diff<0 - can only happen before first insertion or match. -\r
+ * affects op and all following // dif==0 - only when at first\r
+ * position of existing op - // diff>0 - must preserve some existing\r
+ * operations int[] e_range = new int[e_length];\r
+ * System.arraycopy(this.range, o, e_range, 0, e_length); char[] e_op\r
+ * = new char[e_length]; System.arraycopy(this.operation, o, e_op, 0,\r
+ * e_length); length = o; // can now use add_operation to extend\r
+ * list. int e_o=0; // current operation being edited. switch (op) {\r
+ * case M: switch (e_op[e_o]) { case M: if (last_d && diff <= 0) { //\r
+ * reduce D's, if possible if (range<=this.range[o-1]) { this.range[o\r
+ * - 1] -= range; } else { this.range[o-1]=0; } if\r
+ * (this.range[o-1]==0) o--; // lose this op. } e_range[e_o] +=\r
+ * range; // just add more matched residues break; case I: // change\r
+ * from insertion to match if (last_d && diff<=0) { // reduce D's, if\r
+ * possible if (range<=this.range[o-1]) { this.range[o - 1] -= range;\r
+ * } else { this.range[o-1]=0; } if (this.range[o-1]==0) o--; // lose\r
+ * this op. } e_range[e_o] break; default: throw new Inp }\r
+ * \r
+ * break; case I: break; case D: } break; default: throw new\r
+ * Error("Implementation Error: Unknown operation in addOperation!");\r
+ * } // finally, add remaining ops. while (e_o<e_length) {\r
+ * addOperation(e_op[e_o], e_range[e_o]); e_o++; } } }\r
+ */\r