JAL-2745 update www.ebi.ac.uk to https
[jalview.git] / src / jalview / commands / EditCommand.java
index 2d3a8d8..d319249 100644 (file)
@@ -222,14 +222,16 @@ public class EditCommand implements CommandI
     /**
      * Check a contiguous edit; either
      * <ul>
-     * <li>a new Insert <n> positions to the right of the last <insert n>, or</li>
+     * <li>a new Insert <n> positions to the right of the last <insert n>,
+     * or</li>
      * <li>a new Delete <n> gaps which is <n> positions to the left of the last
      * delete.</li>
      * </ul>
      */
-    boolean contiguous = (action == Action.INSERT_GAP && e.position == lastEdit.position
-            + lastEdit.number)
-            || (action == Action.DELETE_GAP && e.position + e.number == lastEdit.position);
+    boolean contiguous = (action == Action.INSERT_GAP
+            && e.position == lastEdit.position + lastEdit.number)
+            || (action == Action.DELETE_GAP
+                    && e.position + e.number == lastEdit.position);
     if (contiguous)
     {
       /*
@@ -307,8 +309,7 @@ public class EditCommand implements CommandI
    * @param performEdit
    */
   final public void appendEdit(Action command, SequenceI[] seqs,
-          int position,
-          int number, AlignmentI al, boolean performEdit)
+          int position, int number, AlignmentI al, boolean performEdit)
   {
     appendEdit(command, seqs, position, number, al, performEdit, null);
   }
@@ -326,8 +327,8 @@ public class EditCommand implements CommandI
    * @param views
    */
   final public void appendEdit(Action command, SequenceI[] seqs,
-          int position,
-          int number, AlignmentI al, boolean performEdit, AlignmentI[] views)
+          int position, int number, AlignmentI al, boolean performEdit,
+          AlignmentI[] views)
   {
     Edit edit = new Edit(command, seqs, position, number,
             al.getGapCharacter());
@@ -432,7 +433,7 @@ public class EditCommand implements CommandI
    */
   @Override
   final public void undoCommand(AlignmentI[] views)
-  { 
+  {
     ListIterator<Edit> iterator = edits.listIterator(edits.size());
     while (iterator.hasPrevious())
     {
@@ -474,9 +475,10 @@ public class EditCommand implements CommandI
 
     for (int s = 0; s < command.seqs.length; s++)
     {
-      command.seqs[s].insertCharAt(command.position,
-              command.number, command.gapChar);
-      // System.out.println("pos: "+command.position+" number: "+command.number);
+      command.seqs[s].insertCharAt(command.position, command.number,
+              command.gapChar);
+      // System.out.println("pos: "+command.position+" number:
+      // "+command.number);
     }
 
     adjustAnnotations(command, true, false, null);
@@ -505,8 +507,8 @@ public class EditCommand implements CommandI
   {
     for (int s = 0; s < command.seqs.length; s++)
     {
-      command.seqs[s].deleteChars(command.position, command.position
-              + command.number);
+      command.seqs[s].deleteChars(command.position,
+              command.position + command.number);
     }
 
     adjustAnnotations(command, false, false, null);
@@ -537,8 +539,8 @@ public class EditCommand implements CommandI
           // we are redoing an undone cut.
           sequence.setDatasetSequence(null);
         }
-        sequence.deleteChars(command.position, command.position
-                + command.number);
+        sequence.deleteChars(command.position,
+                command.position + command.number);
         if (command.oldds != null && command.oldds[i] != null)
         {
           // oldds entry contains the cut dataset sequence.
@@ -556,12 +558,11 @@ public class EditCommand implements CommandI
               command.oldds = new SequenceI[command.seqs.length];
             }
             command.oldds[i] = oldds;
-            adjustFeatures(
-                    command,
-                    i,
+            adjustFeatures(command, i,
                     sequence.findPosition(command.position),
-                    sequence.findPosition(command.position
-                            + command.number), false);
+                    sequence.findPosition(
+                            command.position + command.number),
+                    false);
           }
         }
       }
@@ -647,8 +648,8 @@ public class EditCommand implements CommandI
             {
               newDSNeeded = true;
               start = command.seqs[i].findPosition(command.position);
-              end = command.seqs[i].findPosition(command.position
-                      + command.number);
+              end = command.seqs[i]
+                      .findPosition(command.position + command.number);
             }
             if (command.seqs[i].getStart() == start)
             {
@@ -732,16 +733,16 @@ public class EditCommand implements CommandI
       tmp = new StringBuffer(oldstring.substring(0, start));
       tmp.append(command.string[i]);
       String nogaprep = jalview.analysis.AlignSeq.extractGaps(
-              jalview.util.Comparison.GapChars, new String(
-                      command.string[i]));
+              jalview.util.Comparison.GapChars,
+              new String(command.string[i]));
       int ipos = command.seqs[i].findPosition(start)
               - command.seqs[i].getStart();
       tmp.append(oldstring.substring(end));
       command.seqs[i].setSequence(tmp.toString());
       command.string[i] = oldstring.substring(start, end).toCharArray();
       String nogapold = jalview.analysis.AlignSeq.extractGaps(
-              jalview.util.Comparison.GapChars, new String(
-                      command.string[i]));
+              jalview.util.Comparison.GapChars,
+              new String(command.string[i]));
       if (!nogaprep.toLowerCase().equals(nogapold.toLowerCase()))
       {
         if (newDSWasNeeded)
@@ -834,7 +835,8 @@ public class EditCommand implements CommandI
                 tmp = saved;
                 command.deletedAnnotationRows.put(command.seqs[s], saved);
                 // and then remove any annotation in the other views
-                for (int alview = 0; views != null && alview < views.length; alview++)
+                for (int alview = 0; views != null
+                        && alview < views.length; alview++)
                 {
                   if (views[alview] != command.al)
                   {
@@ -886,7 +888,8 @@ public class EditCommand implements CommandI
                 }
                 // and then duplicate added annotation on every other alignment
                 // view
-                for (int vnum = 0; views != null && vnum < views.length; vnum++)
+                for (int vnum = 0; views != null
+                        && vnum < views.length; vnum++)
                 {
                   if (views[vnum] != command.al)
                   {
@@ -1013,8 +1016,8 @@ public class EditCommand implements CommandI
           }
 
           System.arraycopy(annotations[a].annotations, command.position,
-                  temp, command.position + command.number, aSize
-                          - command.position);
+                  temp, command.position + command.number,
+                  aSize - command.position);
         }
         else
         {
@@ -1045,7 +1048,7 @@ public class EditCommand implements CommandI
           int copylen = Math.min(command.position,
                   annotations[a].annotations.length);
           if (copylen > 0)
-           {
+          {
             System.arraycopy(annotations[a].annotations, 0, temp, 0,
                     copylen); // command.position);
           }
@@ -1057,8 +1060,8 @@ public class EditCommand implements CommandI
                     annotations[a].annotations.length - command.position);
             if (copylen > 0)
             {
-              System.arraycopy(annotations[a].annotations,
-                      command.position, deleted, 0, copylen); // command.number);
+              System.arraycopy(annotations[a].annotations, command.position,
+                      deleted, 0, copylen); // command.number);
             }
           }
 
@@ -1067,10 +1070,10 @@ public class EditCommand implements CommandI
           if (annotations[a].annotations.length > command.position
                   + command.number)
           {
-            System.arraycopy(annotations[a].annotations, command.position
-                    + command.number, temp, command.position,
-                    annotations[a].annotations.length - command.position
-                            - command.number); // aSize
+            System.arraycopy(annotations[a].annotations,
+                    command.position + command.number, temp,
+                    command.position, annotations[a].annotations.length
+                            - command.position - command.number); // aSize
           }
         }
         else
