recovery of identical dataset sequence object on undo (rather than creation of a...
[jalview.git] / src / jalview / commands / EditCommand.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer
3  * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.commands;
20
21 import java.util.*;
22
23 import jalview.datamodel.*;
24
25 /**
26  *
27  * <p>Title: EditCommmand</p>
28  *
29  * <p>Description: Essential information for performing
30  * undo and redo for cut/paste insert/delete gap
31  * which can be stored in the HistoryList </p>
32  *
33  * <p>Copyright: Copyright (c) 2006</p>
34  *
35  * <p>Company: Dundee University</p>
36  *
37  * @author not attributable
38  * @version 1.0
39  */
40 public class EditCommand
41     implements CommandI
42 {
43   public static final int INSERT_GAP = 0;
44   public static final int DELETE_GAP = 1;
45   public static final int CUT = 2;
46   public static final int PASTE = 3;
47   public static final int REPLACE = 4;
48
49   Edit[] edits;
50
51   String description;
52
53   public EditCommand()
54   {}
55
56   public EditCommand(String description)
57   {
58     this.description = description;
59   }
60
61   public EditCommand(String description,
62                      int command,
63                      SequenceI[] seqs,
64                      int position,
65                      int number,
66                      AlignmentI al)
67   {
68     this.description = description;
69     if (command == CUT || command == PASTE)
70     {
71       edits = new Edit[]
72           {
73           new Edit(command, seqs, position, number, al)};
74     }
75
76     performEdit(0, null);
77   }
78
79   public EditCommand(String description,
80                      int command,
81                      String replace,
82                      SequenceI[] seqs,
83                      int position,
84                      int number,
85                      AlignmentI al)
86   {
87     this.description = description;
88     if (command == REPLACE)
89     {
90       edits = new Edit[]
91           { new Edit(command, seqs, position, number, al, replace)};
92     }
93
94     performEdit(0, null);
95   }
96
97   final public String getDescription()
98   {
99     return description;
100   }
101
102   public int getSize()
103   {
104     return edits == null ? 0 : edits.length;
105   }
106
107   final public AlignmentI getAlignment()
108   {
109     return edits[0].al;
110   }
111
112   /**
113    * append a new editCommand
114    * Note. this shouldn't be called if the edit is an operation affects more alignment objects than the one referenced
115    * in al (for example, cut or pasting whole sequences). Use the form with an additional AlignmentI[] views parameter.
116    * @param command
117    * @param seqs
118    * @param position
119    * @param number
120    * @param al
121    * @param performEdit
122    */
123   final public void appendEdit(int command,
124           SequenceI[] seqs,
125           int position,
126           int number,
127           AlignmentI al,
128           boolean performEdit)
129   {
130     appendEdit(command, seqs, position, number, al, performEdit, null);
131   }
132   /**
133    * append a new edit command with a set of alignment views that may be operated on
134    * @param command
135    * @param seqs
136    * @param position
137    * @param number
138    * @param al
139    * @param performEdit
140    * @param views
141    */
142   final public void appendEdit(int command,
143                                SequenceI[] seqs,
144                                int position,
145                                int number,
146                                AlignmentI al,
147                                boolean performEdit, AlignmentI[] views)
148   {
149     Edit edit = new Edit(command, seqs, position, number, al.getGapCharacter());
150     if (al.getHeight() == seqs.length)
151     {
152       edit.al = al;
153       edit.fullAlignmentHeight = true;
154     }
155
156     if (edits != null)
157     {
158       Edit[] temp = new Edit[edits.length + 1];
159       System.arraycopy(edits, 0, temp, 0, edits.length);
160       edits = temp;
161       edits[edits.length - 1] = edit;
162     }
163     else
164     {
165       edits = new Edit[]
166           {
167           edit};
168     }
169
170     if (performEdit)
171     {
172       performEdit(edits.length - 1, views);
173     }
174   }
175
176   final void performEdit(int commandIndex, AlignmentI[] views)
177   {
178     int eSize = edits.length;
179     for (int e = commandIndex; e < eSize; e++)
180     {
181       switch(edits[e].command)
182       {
183         case INSERT_GAP:
184         insertGap(edits[e]);
185           break;
186         case DELETE_GAP:
187         deleteGap(edits[e]);
188           break;
189         case CUT:
190         cut(edits[e], views);
191           break;
192         case PASTE:
193         paste(edits[e], views);
194           break;
195         case REPLACE:
196           replace(edits[e]);
197           break;
198       }
199     }
200   }
201
202   final public void doCommand(AlignmentI[] views)
203   {
204     performEdit(0,views);
205   }
206
207   final public void undoCommand(AlignmentI[] views)
208   {
209     int e = 0, eSize = edits.length;
210     for (e = eSize - 1; e > -1; e--)
211     {
212       switch (edits[e].command)
213       {
214         case INSERT_GAP:
215         deleteGap(edits[e]);
216           break;
217         case DELETE_GAP:
218         insertGap(edits[e]);
219           break;
220         case CUT:
221         paste(edits[e], views);
222           break;
223         case PASTE:
224         cut(edits[e], views);
225           break;
226         case REPLACE:
227           replace(edits[e]);
228           break;
229       }
230     }
231   }
232
233   final void insertGap(Edit command)
234   {
235
236     for (int s = 0; s < command.seqs.length; s++)
237     {
238       command.seqs[s].insertCharAt(command.position,
239                                    command.number,
240                                    command.gapChar);
241     }
242
243     adjustAnnotations(command, true, false, null);
244   }
245
246   final void deleteGap(Edit command)
247   {
248     for (int s = 0; s < command.seqs.length; s++)
249     {
250       command.seqs[s].deleteChars(command.position,
251                                   command.position + command.number);
252     }
253
254     adjustAnnotations(command, false, false, null);
255   }
256
257   void cut(Edit command, AlignmentI[] views)
258   {
259     boolean seqDeleted=false;
260     command.string = new char[command.seqs.length][];
261
262     for (int i = 0; i < command.seqs.length; i++)
263     {
264       if (command.seqs[i].getLength() > command.position)
265       {
266         command.string[i] = command.seqs[i].getSequence(command.position,
267             command.position + command.number);
268         SequenceI oldds = command.seqs[i].getDatasetSequence();
269         if (command.oldds!=null && command.oldds[i]!=null)
270         {
271           // we are redoing an undone cut.
272           command.seqs[i].setDatasetSequence(null);
273         }
274         command.seqs[i].deleteChars(command.position,
275                 command.position + command.number);
276         if (command.oldds!=null && command.oldds[i]!=null)
277         {
278           // oldds entry contains the cut dataset sequence.
279           command.seqs[i].setDatasetSequence(command.oldds[i]);
280           command.oldds[i] = oldds;
281         } else {
282           // modify the oldds if necessary
283           if (oldds!=command.seqs[i].getDatasetSequence()
284             || command.seqs[i].getSequenceFeatures() != null)
285           {
286             if (command.oldds==null)
287             {
288               command.oldds = new SequenceI[command.seqs.length];
289             }
290             command.oldds[i] = oldds;
291             adjustFeatures(command, i,
292                     command.seqs[i].findPosition(command.position),
293                     command.seqs[i].findPosition(command.position +
294                             command.number),
295                             false);
296           }
297         }
298       }
299
300       if (command.seqs[i].getLength() < 1)
301       {
302         command.al.deleteSequence(command.seqs[i]);
303         seqDeleted=true;
304       }
305     }
306
307     adjustAnnotations(command, false, seqDeleted, views);
308   }
309
310   void paste(Edit command, AlignmentI[] views)
311   {
312     StringBuffer tmp;
313     boolean newDSNeeded;
314     boolean newDSWasNeeded;
315     int newstart,newend;
316     boolean seqWasDeleted=false;
317     int start = 0, end = 0;
318
319     for (int i = 0; i < command.seqs.length; i++)
320     {
321       newDSNeeded = false;
322       newDSWasNeeded = command.oldds!=null && command.oldds[i]!=null;
323       if (command.seqs[i].getLength() < 1)
324       {
325         // ie this sequence was deleted, we need to
326         // read it to the alignment
327         if (command.alIndex[i] < command.al.getHeight())
328         {
329           command.al.getSequences().insertElementAt(command.seqs[i],
330               command.alIndex[i]);
331         }
332         else
333         {
334           command.al.addSequence(command.seqs[i]);
335         }
336         seqWasDeleted=true;
337       }
338       newstart = command.seqs[i].getStart();
339       newend = command.seqs[i].getEnd();
340
341       tmp = new StringBuffer();
342       tmp.append(command.seqs[i].getSequence());
343       //Undo of a delete does not replace original dataset sequence on to alignment sequence.
344       
345       if (command.string != null && command.string[i] != null)
346       {
347         if (command.position >= tmp.length())
348         {
349           //This occurs if padding is on, and residues
350           //are removed from end of alignment
351           int length = command.position - tmp.length();
352           while (length > 0)
353           {
354             tmp.append(command.gapChar);
355             length--;
356           }
357         }
358         tmp.insert(command.position, command.string[i]);
359         for (int s = 0; s < command.string[i].length; s++)
360         {
361           if (jalview.schemes.ResidueProperties.aaIndex[command.string[i][s]] !=
362               23)
363           {
364             if (!newDSNeeded)
365             {
366               newDSNeeded = true;
367               start = command.seqs[i].findPosition(command.position);
368               end = command.seqs[i].findPosition(command.position +
369                                                command.number);
370             }
371             if (command.seqs[i].getStart()==start)
372               newstart--;
373             else
374               newend++;
375           }
376         }
377         command.string[i] = null;
378       }
379
380       command.seqs[i].setSequence(tmp.toString());
381       command.seqs[i].setStart(newstart);
382       command.seqs[i].setEnd(newend);
383       if (newDSNeeded)
384       {
385         if (command.seqs[i].getDatasetSequence() != null)
386         { 
387           SequenceI ds;
388           if (newDSWasNeeded)
389           {
390             ds = command.oldds[i];
391           } else {
392             // make a new DS sequence
393             // use new ds mechanism here
394             ds= new Sequence(command.seqs[i].getName(),
395                                      jalview.analysis.AlignSeq.extractGaps(
396                                          jalview.util.Comparison.GapChars,
397                                          command.seqs[i].getSequenceAsString()
398                                      ),
399                                      command.seqs[i].getStart(),
400                                      command.seqs[i].getEnd());
401             ds.setDescription(command.seqs[i].getDescription());
402           }
403           if (command.oldds==null)
404           {
405             command.oldds = new SequenceI[command.seqs.length];
406           }
407           command.oldds[i]=command.seqs[i].getDatasetSequence();
408           command.seqs[i].setDatasetSequence(ds);
409         }
410         adjustFeatures(command, i, start, end, true);
411       }
412     }
413     adjustAnnotations(command, true, seqWasDeleted, views);
414
415     command.string = null;
416   }
417
418   void replace(Edit command)
419   {
420     StringBuffer tmp;
421     String oldstring;
422     int start = command.position;
423     int end = command.number;
424
425     command.number = start + command.string[0].length;
426     for (int i = 0; i < command.seqs.length; i++)
427     {
428       oldstring = command.seqs[i].getSequenceAsString();
429       tmp = new StringBuffer(oldstring.substring(0, start));
430       tmp.append(command.string[i]);
431       tmp.append(oldstring.substring(end));
432       command.seqs[i].setSequence(tmp.toString());
433       command.string[i] = oldstring.substring(start, end).toCharArray();
434       tmp = null;
435       oldstring = null;
436     }
437   }
438
439   final void adjustAnnotations(Edit command, boolean insert, boolean modifyVisibility, AlignmentI[] views)
440   {
441     AlignmentAnnotation[] annotations = null;
442
443     if (modifyVisibility && !insert)
444     {
445       // only occurs if a sequence was added or deleted.
446       command.deletedAnnotationRows = new Hashtable();
447     }
448     if (command.fullAlignmentHeight)
449     {
450       annotations = command.al.getAlignmentAnnotation();
451     }
452     else
453     {
454       int aSize = 0;
455       AlignmentAnnotation[] tmp;
456       for (int s = 0; s < command.seqs.length; s++)
457       {
458         if (modifyVisibility)
459         {
460           // Rows are only removed or added to sequence object.
461           if (!insert) {
462             // remove rows
463             tmp = command.seqs[s].getAnnotation();
464             if (tmp!=null) {
465               int alen=tmp.length;
466               for (int aa =0; aa<tmp.length; aa++)
467               {
468                 if (!command.al.deleteAnnotation(tmp[aa]))
469                 {
470                   // strip out annotation not in the current al (will be put back on insert in all views)
471                   tmp[aa] = null;
472                   alen--;
473                 }
474               }
475               command.seqs[s].setAlignmentAnnotation(null);
476               if (alen!=tmp.length)
477               {
478                 // save the non-null annotation references only
479                 AlignmentAnnotation[] saved = new AlignmentAnnotation[alen];
480                 for (int aa=0,aapos=0;aa<tmp.length;aa++)
481                 {
482                   if (tmp[aa]!=null)
483                   {
484                     saved[aapos++] = tmp[aa];
485                     tmp[aa] = null;
486                   }
487                 }
488                 tmp = saved;
489                 command.deletedAnnotationRows.put(command.seqs[s], saved);
490                 // and then remove any annotation in the other views
491                 for (int alview=0; views!=null && alview<views.length; alview++)
492                 {
493                   if (views[alview]!=command.al)
494                   {
495                     AlignmentAnnotation[] toremove = views[alview].getAlignmentAnnotation();
496                     if (toremove==null || toremove.length==0)
497                     {
498                       continue;
499                     }
500                     // remove any alignment annotation on this sequence that's on that alignment view.
501                     for (int aa = 0; aa<toremove.length; aa++)
502                     {
503                       if (toremove[aa].sequenceRef==command.seqs[s])
504                       {
505                         views[alview].deleteAnnotation(toremove[aa]);
506                       }
507                     }
508                   }
509                 }
510               } else {
511                 // save all the annotation
512                 command.deletedAnnotationRows.put(command.seqs[s], tmp);
513               }
514             }
515           } else {
516             // recover rows
517             if (command.deletedAnnotationRows!=null && command.deletedAnnotationRows.containsKey(command.seqs[s]))
518             {
519               AlignmentAnnotation[] revealed = (AlignmentAnnotation[]) command.deletedAnnotationRows.get(command.seqs[s]);
520               command.seqs[s].setAlignmentAnnotation(revealed);
521               if (revealed!=null) {
522                 for (int aa =0; aa<revealed.length; aa++)
523                 {
524                   // iterate through al adding original annotation
525                   command.al.addAnnotation(revealed[aa]);
526                 }
527                 for (int aa =0; aa<revealed.length; aa++)
528                 {
529                   command.al.setAnnotationIndex(revealed[aa], aa);
530                 }
531                 // and then duplicate added annotation on every other alignment view
532                 for (int vnum=0; views!=null && vnum<views.length; vnum++)
533                 {
534                   if (views[vnum]!=command.al)
535                   {
536                     int avwidth = views[vnum].getWidth()+1;
537                     // duplicate in this view
538                     for (int a=0; a<revealed.length; a++)
539                     {
540                       AlignmentAnnotation newann = new AlignmentAnnotation(revealed[a]);
541                       command.seqs[s].addAlignmentAnnotation(newann);
542                       newann.padAnnotation(avwidth);
543                       views[vnum].addAnnotation(newann);
544                       views[vnum].setAnnotationIndex(newann, a);
545                     }
546                   }
547                 }
548               }
549             }
550           }
551           continue;
552         }
553
554         if (command.seqs[s].getAnnotation() == null)
555         {
556           continue;
557         }
558
559         if (aSize == 0)
560         {
561           annotations = command.seqs[s].getAnnotation();
562         }
563         else
564         {
565           tmp = new AlignmentAnnotation
566               [aSize + command.seqs[s].getAnnotation().length];
567
568           System.arraycopy(annotations, 0, tmp, 0, aSize);
569
570           System.arraycopy(command.seqs[s].getAnnotation(),
571                            0, tmp, aSize,
572                            command.seqs[s].getAnnotation().length);
573
574           annotations = tmp;
575         }
576         aSize = annotations.length;
577       }
578     }
579
580     if (annotations == null)
581     {
582       return;
583     }
584
585     if (!insert)
586     {
587       command.deletedAnnotations = new Hashtable();
588     }
589
590     int aSize;
591     Annotation[] temp;
592     for (int a = 0; a < annotations.length; a++)
593     {
594       if (annotations[a].autoCalculated || annotations[a].annotations == null)
595       {
596         continue;
597       }
598
599       int tSize = 0;
600
601       aSize = annotations[a].annotations.length;
602       if (insert)
603       {
604         temp = new Annotation[aSize + command.number];
605         if(annotations[a].padGaps)
606           for (int aa = 0; aa < temp.length; aa++)
607           {
608             temp[aa] = new Annotation(
609                 command.gapChar+"",
610                 null, ' ', 0);
611           }
612       }
613       else
614       {
615         if (command.position < aSize)
616         {
617           if (command.position + command.number >= aSize)
618           {
619             tSize = aSize;
620           }
621           else
622           {
623             tSize = aSize - command.number;
624           }
625         }
626         else
627         {
628           tSize = aSize;
629         }
630
631         if (tSize < 0)
632         {
633           tSize = aSize;
634         }
635         temp = new Annotation[tSize];
636       }
637
638
639       if (insert)
640       {
641         if (command.position < annotations[a].annotations.length)
642         {
643           System.arraycopy(annotations[a].annotations,
644                            0, temp, 0, command.position);
645
646           if (command.deletedAnnotations != null
647               &&
648               command.deletedAnnotations.containsKey(annotations[a].
649               annotationId))
650           {
651             Annotation[] restore = (Annotation[])
652                 command.deletedAnnotations.get(annotations[a].annotationId);
653
654             System.arraycopy(restore,
655                              0,
656                              temp,
657                              command.position,
658                              command.number);
659
660           }
661
662           System.arraycopy(annotations[a].annotations,
663                            command.position, temp,
664                            command.position + command.number,
665                            aSize - command.position);
666         }
667         else
668         {
669           if (command.deletedAnnotations != null
670               &&
671               command.deletedAnnotations.containsKey(annotations[a].
672               annotationId))
673           {
674             Annotation[] restore = (Annotation[])
675                 command.deletedAnnotations.get(annotations[a].annotationId);
676
677             temp = new Annotation[annotations[a].annotations.length +
678                 restore.length];
679             System.arraycopy(annotations[a].annotations,
680                              0, temp, 0,
681                              annotations[a].annotations.length);
682             System.arraycopy(restore, 0, temp,
683                              annotations[a].annotations.length, restore.length);
684           }
685           else
686           {
687             temp = annotations[a].annotations;
688           }
689         }
690       }
691       else
692       {
693         if (tSize != aSize || command.position < 2)
694         {
695           int copylen = Math.min(command.position, annotations[a].annotations.length);
696           if (copylen>0)
697             System.arraycopy(annotations[a].annotations,
698                            0, temp, 0, copylen); //command.position);
699
700           Annotation[] deleted = new Annotation[command.number];
701           if (copylen>=command.position) {
702             copylen = Math.min(command.number, annotations[a].annotations.length-command.position);
703             if (copylen>0)
704             {
705               System.arraycopy(annotations[a].annotations,
706                       command.position, deleted, 0, copylen); // command.number);
707             }
708           }
709
710           command.deletedAnnotations.put(annotations[a].annotationId,
711                                          deleted);
712           if (annotations[a].annotations.length>command.position+command.number) {
713             System.arraycopy(annotations[a].annotations,
714                            command.position + command.number,
715                            temp, command.position,
716                            annotations[a].annotations.length - command.position - command.number); // aSize
717           }
718         }
719         else
720         {
721           int dSize = aSize - command.position;
722
723           if (dSize > 0)
724           {
725             Annotation[] deleted = new Annotation[command.number];
726             System.arraycopy(annotations[a].annotations,
727                              command.position, deleted, 0, dSize);
728
729             command.deletedAnnotations.put(annotations[a].annotationId,
730                                            deleted);
731
732             tSize = Math.min(annotations[a].annotations.length,
733                              command.position);
734             temp = new Annotation[tSize];
735             System.arraycopy(annotations[a].annotations,
736                              0, temp, 0, tSize);
737           }
738           else
739           {
740             temp = annotations[a].annotations;
741           }
742         }
743       }
744
745       annotations[a].annotations = temp;
746     }
747   }
748
749   final void adjustFeatures(Edit command, int index, int i, int j,
750                             boolean insert)
751   {
752     SequenceI seq = command.seqs[index];
753     SequenceI sequence = seq.getDatasetSequence();
754     if (sequence == null)
755     {
756       sequence = seq;
757     }
758
759     if (insert)
760     {
761       if (command.editedFeatures != null
762           && command.editedFeatures.containsKey(seq))
763       {
764         sequence.setSequenceFeatures(
765             (SequenceFeature[]) command.editedFeatures.get(seq)
766             );
767       }
768
769       return;
770     }
771
772     SequenceFeature[] sf = sequence.getSequenceFeatures();
773
774     if (sf == null)
775     {
776       return;
777     }
778
779     SequenceFeature[] oldsf = new SequenceFeature[sf.length];
780
781     int cSize = j - i;
782
783     for (int s = 0; s < sf.length; s++)
784     {
785       SequenceFeature copy = new SequenceFeature(sf[s]);
786
787       oldsf[s] = copy;
788
789       if (sf[s].getEnd() < i)
790       {
791         continue;
792       }
793
794       if (sf[s].getBegin() > j)
795       {
796         sf[s].setBegin(copy.getBegin() - cSize);
797         sf[s].setEnd(copy.getEnd() - cSize);
798         continue;
799       }
800
801       if (sf[s].getBegin() >= i)
802       {
803         sf[s].setBegin(i);
804       }
805
806       if (sf[s].getEnd() < j)
807       {
808         sf[s].setEnd(j - 1);
809       }
810
811       sf[s].setEnd(sf[s].getEnd() - (cSize));
812
813       if (sf[s].getBegin() > sf[s].getEnd())
814       {
815         sequence.deleteFeature(sf[s]);
816       }
817     }
818
819     if (command.editedFeatures == null)
820     {
821       command.editedFeatures = new Hashtable();
822     }
823
824     command.editedFeatures.put(seq, oldsf);
825
826   }
827
828   class Edit
829   {
830     public SequenceI[] oldds;
831     boolean fullAlignmentHeight = false;
832     Hashtable deletedAnnotationRows;
833     Hashtable deletedAnnotations;
834     Hashtable editedFeatures;
835     AlignmentI al;
836     int command;
837     char[][] string;
838     SequenceI[] seqs;
839     int[] alIndex;
840     int position, number;
841     char gapChar;
842
843     Edit(int command,
844          SequenceI[] seqs,
845          int position,
846          int number,
847          char gapChar)
848     {
849       this.command = command;
850       this.seqs = seqs;
851       this.position = position;
852       this.number = number;
853       this.gapChar = gapChar;
854     }
855
856     Edit(int command,
857          SequenceI[] seqs,
858          int position,
859          int number,
860          AlignmentI al)
861     {
862       this.gapChar = al.getGapCharacter();
863       this.command = command;
864       this.seqs = seqs;
865       this.position = position;
866       this.number = number;
867       this.al = al;
868
869       alIndex = new int[seqs.length];
870       for (int i = 0; i < seqs.length; i++)
871       {
872         alIndex[i] = al.findIndex(seqs[i]);
873       }
874
875       fullAlignmentHeight = (al.getHeight() == seqs.length);
876     }
877
878     Edit(int command,
879          SequenceI[] seqs,
880          int position,
881          int number,
882          AlignmentI al,
883          String replace)
884     {
885       this.command = command;
886       this.seqs = seqs;
887       this.position = position;
888       this.number = number;
889       this.al = al;
890       this.gapChar = al.getGapCharacter();
891       string = new char[seqs.length][];
892       for (int i = 0; i < seqs.length; i++)
893       {
894         string[i] = replace.toCharArray();
895       }
896
897       fullAlignmentHeight = (al.getHeight() == seqs.length);
898     }
899   }
900 }