Class RecentElementList<T>
java.lang.Object
io.github.syst3ms.skriptparser.util.RecentElementList<T>
- Type Parameters:
T- the type ofSyntaxInfo
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intSuppose 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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacknowledge(T element) Updates a given syntax's position inside of the frequency hierarchy.iterator()Custom iterator sorted by frequency of useMerges the elements of this list and the elements of the other list into a new set.voidremoveFrom(List<T> list) Removes the elements of thisRecentElementListfrom anotherList, in-place.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
MAX_LIST_SIZE
public static final int MAX_LIST_SIZESuppose 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
Updates a given syntax's position inside of the frequency hierarchy. This is used to acknowledge that a givenSyntaxInfohas been successfully parsed, and should as such be part of the "recent syntaxes" check.- Parameters:
element- the element to update
-
mergeWith
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
Removes the elements of thisRecentElementListfrom anotherList, in-place.- Parameters:
list- the list to remove from
-
iterator
-