| 227 | } |
| 228 | |
| 229 | public void apply(Map<Trie,TextFile> state) { |
| 230 | if (kind == Kind.REMOVE && state.containsKey(filename)) { |
| 231 | // Easy case |
| 232 | state.remove(filename); |
| 233 | } else if (kind == Kind.REMOVE) { |
| 234 | throw new IllegalArgumentException("Invalid remove action"); |
| 235 | } else if(state.containsKey(filename)) { |
| 236 | TextFile tf = state.get(filename); |
| 237 | state.put(filename, tf.replace(range.start, range.end, lines)); |
| 238 | } else if(range == null){ |
| 239 | // Create entirely new file. |
| 240 | state.put(filename, new TextFile(lines)); |
| 241 | } else { |
| 242 | throw new IllegalArgumentException("Invalid insert action"); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | @Override |
| 247 | public String toString() { |