Skip to content

Commit

Permalink
Implement new JDK21 SortedSet and List methods for SortedList
Browse files Browse the repository at this point in the history
Signed-off-by: neeshy <neeshy@tfwno.gf>
  • Loading branch information
neeshy committed May 28, 2024
1 parent abec712 commit 0377763
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 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,23 @@ public T first() {
return get(0);
}

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

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

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

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

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

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

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

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

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

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

@Override
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

0 comments on commit 0377763

Please sign in to comment.