@@ -1117,8 +1120,7 @@ public class EditCommand implements CommandI
       if (command.editedFeatures != null
               && command.editedFeatures.containsKey(seq))
       {
-        sequence.setSequenceFeatures(command.editedFeatures
-                .get(seq));
+        sequence.setSequenceFeatures(command.editedFeatures.get(seq));
       }
 
       return;
@@ -1222,10 +1224,15 @@ public class EditCommand implements CommandI
         for (SequenceI seq : e.getSequences())
         {
           SequenceI ds = seq.getDatasetSequence();
-          SequenceI preEdit = result.get(ds);
-          if (preEdit == null)
+          // SequenceI preEdit = result.get(ds);
+          if (!result.containsKey(ds))
           {
-            preEdit = new Sequence("", seq.getSequenceAsString());
+            /*
+             * copy sequence including start/end (but don't use copy constructor
+             * as we don't need annotations)
+             */
+            SequenceI preEdit = new Sequence("", seq.getSequenceAsString(),
+                    seq.getStart(), seq.getEnd());
             preEdit.setDatasetSequence(ds);
             result.put(ds, preEdit);
           }
@@ -1238,10 +1245,10 @@ public class EditCommand implements CommandI
      * Work backwards through the edit list, deriving the sequences before each
      * was applied. The final result is the sequence set before any edits.
      */
-    Iterator<Edit> edits = new ReverseListIterator<Edit>(getEdits());
-    while (edits.hasNext())
+    Iterator<Edit> editList = new ReverseListIterator<Edit>(getEdits());
+    while (editList.hasNext())
     {
-      Edit oldEdit = edits.next();
+      Edit oldEdit = editList.next();
       Action action = oldEdit.getAction();
       int position = oldEdit.getPosition();
       int number = oldEdit.getNumber();
@@ -1252,7 +1259,8 @@ public class EditCommand implements CommandI
         SequenceI preEdit = result.get(ds);
         if (preEdit == null)
         {
-          preEdit = new Sequence("", seq.getSequenceAsString());
+          preEdit = new Sequence("", seq.getSequenceAsString(),
+                  seq.getStart(), seq.getEnd());
           preEdit.setDatasetSequence(ds);
           result.put(ds, preEdit);
         }
@@ -1265,8 +1273,7 @@ public class EditCommand implements CommandI
           if (action == Action.DELETE_GAP)
           {
             preEdit.setSequence(new String(StringUtils.insertCharAt(
-                    preEdit.getSequence(), position,
-                    number, gap)));
+                    preEdit.getSequence(), position, number, gap)));
           }
           else if (action == Action.INSERT_GAP)
           {