Package edu.claflin.finder.struct

# Class PrioritySet<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.PriorityQueue<T>
edu.claflin.finder.struct.PrioritySet<T>

Type Parameters:
  `T` - the type of object to manage in the PriorityQueue.

All Implemented Interfaces:
  `Serializable`, `Iterable<T>`, `Collection<T>`, `Queue<T>`

public class PrioritySet<T> extends PriorityQueue<T>
Represents a PrioritySet. Operates as an extension of the java.util.PriorityQueue in that it does not allow duplicate elements. Furthermore, it may be configured so that on addition of similar elements (i.e. elements that are equivalent via .equals() but have different weight values) the higher of the two values is kept via comparator analysis. That is to say, if a Comparator indicates that a newly added object should come BEFORE the other object in a descending order, then the old object is replaced. This can be leveraged to perform a descending-based replacement if the comparator is configured properly. (i.e. a 4 replacing a 5.)

Version:
  1.1 May 28, 2015
Author:
  Charles Allen Schultz II
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `private final boolean`
  `addOverride`
  Boolean indicating if newer elements with a greater compare value should replace others.
  `private static final long`
  `serialVersionUID`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PrioritySet(boolean addOverride)`
  Public constructor for initializing a PrioritySet.
  `PrioritySet(Comparator<T> compare, boolean addOverride)`
  Public constructor for initializing a PrioritySet.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `add(T t)`
  Allows additions of items that already has a copy within the set (determined by obj.equals(obj2) ) and their subsequent replacement if they are of lesser value than the new object as determined by the queue's comparator.

  ### Methods inherited from class java.util.PriorityQueue

  `clear, comparator, contains, forEach, iterator, offer, peek, poll, remove, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray`

  ### Methods inherited from class java.util.AbstractQueue

  `addAll, element, remove`

  ### Methods inherited from class java.util.AbstractCollection

  `containsAll, isEmpty, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface java.util.Collection

  `containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray`

- ## Field Details

  - ### serialVersionUID

    private static final long serialVersionUID
    See Also:
      - Constant Field Values

  - ### addOverride

    private final boolean addOverride
    Boolean indicating if newer elements with a greater compare value should replace others.

- ## Constructor Details

  - ### PrioritySet

    public PrioritySet(boolean addOverride)
    Public constructor for initializing a PrioritySet. Utilizes the natural ordering of the elements.
    Parameters:
      `addOverride` - a boolean indicating if new elements may override older ones based on the comparator's value.

  - ### PrioritySet

    public PrioritySet(Comparator<T> compare, boolean addOverride)
    Public constructor for initializing a PrioritySet. Requires both a comparator for comparing elements and a boolean indicating if addOverride should be enabled.
    Parameters:
      `compare` - the Comparator to use for queue ordering.
      `addOverride` - a boolean indicating if new elements may override older ones based on the comparator's value.

- ## Method Details

  - ### add

    public boolean add(T t)
    Allows additions of items that already has a copy within the set (determined by obj.equals(obj2) ) and their subsequent replacement if they are of lesser value than the new object as determined by the queue's comparator.

    Specified by:
      `add` in interface `Collection<T>`
    Specified by:
      `add` in interface `Queue<T>`
    Overrides:
      `add` in class `PriorityQueue<T>`
    Parameters:
      `t` - the T type object to add.
    Returns:
      true if added, false if not.