Python:
class UniqueItemSizeLimitedPriorityQueue(UniqueItemsPriorityQue):
# items in the queue are unique and do not repeat
# the size of the queue is limited
# this cls can also be used to detect repeated elements (nagging or reruns)
def __init__(self, limit: int):
super().__init__()
self._limit = limit
def getLimit(self) -> int:
return self._limit
def setLimit(self, limit: int):
self._limit = limit
# override
def insert(self, data):
if super().size() == self._limit:
super().poll()
super().insert(data)
# override
def poll(self):
# returns string
temp = super().poll()
if temp is None:
return ""
return temp
# override
def getRNDElement(self):
temp = super().getRNDElement()
if temp is None:
return ""
return temp
def getAsList(self) -> list[str]:
return self.queue