Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
25   191   18   1.92
10   73   0.72   13
13     1.38  
1    
 
  ModuleContext       Line # 35 25 18 100% 1.0
 
  (417)
 
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.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  1176744 toggle public ModuleContext(final ModuleAddress moduleLocation, final String locationWithinModule,
65    final SourcePosition startDelta, final SourcePosition endDelta) {
66  1176744 if (moduleLocation == null) {
67  2 throw new NullPointerException("module adress should not be null");
68    }
69  1176742 if (locationWithinModule == null) {
70  2 throw new NullPointerException("location within module should not be null");
71    }
72  1176740 this.moduleLocation = moduleLocation;
73  1176740 this.locationWithinModule = locationWithinModule;
74  1176740 this.startDelta = startDelta;
75  1176740 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  568004 toggle public ModuleContext(final ModuleAddress moduleLocation, final String locationWithinModule) {
86  568004 this(moduleLocation, locationWithinModule, null, null);
87    }
88   
89    /**
90    * Constructor.
91    *
92    * @param moduleLocation Module location information.
93    */
 
94  567773 toggle public ModuleContext(final ModuleAddress moduleLocation) {
95  567773 this(moduleLocation, "");
96    }
97   
98    /**
99    * Copy constructor.
100    *
101    * @param original Original context.
102    */
 
103  607993 toggle public ModuleContext(final ModuleContext original) {
104  607993 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 toggle public ModuleContext(final ModuleContext main, final String moduleLocation) {
115  5 this(main.getModuleLocation(), moduleLocation);
116    }
117   
118    /**
119    * Get location information about module.
120    *
121    * @return Module location information.
122    */
 
123  778857 toggle public final ModuleAddress getModuleLocation() {
124  778857 return moduleLocation;
125    }
126   
127    /**
128    * Get location information where are we within the module.
129    *
130    * @return Location within module.
131    */
 
132  29505507 toggle public final String getLocationWithinModule() {
133  29505507 return locationWithinModule;
134    }
135   
136    /**
137    * Set location information where are we within the module.
138    *
139    * @param locationWithinModule Location within module.
140    */
 
141  25496651 toggle public final void setLocationWithinModule(final String locationWithinModule) {
142  25496651 final String method = "setLocationWithinModule(String)";
143  25496651 this.locationWithinModule = locationWithinModule;
144  25496651 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  608321 toggle public final SourcePosition getStartDelta() {
155  608321 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  608321 toggle public final SourcePosition getEndDelta() {
166  608321 return endDelta;
167    }
168   
 
169  94 toggle public final int hashCode() {
170  94 return getModuleLocation().hashCode() ^ getLocationWithinModule().hashCode()
171  94 ^ (startDelta != null ? startDelta.hashCode() : 7)
172  94 ^ (endDelta != null ? endDelta.hashCode() : 11);
173    }
174   
 
175  67 toggle public final boolean equals(final Object obj) {
176  67 if (!(obj instanceof ModuleContext)) {
177  6 return false;
178    }
179  61 final ModuleContext other = (ModuleContext) obj;
180  61 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 toggle public final String toString() {
187  11 return getModuleLocation() + ":" + getLocationWithinModule()
188    + ":" + startDelta + ":" + endDelta;
189    }
190   
191    }