|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ModuleContext | Line # 35 | 25 | 18 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(25) | |||
Result | |||
0.6666667
|
org.qedeq.kernel.se.common.ModuleContextTest.testConstructor
![]() |
1 PASS | |
0.5833333
|
org.qedeq.kernel.se.common.ModuleDataExceptionTest.testConstructor
![]() |
1 PASS | |
0.47916666
|
org.qedeq.kernel.se.visitor.QedeqNotNullTraverserTest.testAcceptors2
![]() |
1 PASS | |
0.45833334
|
org.qedeq.kernel.se.common.IllegalModuleDataExceptionTest.testConstructor
![]() |
1 PASS | |
0.45833334
|
org.qedeq.kernel.se.visitor.InterruptExceptionTest.testConstructor
![]() |
1 PASS | |
0.4375
|
org.qedeq.kernel.se.common.DefaultModuleAddressTest.testCreateModuleContext
![]() |
1 PASS | |
0.39583334
|
org.qedeq.kernel.se.visitor.QedeqNotNullTraverserTest.testQedeq
![]() |
1 PASS | |
0.3125
|
org.qedeq.kernel.se.common.DefaultModuleAddressTest.testDefaultModuleAddressURL
![]() |
1 PASS | |
0.3125
|
org.qedeq.kernel.se.common.DefaultModuleAddressTest.testDefaultModuleAddressFile
![]() |
1 PASS | |
0.3125
|
org.qedeq.kernel.se.common.DefaultModuleAddressTest.testConstructor
![]() |
1 PASS | |
0.27083334
|
org.qedeq.kernel.se.visitor.QedeqNotNullTraverserTest.testAcceptors1
![]() |
1 PASS | |
0.27083334
|
org.qedeq.kernel.se.visitor.QedeqNotNullTraverserTest.testQedeq2
![]() |
1 PASS | |
0.27083334
|
org.qedeq.kernel.se.common.ModuleContextTest.testEqualsObject
![]() |
1 PASS | |
0.27083334
|
org.qedeq.kernel.se.visitor.DefaultContextCheckerTest.testCheckHashCode
![]() |
1 PASS | |
0.20833333
|
org.qedeq.kernel.se.common.ModuleContextTest.testHashCode
![]() |
1 PASS | |
0.1875
|
org.qedeq.kernel.se.common.IllegalModuleDataExceptionTest.testEqualsObject
![]() |
1 PASS | |
0.1875
|
org.qedeq.kernel.se.common.ModuleDataExceptionTest.testEqualsObject
![]() |
1 PASS | |
0.1875
|
org.qedeq.kernel.se.visitor.InterruptExceptionTest.testEqualsObject
![]() |
1 PASS | |
0.16666667
|
org.qedeq.kernel.se.visitor.InterruptExceptionTest.testHashCode
![]() |
1 PASS | |
0.16666667
|
org.qedeq.kernel.se.common.IllegalModuleDataExceptionTest.testHashCode
![]() |
1 PASS | |
0.16666667
|
org.qedeq.kernel.se.common.ModuleDataExceptionTest.testHashCode
![]() |
1 PASS | |
0.125
|
org.qedeq.kernel.se.visitor.QedeqNotNullTraverserTest.testGeneration
![]() |
1 PASS | |
0.125
|
org.qedeq.kernel.se.common.ModuleContextTest.testToString
![]() |
1 PASS | |
0.125
|
org.qedeq.kernel.se.visitor.QedeqNotNullTraverserTest.testVisit
![]() |
1 PASS | |
0.083333336
|
org.qedeq.kernel.se.common.ModuleContextTest.testGetDelta
![]() |
1 PASS | |
1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org | |
2 | * | |
3 | * Copyright 2000-2014, 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.kernel.se.common; | |
17 | ||
18 | import org.qedeq.base.io.SourcePosition; | |
19 | import org.qedeq.base.trace.Trace; | |
20 | import org.qedeq.base.utility.EqualsUtility; | |
21 | ||
22 | ||
23 | /** | |
24 | * Define context for an instance of {@link org.qedeq.kernel.se.base.module.Qedeq}. | |
25 | * It consists of a location information: where is this module located. | |
26 | * Also the location within the {@link org.qedeq.kernel.se.base.module.Qedeq} object | |
27 | * should be described in an XPath like manner. | |
28 | * <p> | |
29 | * The idea behind this context is a caller perspective. The caller sets the | |
30 | * context (at least the module location information) and if the called method | |
31 | * throws an exception a try/catch block can retrieve the context information. | |
32 | * | |
33 | * @author Michael Meyling | |
34 | */ | |
35 | public class ModuleContext { | |
36 | ||
37 | /** This class. */ | |
38 | private static final Class CLASS = ModuleContext.class; | |
39 | ||
40 | /** Module location. */ | |
41 | private ModuleAddress moduleLocation; | |
42 | ||
43 | /** Location within the module. */ | |
44 | private String locationWithinModule; | |
45 | ||
46 | /** Skip position (relative to location start). Could be <code>null</code>. */ | |
47 | private final SourcePosition startDelta; | |
48 | ||
49 | /** Mark until this column (relative to location start). Could be <code>null</code>. */ | |
50 | private final SourcePosition endDelta; | |
51 | ||
52 | /** | |
53 | * Constructor. | |
54 | * | |
55 | * @param moduleLocation Module location information. Must not be <code>null</code>. | |
56 | * @param locationWithinModule Location within module. Must not be <code>null</code>. | |
57 | * @param startDelta Skip position (relative to location start). Could be | |
58 | * <code>null</code>. | |
59 | * @param endDelta Mark until this column (relative to location start). Could | |
60 | * be <code>null</code>. | |
61 | * @throws NullPointerException At least one parameter is null. | |
62 | * @throws IllegalArgumentException One parameter is below its allowed minimum. | |
63 | */ | |
64 | 342 |
![]() |
65 | final SourcePosition startDelta, final SourcePosition endDelta) { | |
66 | 342 | if (moduleLocation == null) { |
67 | 2 | throw new NullPointerException("module adress should not be null"); |
68 | } | |
69 | 340 | if (locationWithinModule == null) { |
70 | 2 | throw new NullPointerException("location within module should not be null"); |
71 | } | |
72 | 338 | this.moduleLocation = moduleLocation; |
73 | 338 | this.locationWithinModule = locationWithinModule; |
74 | 338 | this.startDelta = startDelta; |
75 | 338 | this.endDelta = endDelta; |
76 | } | |
77 | ||
78 | /** | |
79 | * Constructor. | |
80 | * | |
81 | * @param moduleLocation Module location information. Must not be <code>null</code>. | |
82 | * @param locationWithinModule Location within module. Must not be <code>null</code>. | |
83 | * @throws NullPointerException At least one parameter is null. | |
84 | */ | |
85 | 177 |
![]() |
86 | 177 | this(moduleLocation, locationWithinModule, null, null); |
87 | } | |
88 | ||
89 | /** | |
90 | * Constructor. | |
91 | * | |
92 | * @param moduleLocation Module location information. | |
93 | */ | |
94 | 148 |
![]() |
95 | 148 | this(moduleLocation, ""); |
96 | } | |
97 | ||
98 | /** | |
99 | * Copy constructor. | |
100 | * | |
101 | * @param original Original context. | |
102 | */ | |
103 | 156 |
![]() |
104 | 156 | this(original.getModuleLocation(), original.getLocationWithinModule(), |
105 | original.getStartDelta(), original.getEndDelta()); | |
106 | } | |
107 | ||
108 | /** | |
109 | * Constructor. | |
110 | * | |
111 | * @param main Main context. Must not be <code>null</code>. | |
112 | * @param moduleLocation Module location information. Must not be <code>null</code>. | |
113 | */ | |
114 | 5 |
![]() |
115 | 5 | this(main.getModuleLocation(), moduleLocation); |
116 | } | |
117 | ||
118 | /** | |
119 | * Get location information about module. | |
120 | * | |
121 | * @return Module location information. | |
122 | */ | |
123 | 402 |
![]() |
124 | 402 | return moduleLocation; |
125 | } | |
126 | ||
127 | /** | |
128 | * Get location information where are we within the module. | |
129 | * | |
130 | * @return Location within module. | |
131 | */ | |
132 | 4816 |
![]() |
133 | 4816 | return locationWithinModule; |
134 | } | |
135 | ||
136 | /** | |
137 | * Set location information where are we within the module. | |
138 | * | |
139 | * @param locationWithinModule Location within module. | |
140 | */ | |
141 | 4780 |
![]() |
142 | 4780 | final String method = "setLocationWithinModule(String)"; |
143 | 4780 | this.locationWithinModule = locationWithinModule; |
144 | 4780 | Trace.param(CLASS, this, method, "locationWithinModule", locationWithinModule); |
145 | } | |
146 | ||
147 | /** | |
148 | * Get delta position (relative to location start). This describes the precise | |
149 | * location start. | |
150 | * Could be <code>null</code>. | |
151 | * | |
152 | * @return Delta for precise location start. | |
153 | */ | |
154 | 160 |
![]() |
155 | 160 | return startDelta; |
156 | } | |
157 | ||
158 | /** | |
159 | * Get delta position (relative to location start). This describes the precise | |
160 | * location end. | |
161 | * Could be <code>null</code>. | |
162 | * | |
163 | * @return Delta for precise location end. | |
164 | */ | |
165 | 160 |
![]() |
166 | 160 | return endDelta; |
167 | } | |
168 | ||
169 | 94 |
![]() |
170 | 94 | return getModuleLocation().hashCode() ^ getLocationWithinModule().hashCode() |
171 | 94 | ^ (startDelta != null ? startDelta.hashCode() : 7) |
172 | 94 | ^ (endDelta != null ? endDelta.hashCode() : 11); |
173 | } | |
174 | ||
175 | 66 |
![]() |
176 | 66 | if (!(obj instanceof ModuleContext)) { |
177 | 6 | return false; |
178 | } | |
179 | 60 | final ModuleContext other = (ModuleContext) obj; |
180 | 60 | return getModuleLocation().equals(other.getModuleLocation()) |
181 | && getLocationWithinModule().equals(other.getLocationWithinModule()) | |
182 | && EqualsUtility.equals(startDelta, other.startDelta) | |
183 | && EqualsUtility.equals(endDelta, other.endDelta); | |
184 | } | |
185 | ||
186 | 11 |
![]() |
187 | 11 | return getModuleLocation() + ":" + getLocationWithinModule() |
188 | + ":" + startDelta + ":" + endDelta; | |
189 | } | |
190 | ||
191 | } |
|