RFR: 8266571: Sequenced Collections [v10]

ExE Boss duke at openjdk.org
Sat Apr 22 09:44:09 UTC 2023


On Fri, 21 Apr 2023 22:33:13 GMT, Stuart Marks <smarks at openjdk.org> wrote:

>> PR for Sequenced Collections implementation.
>
> Stuart Marks has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Wording tweaks to SequencedMap / NavigableMap.
>  - Change "The implementation in this class" to "... interface."

src/java.base/share/classes/java/util/AbstractMap.java line 900:

> 898:      */
> 899:     /* non-public */ abstract static class ViewCollection<E> implements Collection<E> {
> 900:         UnsupportedOperationException uoe() { return new UnsupportedOperationException(); }

This doesn’t need to be an instance method:
Suggestion:

        static UnsupportedOperationException uoe() { return new UnsupportedOperationException(); }

src/java.base/share/classes/java/util/SortedMap.java line 113:

> 111:  */
> 112: 
> 113: public interface SortedMap<K,V> extends SequencedMap<K,V> {

This interface can now provide default implementations for the `firstKey` and `lastKey` methods:

default K firstKey() {
	var entry = this.firstEntry();
	if (entry == null) {
		throw new NoSuchElementException();
	}
	return entry.getKey();
}


default K lastKey() {
	var entry = this.lastEntry();
	if (entry == null) {
		throw new NoSuchElementException();
	}
	return entry.getKey();
}

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1174349716
PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1174351159


More information about the core-libs-dev mailing list