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() {
860
860
public void testGetLast_emptySortedSet () {
861
861
SortedSet <String > sortedSet = ImmutableSortedSet .of ();
862
862
assertThrows (NoSuchElementException .class , () -> Iterables .getLast (sortedSet ));
863
+ assertEquals ("c" , Iterables .getLast (sortedSet , "c" ));
863
864
}
864
865
865
866
public void testGetLast_iterable () {
Original file line number Diff line number Diff line change 36
36
import java .util .Queue ;
37
37
import java .util .RandomAccess ;
38
38
import java .util .Set ;
39
+ import java .util .SortedSet ;
39
40
import java .util .stream .Stream ;
40
41
import org .jspecify .annotations .NonNull ;
41
42
import org .jspecify .annotations .Nullable ;
@@ -859,6 +860,8 @@ public Iterator<T> iterator() {
859
860
throw new NoSuchElementException ();
860
861
}
861
862
return getLastInNonemptyList (list );
863
+ } else if (iterable instanceof SortedSet ) {
864
+ return ((SortedSet <T >) iterable ).last ();
862
865
}
863
866
864
867
return Iterators .getLast (iterable .iterator ());
@@ -889,6 +892,8 @@ public Iterator<T> iterator() {
889
892
return defaultValue ;
890
893
} else if (iterable instanceof List ) {
891
894
return getLastInNonemptyList ((List <? extends T >) iterable );
895
+ } else if (iterable instanceof SortedSet ) {
896
+ return ((SortedSet <? extends T >) iterable ).last ();
892
897
}
893
898
}
894
899
Original file line number Diff line number Diff line change @@ -889,6 +889,7 @@ public void testGetLast_withDefault_not_empty_list() {
889
889
public void testGetLast_emptySortedSet () {
890
890
SortedSet <String > sortedSet = ImmutableSortedSet .of ();
891
891
assertThrows (NoSuchElementException .class , () -> Iterables .getLast (sortedSet ));
892
+ assertEquals ("c" , Iterables .getLast (sortedSet , "c" ));
892
893
}
893
894
894
895
public void testGetLast_iterable () {
Original file line number Diff line number Diff line change 36
36
import java .util .Queue ;
37
37
import java .util .RandomAccess ;
38
38
import java .util .Set ;
39
+ import java .util .SortedSet ;
39
40
import java .util .Spliterator ;
40
41
import java .util .function .Consumer ;
41
42
import java .util .stream .Stream ;
@@ -849,6 +850,8 @@ public Spliterator<T> spliterator() {
849
850
throw new NoSuchElementException ();
850
851
}
851
852
return getLastInNonemptyList (list );
853
+ } else if (iterable instanceof SortedSet ) {
854
+ return ((SortedSet <T >) iterable ).last ();
852
855
}
853
856
854
857
return Iterators .getLast (iterable .iterator ());
@@ -879,6 +882,8 @@ public Spliterator<T> spliterator() {
879
882
return defaultValue ;
880
883
} else if (iterable instanceof List ) {
881
884
return getLastInNonemptyList ((List <? extends T >) iterable );
885
+ } else if (iterable instanceof SortedSet ) {
886
+ return ((SortedSet <? extends T >) iterable ).last ();
882
887
}
883
888
}
884
889
You can’t perform that action at this time.
0 commit comments