Class StyleIndex

java.lang.Object
net.sourceforge.plantuml.style.StyleIndex

public final class StyleIndex extends Object
The fast, queryable counterpart of the old StyleStorage: every loaded Style is indexed by its query's tags in a StyleAtomTrie, so findMatching(StyleQuery) only ever visits declarations that could possibly match a query, instead of the old linear scan over every style ever loaded checking StyleSignatureBasic#matchAll one by one -- the actual fix for the slow style resolution (StyleBuilder.getMergedStyle(net.sourceforge.plantuml.style.StyleQuery), StyleBuilder.getMergedStyleSpecial(net.sourceforge.plantuml.style.StyleQuery, int)) this whole parser2 engine was built for. The subset-query trie itself already replicates matchAll's semantics exactly (level, star, SName set and stereotype set all included) -- see net.sourceforge.plantuml.style.parser2.LevelConstraint and net.sourceforge.plantuml.style.parser2.StyleAtom. Immutable: withLoaded(Style) and withMuted(Collection) both return a new index, leaving this one exactly as queryable as before, so that a StyleBuilder cached and reused across diagrams (see StyleLoader#loadSkin) never has a later diagram's own <style> override leak back into the shared, cached instance it was cloned from.
  • Method Details

    • empty

      public static StyleIndex empty()
    • withLoaded

      public StyleIndex withLoaded(Style newStyle)
      The counterpart of the old StyleBuilder#loadInternal's storage.get(signature)/storage.put(...) pair, called while loading a .skin file: a light-only "root { FontColor black }" and a later, dark-only "@media (dark) { root { FontColor white } }" share the exact same StyleQuery and MUST be folded into one Style right here, at load time -- not left for findMatching(net.sourceforge.plantuml.style.StyleQuery) to hand back as two separate entries. Deferring that fold to query time is unsound: a cross-selector cascade merge (say, "root" combined with a more specific "root document ganttDiagram") uses priority alone to decide the winner once both sides already carry a value (DarkString.mergeWith(net.sourceforge.plantuml.style.value.DarkString)'s final, non-combining branch), so a still-unmerged dark-only "root" entry -- whose priority is always high, since every dark declaration in a .skin file is numbered after every light one -- can beat an already-combined light+dark value from a less specific selector and silently drop that combined value's light half. Pre-merging same-signature entries here, exactly as the old code did, keeps every entry this index ever hands out fully self-consistent (both halves set whenever either declaration set either), so that later cascade folding only ever has to pick a winner between two complete values.
    • withMuted

      public StyleIndex withMuted(Collection<Style> newStyles)
      The counterpart of the old StyleBuilder#muteStyle: folds every style in newStyles into a brand new index, this one left untouched -- merging each one, in turn, with whatever already shares its exact signature (either already in this index, or earlier in newStyles itself), for the same reason withLoaded(net.sourceforge.plantuml.style.Style) does.
    • findMatching

      public List<Style> findMatching(StyleQuery query)
      Every loaded style whose query is a subset of query's, in the order they were loaded or muted in.
    • getAllStyles

      public List<Style> getAllStyles()
      Every style ever loaded or muted into this index, in that same order.