1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.diff.internal

File InsertDelta.java

 

Coverage histogram

../../../../img/srcFileCovDistChart2.png
83% of files have more coverage

Code metrics

6
13
5
1
82
41
8
0.62
2.6
5
1.6

Classes

Class Line # Actions
InsertDelta 33 13 0% 8 20
0.1666666716.7%
 

Contributing tests

This file is covered by 14 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software 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 GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.diff.internal;
21   
22    import java.util.List;
23   
24    import org.xwiki.diff.Chunk;
25    import org.xwiki.diff.PatchException;
26   
27    /**
28    * Implementation of {@link org.xwiki.diff.Delta} representing a chunk which does not exist in previous version.
29    *
30    * @param <E> the type of compared elements
31    * @version $Id: d81825a621a71576825b32c52b750340351cf74c $
32    */
 
33    public class InsertDelta<E> extends AbstractDelta<E>
34    {
35    /**
36    * @param previous the chunk before the modification
37    * @param next the chunk after the modification
38    */
 
39  3 toggle public InsertDelta(Chunk<E> previous, Chunk<E> next)
40    {
41  3 super(previous, next, Type.INSERT);
42    }
43   
44    /**
45    * @param original the chunk before the modification
46    * @param revised the chunk after the modification
47    */
 
48  62 toggle public InsertDelta(difflib.Chunk<E> original, difflib.Chunk<E> revised)
49    {
50  62 super(original, revised, Type.INSERT);
51    }
52   
 
53  0 toggle @Override
54    public void apply(List<E> target) throws PatchException
55    {
56  0 verify(target);
57   
58  0 int index = getPrevious().getIndex();
59  0 List<E> elements = getNext().getElements();
60  0 for (int i = 0; i < elements.size(); i++) {
61  0 target.add(index + i, elements.get(i));
62    }
63    }
64   
 
65  0 toggle @Override
66    public void restore(List<E> target)
67    {
68  0 int index = getNext().getIndex();
69  0 int size = getNext().size();
70  0 for (int i = 0; i < size; i++) {
71  0 target.remove(index);
72    }
73    }
74   
 
75  0 toggle @Override
76    public void verify(List<E> target) throws PatchException
77    {
78  0 if (getPrevious().getIndex() > target.size()) {
79  0 throw new PatchException("Incorrect patch for delta: delta original position > target size");
80    }
81    }
82    }