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

File AbstractDelta.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

4
23
10
1
143
73
12
0.52
2.3
10
1.2

Classes

Class Line # Actions
AbstractDelta 34 23 0% 12 14
0.621621662.2%
 

Contributing tests

This file is covered by 39 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.Objects;
23   
24    import org.apache.commons.lang3.builder.HashCodeBuilder;
25    import org.xwiki.diff.Chunk;
26    import org.xwiki.diff.Delta;
27   
28    /**
29    * Base class used for various types of {@link Delta}s.
30    *
31    * @param <E> the type of compared elements
32    * @version $Id: b6d83b749899d6f6b088a2d9a39a3fc1866cfe19 $
33    */
 
34    public abstract class AbstractDelta<E> implements Delta<E>
35    {
36    /**
37    * @see #getType()
38    */
39    private Type type;
40   
41    /**
42    * @see #getPrevious()
43    */
44    private Chunk<E> previous;
45   
46    /**
47    * @see #getNext()
48    */
49    private Chunk<E> next;
50   
51    /**
52    * @param previous the chunk before the modification
53    * @param next the chunk after the modification
54    * @param type the type of modification applied to the list
55    */
 
56  26 toggle public AbstractDelta(Chunk<E> previous, Chunk<E> next, Type type)
57    {
58  26 this.type = type;
59  26 this.previous = previous;
60  26 this.next = next;
61    }
62   
63    /**
64    * @param original the chunk before the modification
65    * @param revised the chunk after the modification
66    * @param type the type of modification applied to the list
67    */
 
68  144 toggle public AbstractDelta(difflib.Chunk<E> original, difflib.Chunk<E> revised, Type type)
69    {
70  144 this.type = type;
71  144 this.previous = new DefaultChunk<E>(original);
72  144 this.next = new DefaultChunk<E>(revised);
73    }
74   
 
75  252 toggle @Override
76    public Type getType()
77    {
78  252 return this.type;
79    }
80   
 
81  478 toggle @Override
82    public Chunk<E> getPrevious()
83    {
84  478 return this.previous;
85    }
86   
87    /**
88    * @param previous the chunk before the modification
89    */
 
90  0 toggle public void setPrevious(Chunk<E> previous)
91    {
92  0 this.previous = previous;
93    }
94   
 
95  219 toggle @Override
96    public Chunk<E> getNext()
97    {
98  219 return this.next;
99    }
100   
101    /**
102    * @param next the chunk after the modification
103    */
 
104  0 toggle public void setNext(Chunk<E> next)
105    {
106  0 this.next = next;
107    }
108   
 
109  0 toggle @Override
110    public int hashCode()
111    {
112  0 HashCodeBuilder builder = new HashCodeBuilder();
113   
114  0 builder.append(getType());
115  0 builder.append(getPrevious());
116  0 builder.append(getNext());
117   
118  0 return builder.toHashCode();
119    }
120   
 
121  18 toggle @Override
122    public boolean equals(Object obj)
123    {
124  18 if (this == obj) {
125  0 return true;
126    }
127   
128  18 if (obj instanceof Delta) {
129  18 Delta<?> otherDelta = (Delta<?>) obj;
130   
131  18 return getType() == otherDelta.getType() && Objects.equals(getPrevious(), otherDelta.getPrevious())
132    && Objects.equals(getNext(), otherDelta.getNext());
133    }
134   
135  0 return false;
136    }
137   
 
138  4 toggle @Override
139    public String toString()
140    {
141  4 return "[-" + getPrevious() + " +" + getNext() + "]";
142    }
143    }