Package eu.bandm.tools.location
Class LocationMap<D,E>
java.lang.Object
eu.bandm.tools.location.LocationMap<D,E>
- Type Parameters:
D
- the document identifier type of the domain locationsE
- the document identifier type of the range locations
Facility to translate
Location
s. Is needed in case of re-arranging
text fragments, and location info must be adjusted accordingly.
Eg. when fragents from a source text are concatenated into a StringBuilder, which is then subject to a lexical sanner, the scanner will produce error messages which must be re-mapped to the original context to become meaningful for the user.
All locations entered into this map must be of the "region" flavour
(see Location
). They must be entered pairwise, with identical
lengths.
-
Field Summary
Modifier and TypeFieldDescriptionLocations making up the translation's domain.Total function, which translates null to null and maps every location according to the containingLocationMap
.Locations making up the translation's range.protected boolean
Whether locatiosn not in the domain are delivered unmodified, as their own Translation. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the map completely, in both directions.Resolve a point or a region.void
dump
(PrintStream p) Auxiliary debugging routine.void
Establishes the mapping between both locations.Performs the mapping from left to right, Can currently only deal with points and intervals, not with sets.resolveBackward
(Location<E> loc) Performs the mapping from right to left, Can currently only deal with points and intervals, not with sets.Translates a location point at offset p in domain region n to the point at the same offset in the range region n.boolean
setTransparent
(boolean trans) Sets the transparent attribute and returns its old value.
-
Field Details
-
leftlocs
Locations making up the translation's domain. List is in one-to-one-correspondance torightlocs
. -
rightlocs
Locations making up the translation's range. List is in one-to-one-correspondance toleftlocs
. -
transparent
protected boolean transparentWhether locatiosn not in the domain are delivered unmodified, as their own Translation. If not set, null is returned in this case. -
mapLocations
Total function, which translates null to null and maps every location according to the containingLocationMap
.
-
-
Constructor Details
-
LocationMap
public LocationMap()Construct a new instance.
-
-
Method Details
-
clear
public void clear()Clear the map completely, in both directions. -
put
Establishes the mapping between both locations.left
andright
must be of "region" type and must have equal length.- Parameters:
left
- the region on the left side of the mapright
- the region on the right of the map
-
setTransparent
public boolean setTransparent(boolean trans) Sets the transparent attribute and returns its old value. Id decides whether a location which is not in the domain is returned unmodified (as its own translation, in casetransparent == true
), or ifnull
is returned otherwise. This is only sensible when type parameters D and E have the same value. Otherwise a type error will occur at runtime.- Parameters:
trans
- the new value for transparent behaviour.- Returns:
- the old value for transparent behaviour.
-
resolve
Performs the mapping from left to right, Can currently only deal with points and intervals, not with sets.- Parameters:
loc
- the Location to translate (from the left to the right side of the map.)- Returns:
- the translated location, or null if not in domain.
-
resolveBackward
Performs the mapping from right to left, Can currently only deal with points and intervals, not with sets.- Parameters:
loc
- the Location to translate (from the right to the left side of the map.)- Returns:
- the translated location, or null if not in domain.
-
doResolve
@Opt protected <P,Q> @Opt Location<Q> doResolve(List<Location<P>> from, List<Location<Q>> to, Location<P> loc) Resolve a point or a region. If a point is not in a domain region return null (iff transparent not set) or the unmodified point.If only one end of a region is in a domain region, then return this end. If no end of a region is in a domain region, return
null
or the original, depending ontransparent
.- Type Parameters:
P
- the document type of the input location.Q
- the document type of the target location.- Parameters:
from
- the list of the input locations, must be in sync with the list of the output locations.to
- the list of the output locations.loc
- the Location to translate.- Returns:
- the translated location, possibly
null
or the unchanged input.
-
resolvePoint
@Opt protected static <P,Q> @Opt Location<Q> resolvePoint(List<Location<P>> from, List<Location<Q>> to, Location<P> loc) Translates a location point at offset p in domain region n to the point at the same offset in the range region n.- Type Parameters:
P
- the document type of the input location.Q
- the document type of the target location.- Parameters:
from
- the list of the input locations, must be in sync with the list of the output locations.to
- the list of the output locations.loc
- the Location to translate.- Returns:
- the translated location, possibly
null
if the input location is not contained in a domain region.
-
dump
Auxiliary debugging routine. Prints all pairs of regions to the given output.- Parameters:
p
- the drain of the outputs.
-