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

File ChangeDelta.java

 

Coverage histogram

../../../../img/srcFileCovDistChart1.png
82% of files have more coverage

Code metrics

6
22
5
1
96
52
8
0.36
4.4
5
1.6

Classes

Class Line # Actions
ChangeDelta 34 22 0% 8 31
0.0606060626.1%
 

Contributing tests

This file is covered by 23 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 has been modified between previous and next
29    * version.
30    *
31    * @param <E> the type of compared elements
32    * @version $Id: f41760c5b966b75f63a58d000c681a4ec4059b84 $
33    */
 
34    public class ChangeDelta<E> extends AbstractDelta<E>
35    {
36    /**
37    * @param previous the chunk before the modification
38    * @param next the chunk after the modification
39    */
 
40  0 toggle public ChangeDelta(Chunk<E> previous, Chunk<E> next)
41    {
42  0 super(previous, next, Type.CHANGE);
43    }
44   
45    /**
46    * @param original the chunk before the modification
47    * @param revised the chunk after the modification
48    */
 
49  78 toggle public ChangeDelta(difflib.Chunk<E> original, difflib.Chunk<E> revised)
50    {
51  78 super(original, revised, Type.CHANGE);
52    }
53   
 
54  0 toggle @Override
55    public void apply(List<E> target) throws PatchException
56    {
57  0 verify(target);
58   
59  0 int index = getPrevious().getIndex();
60  0 int size = getPrevious().size();
61  0 for (int i = 0; i < size; i++) {
62  0 target.remove(index);
63    }
64   
65  0 int i = 0;
66  0 for (E element : getNext().getElements()) {
67  0 target.add(index + i, element);
68  0 i++;
69    }
70    }
71   
 
72  0 toggle @Override
73    public void restore(List<E> target)
74    {
75  0 int index = getNext().getIndex();
76  0 int size = getNext().size();
77  0 for (int i = 0; i < size; i++) {
78  0 target.remove(index);
79    }
80   
81  0 int i = 0;
82  0 for (E element : getPrevious().getElements()) {
83  0 target.add(index + i, element);
84  0 i++;
85    }
86    }
87   
 
88  0 toggle @Override
89    public void verify(List<E> target) throws PatchException
90    {
91  0 getPrevious().verify(target);
92  0 if (getPrevious().getIndex() > target.size()) {
93  0 throw new PatchException("Incorrect patch for delta: delta original position > target size");
94    }
95    }
96    }