Package monq.jfa

Class Intervals<D>

java.lang.Object
monq.jfa.Intervals<D>

public class Intervals<D> extends Object

Used to construct CharTrans objects of different implementations.

NOTE: This looks as if it could implement CharTrans, but it should not, because it explicitly stores character ranges mapped to null which contradicts the contract of CharTrans. Furthermore this class is intentionally mutable, which is also not the idea of CharTrans.

TODO: replace with an implementation which has a complete Char.MAX_VALUE pair of arrays that is plainly set and overwritten, instead of mainting the intervals. Then measure performance.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    all intervals which are currently mapped to null will be mapped to the given object.
    get(char ch)
     
    final D
    getAt(int i)
     
    final char
    getFirstAt(int i)
     
    final char
    getLastAt(int i)
     
    final void
    invert(D o)
    inverts the mapped and unmapped intervals.
    static String
     
    final void
    overwrite(char first, char last, D o)
     
    final void
    reset to the state of a freshly constructed object.
    static void
     
    final void
    setAt(int i, D o)
     
    final int
    Provides the number of stored character ranges, including ranges which map to null.
     
    final <E> void
    update(char first, char last, E newValue, Function<D,D> copyOnSplit, BiFunction<D,E,D> merger)
    Update what the range of characters from first to last (inclusive) maps to by applying the merger to the currently mapped value and the new one.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Intervals

      public Intervals()
  • Method Details

    • logStats

      public static String logStats()
    • resetStats

      public static void resetStats()
    • complete

      public final void complete(D o)

      all intervals which are currently mapped to null will be mapped to the given object.

    • reset

      public final void reset()
      reset to the state of a freshly constructed object. In particular there will be one interval spanning the whole range of char values being mapped to null.
    • get

      public D get(char ch)
    • size

      public final int size()
      Provides the number of stored character ranges, including ranges which map to null. For Example, after a reset() this is 1, because the single stored character range including all characters is mapped to null. After adding a value for one range, say, a-z, this will be 3, with the range left right of [a-z] mapped to null.
      Returns:
      number of store character ranges, including those mapped to null
    • getAt

      public final D getAt(int i)
    • setAt

      public final void setAt(int i, D o)
    • getFirstAt

      public final char getFirstAt(int i)
    • getLastAt

      public final char getLastAt(int i)
    • overwrite

      public final void overwrite(char first, char last, D o)
    • update

      public final <E> void update(char first, char last, E newValue, Function<D,D> copyOnSplit, BiFunction<D,E,D> merger)
      Update what the range of characters from first to last (inclusive) maps to by applying the merger to the currently mapped value and the new one.

      As an example consider the stored values to be of type D=Set<Stuff> and the newValue of type Stuff where the merger adds the new value to the set.

      Type Parameters:
      E - type of the new value
      Parameters:
      first - character of range
      last - character of range
      newValue - to merge with available values.
      copyOnSplit - when splitting an available interval at either first or last, the newly introduced interval needs a value and copyOnSplit is called with the value of the previous interval. It may just return that value, or make a copy, or return a fresh value or null or whatever is needed
      merger - merge the available value in the range with the new value. NOTE: the merger must deal with the available value being null
    • invert

      public final void invert(D o)

      inverts the mapped and unmapped intervals. Intervals which are currently mapped to null will be mapped to o, and those currently mapped to some object are mapped to null.

    • toString

      public String toString()
      Overrides:
      toString in class Object