Skip to content

Commit

Permalink
Merge pull request #6134 from neeshy/master
Browse files Browse the repository at this point in the history
[libg] Implement new JDK21 SortedSet and List methods for SortedList
  • Loading branch information
kriegfrj committed May 31, 2024
2 parents abec712 + a29d635 commit 70612e3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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;

0 comments on commit 70612e3

Please sign in to comment.