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

File OffsetsMapAlteredContent.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart6.png
72% of files have more coverage

Code metrics

4
14
5
1
103
46
7
0.5
2.8
5
1.4

Classes

Class Line # Actions
OffsetsMapAlteredContent 33 14 0% 7 11
0.521739152.2%
 

Contributing tests

This file is covered by 143 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   
21    package org.xwiki.annotation.internal.content;
22   
23    import java.util.Map;
24   
25    import org.xwiki.annotation.content.AlteredContent;
26   
27    /**
28    * Offsets maps based implementation of the {@link AlteredContent}.
29    *
30    * @version $Id: 8d7a2b57b0dc5ec9a8bfd5dc42a903e55feaa72a $
31    * @since 2.3M1
32    */
 
33    public class OffsetsMapAlteredContent implements AlteredContent
34    {
35    /**
36    * The actual character sequence representing the altered content.
37    */
38    private final CharSequence content;
39   
40    /**
41    * The offsets map for translating initial offsets to altered offsets.
42    */
43    private final Map<Integer, Integer> initialToAltered;
44   
45    /**
46    * The offsets map for translating the altered offsets to the initial offsets.
47    */
48    private final Map<Integer, Integer> alteredToInitial;
49   
50    /**
51    * The initial size of the content.
52    */
53    private final int size;
54   
55    /**
56    * Builds an altered content from the passed maps.
57    *
58    * @param content actual character sequence representing the altered content
59    * @param size initial size of the content
60    * @param initialToAltered offsets map for translating initial offsets to altered offsets
61    * @param alteredToInitial offsets map for translating the altered offsets to the initial offsets
62    */
 
63  269 toggle public OffsetsMapAlteredContent(CharSequence content, int size, Map<Integer, Integer> initialToAltered,
64    Map<Integer, Integer> alteredToInitial)
65    {
66  269 this.content = content;
67  269 this.initialToAltered = initialToAltered;
68  269 this.alteredToInitial = alteredToInitial;
69  269 this.size = size;
70    }
71   
 
72  269 toggle @Override
73    public CharSequence getContent()
74    {
75  269 return content;
76    }
77   
 
78  192 toggle @Override
79    public int getInitialOffset(int i)
80    {
81  192 Integer result = alteredToInitial.get(i);
82  192 if (result == null) {
83  0 throw new IllegalArgumentException();
84    }
85  192 return result;
86    }
87   
 
88  0 toggle @Override
89    public int getAlteredOffset(int i)
90    {
91  0 Integer result = initialToAltered.get(i);
92  0 if (result == null) {
93  0 throw new IllegalArgumentException();
94    }
95  0 return result;
96    }
97   
 
98  0 toggle @Override
99    public int getInitialLength()
100    {
101  0 return size;
102    }
103    }