[External] : Re: Introduce constructor for PriorityQueue with existing collection and custom comparator
Archie Cobbs
archie.cobbs at gmail.com
Thu Dec 14 15:22:20 UTC 2023
On Thu, Dec 14, 2023 at 4:56 AM Viktor Klang <viktor.klang at oracle.com>
wrote:
> I presume that the precondition to have the original collection be
> pre-ordered according to the supplied Comparator can be verified by
> checking before adding each element in the collection to the PQ that it
> compareTo equal-or-greater to the previous one?
>
Hmm... something is not adding up.
Either (a) there is a precondition that the collection already be sorted or
(b) there's no such precondition.
In case (a):
- Why isn't the new constructor invoking initElementsFromCollection()
instead of initFromCollection()?
- The precondition is not very obvious from the Javadoc description, and
moreover what happens when the precondition is not met is not documented at
all.
In case (b):
- The Javadoc is misleading because it (ambiguously) implies there is a
precondition with the wording "collection that orders its elements
according to the specified comparator" (the referent of "that" is ambiguous
- does it refer to the collection or the PriorityQueue?)
>From the PR description it seems clear that there is no such precondition.
So maybe the Javadoc should say this instead:
Creates a {@code PriorityQueue} containing the elements in the specified
> collection. The {@code PriorityQueue} will order its elements according to
> the specified comparator.
>
-Archie
--
Archie L. Cobbs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20231214/4a5db8d1/attachment.htm>
More information about the core-libs-dev
mailing list