Klasse ObjectArrayPriorityQueue<T>

java.lang.Object
speiger.src.collections.objects.queues.AbstractObjectPriorityQueue<T>
speiger.src.collections.objects.queues.ObjectArrayPriorityQueue<T>
Typparameter:
T - the keyType of elements maintained by this Collection
Alle implementierten Schnittstellen:
Iterable<T>, ObjectIterable<T>, ObjectPriorityQueue<T>

public class ObjectArrayPriorityQueue<T> extends AbstractObjectPriorityQueue<T>
A Array Priority Queue, this is a very unoptimized implementation of the PriorityQueue for very specific usecases. It allows for duplicated entries and works like List.indexOf(Object) search. It is highly suggested to use HeapPriorityQueue otherwise, unless you know why you need this specific implementation
  • Konstruktordetails

    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue()
      Default Constructor
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(Comparator<? super T> comp)
      Constructor using custom sorter
      Parameter:
      comp - Comparator to sort the Array. Can be null
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(int size)
      Constructor with a Min Capacity
      Parameter:
      size - the initial capacity of the backing array
      Löst aus:
      IllegalStateException - if the initial size is smaller 0
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(int size, Comparator<? super T> comp)
      Constructor with a Min Capacity and custom Sorter
      Parameter:
      size - the initial capacity of the backing array
      comp - Comparator to sort the Array. Can be null
      Löst aus:
      IllegalStateException - if the initial size is smaller 0
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(T[] array)
      Constructor using a initial array
      Parameter:
      array - the Array that should be used
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(T[] array, int size)
      Constructor using a initial array
      Parameter:
      array - the Array that should be used
      size - the amount of elements found within the array
      Löst aus:
      NegativeArraySizeException - if size is smaller then 0
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(T[] array, Comparator<? super T> comp)
      Constructor using a initial array and a custom sorter
      Parameter:
      array - the Array that should be used
      comp - Comparator to sort the Array. Can be null
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(T[] array, int size, Comparator<? super T> comp)
      Constructor using a initial array and a custom sorter
      Parameter:
      array - the Array that should be used
      size - the amount of elements found within the array
      comp - Comparator to sort the Array. Can be null
      Löst aus:
      NegativeArraySizeException - if size is smaller then 0
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(ObjectCollection<T> c)
      Constructor using a Collection
      Parameter:
      c - the Collection that should be used
    • ObjectArrayPriorityQueue

      public ObjectArrayPriorityQueue(ObjectCollection<T> c, Comparator<? super T> comp)
      Constructor using a Collection and a custom sorter
      Parameter:
      c - the Collection that should be used
      comp - Comparator to sort the Array. Can be null
  • Methodendetails

    • wrap

      public static <T> ObjectArrayPriorityQueue<T> wrap(T[] array)
      Wrapping method to help serialization
      Typparameter:
      T - the keyType of elements maintained by this Collection
      Parameter:
      array - the array that should be used
      Gibt zurück:
      a ArrayPriorityQueue containing the original input array
    • wrap

      public static <T> ObjectArrayPriorityQueue<T> wrap(T[] array, int size)
      Wrapping method to help serialization
      Typparameter:
      T - the keyType of elements maintained by this Collection
      Parameter:
      array - the array that should be used
      size - the amount of elements within the array
      Gibt zurück:
      a ArrayPriorityQueue containing the original input array
    • wrap

      public static <T> ObjectArrayPriorityQueue<T> wrap(T[] array, Comparator<? super T> comp)
      Wrapping method to help serialization, using a custom sorter
      Typparameter:
      T - the keyType of elements maintained by this Collection
      Parameter:
      array - the array that should be used
      comp - Comparator to sort the Array. Can be null
      Gibt zurück:
      a ArrayPriorityQueue containing the original input array
    • wrap

      public static <T> ObjectArrayPriorityQueue<T> wrap(T[] array, int size, Comparator<? super T> comp)
      Wrapping method to help serialization, using a custom sorter
      Typparameter:
      T - the keyType of elements maintained by this Collection
      Parameter:
      array - the array that should be used
      size - the amount of elements within the array
      comp - Comparator to sort the Array. Can be null
      Gibt zurück:
      a ArrayPriorityQueue containing the original input array
    • enqueue

      public void enqueue(T e)
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Method to insert a element into the PriorityQueue
      Parameter:
      e - the element that should be inserted
    • dequeue

      public T dequeue()
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Method to extract a element from the PriorityQueue
      Gibt zurück:
      a element from the Queue
    • first

      public T first()
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Shows the element that is to be returned next
      Gibt zurück:
      the first element in the Queue
    • peek

      public T peek(int index)
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Peeking function to see whats inside the queue.
      Parameter:
      index - of the element that is requested to be viewed.
      Gibt zurück:
      the element that is requested
    • contains

      public boolean contains(T e)
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Method to find out if a element is part of the queue
      Parameter:
      e - the element that is searched for
      Gibt zurück:
      true if the element is in the queue
    • removeFirst

      public boolean removeFirst(T e)
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Removes the first found element in the queue
      Parameter:
      e - the element that should be removed
      Gibt zurück:
      if a searched element was removed
    • removeLast

      public boolean removeLast(T e)
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Removes the last found element in the queue
      Parameter:
      e - the element that should be removed
      Gibt zurück:
      if a searched element was removed
    • onChanged

      public void onChanged()
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      Allows to notify the Queue to be revalidate its data
    • size

      public int size()
      Gibt zurück:
      the amount of elements that are stored in the PriorityQueue
    • clear

      public void clear()
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      clears all elements within the PriorityQueue, this does not resize the backing arrays
    • forEach

      public void forEach(Consumer<? super T> action)
    • forEachIndexed

      public void forEachIndexed(IntObjectConsumer<T> action)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      A Indexed forEach implementation that allows you to keep track of how many elements were already iterated over.
      Parameter:
      action - The action to be performed for each element
    • forEach

      public <E> void forEach(E input, ObjectObjectConsumer<E,T> action)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Helper function to reduce Lambda usage and allow for more method references, since these are faster/cleaner.
      Typparameter:
      E - the generic type of the Object
      Parameter:
      input - the object that should be included
      action - The action to be performed for each element
    • matchesAny

      public boolean matchesAny(Predicate<T> filter)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Helper function to reduce stream usage that allows to filter for any matches.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      true if any matches were found
    • matchesNone

      public boolean matchesNone(Predicate<T> filter)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Helper function to reduce stream usage that allows to filter for no matches.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      true if no matches were found
    • matchesAll

      public boolean matchesAll(Predicate<T> filter)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Helper function to reduce stream usage that allows to filter for all matches.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      true if all matches.
    • reduce

      public <E> E reduce(E identity, BiFunction<E,T,E> operator)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Performs a reduction on the elements of this Iterable
      Typparameter:
      E - the keyType of elements maintained by this Collection
      Parameter:
      identity - the start value
      operator - the operation that should be applied
      Gibt zurück:
      the reduction result, returns identity if nothing was found
    • reduce

      public T reduce(ObjectObjectUnaryOperator<T,T> operator)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Performs a reduction on the elements of this Iterable
      Parameter:
      operator - the operation that should be applied
      Gibt zurück:
      the reduction result, returns null value if nothing was found
    • findFirst

      public T findFirst(Predicate<T> filter)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Helper function to reduce stream usage that allows to filter for the first match.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      the found value or the null equivalent variant.
    • count

      public int count(Predicate<T> filter)
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Helper function to reduce stream usage that allows to count the valid elements.
      Parameter:
      filter - that should be applied
      Gibt zurück:
      the amount of Valid Elements
    • iterator

      public ObjectIterator<T> iterator()
      Beschreibung aus Schnittstelle kopiert: ObjectIterable
      Returns an iterator over elements of type T.
      Gibt zurück:
      draining iterator of the PriorityQueue
    • copy

      public ObjectArrayPriorityQueue<T> copy()
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      A Function that does a shallow clone of the PriorityQueue itself. This function is more optimized then a copy constructor since the PriorityQueue does not have to be unsorted/resorted. It can be compared to Cloneable but with less exception risk
      Gibt zurück:
      a Shallow Copy of the PriorityQueue
    • comparator

      public Comparator<? super T> comparator()
      Gibt zurück:
      the sorter of the Queue, can be null
    • toArray

      public <E> E[] toArray(E[] input)
      Beschreibung aus Schnittstelle kopiert: ObjectPriorityQueue
      A method to drop the contents of the Queue without clearing the queue
      Typparameter:
      E - the keyType of elements maintained by this Collection
      Parameter:
      input - where the elements should be inserted to. If it does not fit then it creates a new appropiatly created array
      Gibt zurück:
      the contents of the queue into a seperate array.