Package monq.jfa
Class Intervals<D>
java.lang.Object
monq.jfa.Intervals<D>
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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidall intervals which are currently mapped tonullwill be mapped to the given object.get(char ch) final DgetAt(int i) final chargetFirstAt(int i) final chargetLastAt(int i) final voidinverts the mapped and unmapped intervals.static StringlogStats()final voidfinal voidreset()reset to the state of a freshly constructed object.static voidfinal voidfinal intsize()Provides the number of stored character ranges, including ranges which map tonull.toString()final <E> voidUpdate what the range of characters fromfirsttolast(inclusive) maps to by applying themergerto the currently mapped value and the new one.
-
Constructor Details
-
Intervals
public Intervals()
-
-
Method Details
-
logStats
-
resetStats
public static void resetStats() -
complete
all intervals which are currently mapped to
nullwill 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 ofcharvalues being mapped tonull. -
get
-
size
public final int size()Provides the number of stored character ranges, including ranges which map tonull. For Example, after areset()this is 1, because the single stored character range including all characters is mapped tonull. After adding a value for one range, say,a-z, this will be 3, with the range left right of[a-z]mapped tonull.- Returns:
- number of store character ranges, including those mapped to
null
-
getAt
-
setAt
-
getFirstAt
public final char getFirstAt(int i) -
getLastAt
public final char getLastAt(int i) -
overwrite
-
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 fromfirsttolast(inclusive) maps to by applying themergerto the currently mapped value and the new one.As an example consider the stored values to be of type
D=Set<Stuff>and thenewValueof typeStuffwhere the merger adds the new value to the set.- Type Parameters:
E- type of the new value- Parameters:
first- character of rangelast- character of rangenewValue- 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 ornullor whatever is neededmerger- merge the available value in the range with the new value. NOTE: the merger must deal with the available value beingnull
-
invert
inverts the mapped and unmapped intervals. Intervals which are currently mapped to
nullwill be mapped too, and those currently mapped to some object are mapped tonull. -
toString
-