Class RecentElementList<T>

java.lang.Object
io.github.syst3ms.skriptparser.util.RecentElementList<T>
Type Parameters:
T - the type of SyntaxInfo
All Implemented Interfaces:
Iterable<T>

public class RecentElementList<T> extends Object implements Iterable<T>
A simple list that is only meant to keep track of which syntaxes are used frequently, in order to preemptively check them against a string that's being parsed. To illustrate the behaviour of this class, imagine you use some syntax A 8 times, then use syntax B once. The very next time the parser does the "recent syntaxes" check, it will check syntax A first, because it was used more than syntax B.
  • Field Details

    • MAX_LIST_SIZE

      public static final int MAX_LIST_SIZE
      Suppose you use a bunch of different syntaxes in your script: they all get sorted properly in the frequency hierarchy, and the "recent syntaxes" check works fine. But if there are many syntaxes in that list, then if one wants to use a syntax one hasn't used before, it would take a lot of time to actually match the pattern against it, since there's all the previously used syntaxes to check beforehand. Hence, the maximum number of recent elements is capped.
      See Also:
  • Constructor Details

    • RecentElementList

      public RecentElementList()
  • Method Details

    • acknowledge

      public void acknowledge(T element)
      Updates a given syntax's position inside of the frequency hierarchy. This is used to acknowledge that a givenSyntaxInfo has been successfully parsed, and should as such be part of the "recent syntaxes" check.
      Parameters:
      element - the element to update
    • mergeWith

      public List<T> mergeWith(List<T> other)
      Merges the elements of this list and the elements of the other list into a new set. The elements of this list have priority over the other elements. There will be no duplicate elements in the returned collection.
      Parameters:
      other - the other list
      Returns:
      a merged set with the elements of both lists
    • removeFrom

      public void removeFrom(List<T> list)
      Removes the elements of this RecentElementList from another List, in-place.
      Parameters:
      list - the list to remove from
    • iterator

      @NotNull public @NotNull Iterator<T> iterator()
      Custom iterator sorted by frequency of use
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      an iterator where syntaxes appear in decreasing order of frequency of use