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

File InlineDiffChunk.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

0
11
7
2
122
47
7
0.64
1.57
3.5
1

Classes

Class Line # Actions
InlineDiffChunk 31 11 0% 7 4
0.777777877.8%
InlineDiffChunk.Type 36 0 - 0 0
-1.0 -
 

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.display;
21   
22    import java.util.List;
23   
24    /**
25    * A group of consecutive elements that are targeted by the same operation (add, remove, keep) in an in-line diff.
26    *
27    * @param <E> the type of elements that form a chunk
28    * @version $Id: 3cc85a846638b9b37e495508cb9fec0026989327 $
29    * @since 4.1RC1
30    */
 
31    public class InlineDiffChunk<E>
32    {
33    /**
34    * The possible types of chunks you can find within an in-line diff.
35    */
 
36    public enum Type
37    {
38    /** A chunk that has been added. All the elements that form this chunk have been added. */
39    ADDED,
40   
41    /** A chunk that has been removed. All the elements that form this chunk have been added. */
42    DELETED,
43   
44    /**
45    * A chunk that stays unmodified. The elements of this chunk are neither added nor removed. They indicate the
46    * context where a change has been made.
47    */
48    UNMODIFIED;
49    }
50   
51    /**
52    * The chunk type. This specified the operation (add, remove, keep) that targets all the chunk elements.
53    */
54    private final Type type;
55   
56    /**
57    * The list of elements that form this chunk.
58    */
59    private final List<E> elements;
60   
61    /**
62    * Creates a new chunk with the specified type and elements.
63    *
64    * @param type the chunk type
65    * @param elements the list of elements that form the chunk
66    */
 
67  85 toggle public InlineDiffChunk(Type type, List<E> elements)
68    {
69  85 this.type = type;
70  85 this.elements = elements;
71    }
72   
73    /**
74    * @return the chunk type
75    */
 
76  53 toggle public Type getType()
77    {
78  53 return this.type;
79    }
80   
81    /**
82    * @return the list of element that form this chunk
83    */
 
84  0 toggle public List<E> getElements()
85    {
86  0 return this.elements;
87    }
88   
89    /**
90    * @return {@code true} if this chunk was added, {@code false} otherwise
91    */
 
92  111 toggle public boolean isAdded()
93    {
94  111 return this.type == Type.ADDED;
95    }
96   
97    /**
98    * @return {@code true} if this chunk was deleted, {@code false} otherwise
99    */
 
100  96 toggle public boolean isDeleted()
101    {
102  96 return this.type == Type.DELETED;
103    }
104   
105    /**
106    * @return {@code true} if this chunk was left unmodified, {@code false} otherwise
107    */
 
108  0 toggle public boolean isUnmodified()
109    {
110  0 return this.type == Type.UNMODIFIED;
111    }
112   
 
113  167 toggle @Override
114    public String toString()
115    {
116  167 StringBuilder stringBuilder = new StringBuilder(this.elements.size());
117  167 for (E element : this.elements) {
118  579 stringBuilder.append(element);
119    }
120  167 return stringBuilder.toString();
121    }
122    }