File tree Expand file tree Collapse file tree 4 files changed +12
-0
lines changed
guava-tests/test/com/google/common/collect
guava/src/com/google/common/collect
guava-tests/test/com/google/common/collect
guava/src/com/google/common/collect Expand file tree Collapse file tree 4 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -860,6 +860,7 @@ public void testGetLast_withDefault_not_empty_list() {
860860 public void testGetLast_emptySortedSet () {
861861 SortedSet <String > sortedSet = ImmutableSortedSet .of ();
862862 assertThrows (NoSuchElementException .class , () -> Iterables .getLast (sortedSet ));
863+ assertEquals ("c" , Iterables .getLast (sortedSet , "c" ));
863864 }
864865
865866 public void testGetLast_iterable () {
Original file line number Diff line number Diff line change 3636import java .util .Queue ;
3737import java .util .RandomAccess ;
3838import java .util .Set ;
39+ import java .util .SortedSet ;
3940import java .util .stream .Stream ;
4041import org .jspecify .annotations .NonNull ;
4142import org .jspecify .annotations .Nullable ;
@@ -859,6 +860,8 @@ public Iterator<T> iterator() {
859860 throw new NoSuchElementException ();
860861 }
861862 return getLastInNonemptyList (list );
863+ } else if (iterable instanceof SortedSet ) {
864+ return ((SortedSet <T >) iterable ).last ();
862865 }
863866
864867 return Iterators .getLast (iterable .iterator ());
@@ -889,6 +892,8 @@ public Iterator<T> iterator() {
889892 return defaultValue ;
890893 } else if (iterable instanceof List ) {
891894 return getLastInNonemptyList ((List <? extends T >) iterable );
895+ } else if (iterable instanceof SortedSet ) {
896+ return ((SortedSet <? extends T >) iterable ).last ();
892897 }
893898 }
894899
Original file line number Diff line number Diff line change @@ -889,6 +889,7 @@ public void testGetLast_withDefault_not_empty_list() {
889889 public void testGetLast_emptySortedSet () {
890890 SortedSet <String > sortedSet = ImmutableSortedSet .of ();
891891 assertThrows (NoSuchElementException .class , () -> Iterables .getLast (sortedSet ));
892+ assertEquals ("c" , Iterables .getLast (sortedSet , "c" ));
892893 }
893894
894895 public void testGetLast_iterable () {
Original file line number Diff line number Diff line change 3636import java .util .Queue ;
3737import java .util .RandomAccess ;
3838import java .util .Set ;
39+ import java .util .SortedSet ;
3940import java .util .Spliterator ;
4041import java .util .function .Consumer ;
4142import java .util .stream .Stream ;
@@ -849,6 +850,8 @@ public Spliterator<T> spliterator() {
849850 throw new NoSuchElementException ();
850851 }
851852 return getLastInNonemptyList (list );
853+ } else if (iterable instanceof SortedSet ) {
854+ return ((SortedSet <T >) iterable ).last ();
852855 }
853856
854857 return Iterators .getLast (iterable .iterator ());
@@ -879,6 +882,8 @@ public Spliterator<T> spliterator() {
879882 return defaultValue ;
880883 } else if (iterable instanceof List ) {
881884 return getLastInNonemptyList ((List <? extends T >) iterable );
885+ } else if (iterable instanceof SortedSet ) {
886+ return ((SortedSet <? extends T >) iterable ).last ();
882887 }
883888 }
884889
You can’t perform that action at this time.
0 commit comments