1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.diff.internal

File DeleteDelta.java

 

Coverage histogram

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

Code metrics

4
12
5
1
80
39
7
0.58
2.4
5
1.4

Classes

Class Line # Actions
DeleteDelta 33 12 0% 7 17
0.190476219%
 

Contributing tests

This file is covered by 13 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 next version.
29    *
30    * @param <E> the type of compared elements
31    * @version $Id: 3c6bdd993b2e4c8763c3819401be4b917132c72f $
32    */
 
33    public class DeleteDelta<E> extends AbstractDelta<E>
34    {
35    /**
36    * @param previous the chunk before the modification
37    * @param next the chunk after the modification
38    */
 
39  7 toggle public DeleteDelta(Chunk<E> previous, Chunk<E> next)
40    {
41  7 super(previous, next, Type.DELETE);
42    }
43   
44    /**
45    * @param original the chunk before the modification
46    * @param revised the chunk after the modification
47    */
 
48  13 toggle public DeleteDelta(difflib.Chunk<E> original, difflib.Chunk<E> revised)
49    {
50  13 super(original, revised, Type.DELETE);
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 int size = getPrevious().size();
60  0 for (int i = 0; i < size; i++) {
61  0 target.remove(index);
62    }
63    }
64   
 
65  0 toggle @Override
66    public void restore(List<E> target)
67    {
68  0 int index = getNext().getIndex();
69  0 List<E> elements = getPrevious().getElements();
70  0 for (int i = 0; i < elements.size(); i++) {
71  0 target.add(index + i, elements.get(i));
72    }
73    }
74   
 
75  0 toggle @Override
76    public void verify(List<E> target) throws PatchException
77    {
78  0 getPrevious().verify(target);
79    }
80    }