Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
12   117   8   1.5
0   33   0.67   8
8     1  
1    
 
  SubTextInput       Line # 24 12 8 100% 1.0
 
  (31)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program 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
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.base.io;
17   
18   
19    /**
20    * Wraps a text output stream.
21    *
22    * @author Michael Meyling
23    */
 
24    public class SubTextInput extends TextInput {
25   
26    /** Absolute start of this input relative to base {@link SubTextInput}. */
27    private final int absoluteStart;
28   
29    /** Absolute end of this input relative to base {@link SubTextInput}. */
30    private final int absoluteEnd;
31   
32    /**
33    * Constructor.
34    *
35    * @param source Text input.
36    */
 
37  3942 toggle public SubTextInput(final String source) {
38  3942 super(source);
39  3942 this.absoluteStart = 0;
40  3942 this.absoluteEnd = source.length();
41    }
42   
43    /**
44    * Constructor.
45    *
46    * @param original Parent input.
47    * @param absoluteStart Input part starts here.
48    * @param absoluteEnd Input part ends here.
49    */
 
50  4855 toggle public SubTextInput(final SubTextInput original, final int absoluteStart, final int absoluteEnd) {
51  4855 super(original.getAbsoluteSubstring(absoluteStart, absoluteEnd));
52  4855 this.absoluteStart = absoluteStart;
53  4855 this.absoluteEnd = absoluteEnd;
54    }
55   
56    /**
57    * Get the absolute start position of the current {@link SubTextInput}.
58    *
59    * @return Absolute start position.
60    */
 
61  702365 toggle public int getAbsoluteStart() {
62  702365 return absoluteStart;
63    }
64   
65    /**
66    * Get the absolute end position of the current {@link SubTextInput}.
67    *
68    * @return Absolute end position.
69    */
 
70  2 toggle public int getAbsoluteEnd() {
71  2 return absoluteEnd;
72    }
73   
74    /**
75    * Get the absolute position of the current position.
76    *
77    * @return Absolute position of current position.
78    */
 
79  692648 toggle public int getAbsolutePosition() {
80  692648 return getAbsoluteStart() + getPosition();
81    }
82   
83    /**
84    * Set the current position by calculating the relative position
85    * from the given absolute position.
86    *
87    * @param absolutePosition This should be the absolute position.
88    */
 
89  3 toggle public void setAbsolutePosition(final int absolutePosition) {
90  3 setPosition(absolutePosition - getAbsoluteStart());
91    }
92   
93    /**
94    * Get sub string of source. The given parameters have values for the underlying original
95    * SubTextInput at the base.
96    *
97    * @param absoluteFrom Absolute start of sub string.
98    * @param absoluteTo Absolute end of sub string.
99    * @return Sub string.
100    */
 
101  4856 toggle public String getAbsoluteSubstring(final int absoluteFrom, final int absoluteTo) {
102  4856 return getSubstring(absoluteFrom - getAbsoluteStart(), absoluteTo - getAbsoluteStart());
103    }
104   
105    /**
106    * Get sub string of source as a new {@link SubTextInput}. The given parameters have
107    * values for the underlying original SubTextInput at the base.
108    *
109    * @param absoluteFrom Absolute start of sub string.
110    * @param absoluteTo Absolute end of sub string.
111    * @return Sub string.
112    */
 
113  4851 toggle public SubTextInput getSubTextInput(final int absoluteFrom, final int absoluteTo) {
114  4851 return new SubTextInput(this, absoluteFrom, absoluteTo);
115    }
116   
117    }