Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new JDK21 SortedSet and List methods for SortedList #6134

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions aQute.libg/src/aQute/lib/collections/SortedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,21 @@ public T first() {
return get(0);
}

public T getFirst() {
return first();
}

@Override
public T last() {
if (isEmpty())
throw new NoSuchElementException("last");
return get(size() - 1);
}

public T getLast() {
return last();
}

@Override
@Deprecated
public boolean addAll(int index, Collection<? extends T> c) {
Expand Down Expand Up @@ -392,12 +400,32 @@ public void add(int index, T element) {
throw new UnsupportedOperationException("Immutable");
}

@Deprecated
public void addFirst(T e) {
throw new UnsupportedOperationException("Immutable");
}

@Deprecated
public void addLast(T e) {
throw new UnsupportedOperationException("Immutable");
}

@Override
@Deprecated
public T remove(int index) {
throw new UnsupportedOperationException("Immutable");
}

@Deprecated
public T removeFirst() {
throw new UnsupportedOperationException("Immutable");
}

@Deprecated
public T removeLast() {
throw new UnsupportedOperationException("Immutable");
}

@Override
public ListIterator<T> listIterator() {
return new It(start);
Expand Down Expand Up @@ -506,6 +534,13 @@ public static <T> SortedSet<T> empty() {
return (SortedSet<T>) EMPTY;
}

public SortedList<T> reversed() {
if (comparator == null) {
return new SortedList<>(list, start, end, (Comparator<? super T>) Comparator.reverseOrder());
}
return new SortedList<>(list, start, end, comparator.reversed());
}

@Override
public Spliterator<T> spliterator() {
return SortedSet.super.spliterator();
Expand Down
2 changes: 1 addition & 1 deletion aQute.libg/src/aQute/lib/collections/package-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Version("4.2.0")
@Version("4.3.0")
package aQute.lib.collections;

import org.osgi.annotation.versioning.Version;