Class LocationMap<D,E>

java.lang.Object
eu.bandm.tools.message.LocationMap<D,E>
Type Parameters:
D - the document identifier type of the domain locations
E - the document identifier type of the range locations

public class LocationMap<D,E> extends Object
Facility to translate Locations. 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 Details

    • leftlocs

      protected List<Location<D>> leftlocs
      Locations making up the translation's domain. List is in one-to-one-correspondance to rightlocs.
    • rightlocs

      protected List<Location<E>> rightlocs
      Locations making up the translation's range. List is in one-to-one-correspondance to leftlocs.
    • transparent

      protected boolean transparent
      Whether locatiosn not in the domain are delivered unmodified, as their own Translation. If not set, null is returned in this case.
    • mapLocations

      public final Function<Location<D>,Location<E>> mapLocations
      Total function, which translates null to null and maps every location according to the containing .
    • mapMessages

      public final Function<SimpleMessage<D>,SimpleMessage<E>> mapMessages
      A public Function object which applies the mapping of the containing class to the location fields of SimpleMessages.
  • Constructor Details

    • LocationMap

      public LocationMap()
  • Method Details

    • clear

      public void clear()
      DOCME
    • put

      public void put(Location<D> left, Location<E> right)
      Establishes the mapping between both locations. left and right must be of "region" type and must have equal length.
    • setTransparent

      public boolean setTransparent(boolean trans)
      Sets the transparent attribute and returns its old value. Id decides that locatiosn not in the domain are delivered unmodified, as their own Translation. This is only sensible if type parameters D and E have the same value. Otherwise a type error will occur at runtime.
      if transparent is not set, null is returned in this case.
    • resolve

      @Opt public @Opt Location<E> resolve(Location<D> loc)
      Performs the mapping from left to right, Can currently only deal with points and intervals, not with sets.
      Returns:
      the translated location, or null if not in domain.
    • resolve_backward

      @Opt public @Opt Location<D> resolve_backward(Location<E> loc)
      Performs the mapping from right to left, Can currently only deal with points and intervals, not with sets.
    • 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 on transparent.
    • 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.
    • dump

      public void dump(PrintStream p)
      Auxiliary debugging routine. Prints all pairs of regions to stderr.