Class PrefixTree<T>

java.lang.Object
com.e1c.langtool.v8.dt.internal.ui.refactoring.PrefixTree<T>

public class PrefixTree<T> extends Object
Naive prefix tree implementation.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> @NonNull PrefixTree<T>
    Create new, empty prefix tree.
    @Nullable T
    find(@NonNull String key)
    Find value, associated with given key.
    @Nullable T
    Return value, associated with current node or null if no value associated.
    @Nullable T
    insert(@NonNull String key, @NonNull T value)
    Add or replace value, associated with key.
    @Nullable T
    setValue(@Nullable T value)
    Set current node value.
    @NonNull Map<List<String>,T>
    Convert current tree to the map of form <List of key segments, Value>
    Key segment boundary computed as follows: Last character terminate current segment Character for which predicate splitter returns true terminate current segment

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createPrefixTree

      public static <T> @NonNull PrefixTree<T> createPrefixTree()
      Create new, empty prefix tree.
      Type Parameters:
      T - Value item type
      Returns:
      New empty tree
    • getValue

      public @Nullable T getValue()
      Return value, associated with current node or null if no value associated.
      Returns:
      Current node value
    • setValue

      public @Nullable T setValue(@Nullable T value)
      Set current node value. Will return previous value, associated with current node, if any.
      Parameters:
      value - New value
      Returns:
      Previous value or null
    • insert

      public @Nullable T insert(@NonNull String key, @NonNull T value)
      Add or replace value, associated with key.
      Parameters:
      key - Key
      value - Associated value
      Returns:
      Previous value, associated with same key, if any
    • find

      public @Nullable T find(@NonNull String key)
      Find value, associated with given key.
      Parameters:
      key - Key
      Returns:
      Value, associated with key or null if no associated value found.
    • toSegmentedKeyMap

      public @NonNull Map<List<String>,T> toSegmentedKeyMap(@NonNull Predicate<Character> splitter)
      Convert current tree to the map of form <List of key segments, Value>
      Key segment boundary computed as follows:
      • Last character terminate current segment
      • Character for which predicate splitter returns true terminate current segment
      Parameters:
      splitter - Predicate, allowing additional key breaks insertion
      Returns:
      Current tree, converted to map