Merge branch 'pr-120'

This closes #120
This commit is contained in:
Bruno P. Kinoshita 2020-03-28 18:14:42 +13:00
commit 45ea11ad15
4 changed files with 11 additions and 6 deletions

View File

@ -21,6 +21,9 @@
</properties> </properties>
<body> <body>
<release version="4.5" date="2020-MM-DD" description="Maintenance release."> <release version="4.5" date="2020-MM-DD" description="Maintenance release.">
<action issue="COLLECTIONS-737" dev="kinow" type="update" due-to="Prodigysov">
Return 0 immeditaly if the given iterable is null in IterableUtils#size. Update tests.
</action>
<action issue="COLLECTIONS-697" dev="eax" type="update" due-to="Ranjan George"> <action issue="COLLECTIONS-697" dev="eax" type="update" due-to="Ranjan George">
JavaDoc for FixedSizeList should warn that modifying underlying list is still allowed and is not prevented JavaDoc for FixedSizeList should warn that modifying underlying list is still allowed and is not prevented
</action> </action>

View File

@ -797,6 +797,9 @@ public class IterableUtils {
* @return the number of elements contained in the iterable * @return the number of elements contained in the iterable
*/ */
public static int size(final Iterable<?> iterable) { public static int size(final Iterable<?> iterable) {
if (iterable == null) {
return 0;
}
if (iterable instanceof Collection<?>) { if (iterable instanceof Collection<?>) {
return ((Collection<?>) iterable).size(); return ((Collection<?>) iterable).size();
} }

View File

@ -416,12 +416,6 @@ public class FluentIterableTest {
@Test @Test
public void size() { public void size() {
try {
FluentIterable.of((Iterable<?>) null).size();
fail("expecting NullPointerException");
} catch (final NullPointerException npe) {
// expected
}
assertEquals(0, FluentIterable.of(emptyIterable).size()); assertEquals(0, FluentIterable.of(emptyIterable).size());
assertEquals(IterableUtils.toList(iterableOdd).size(), FluentIterable.of(iterableOdd).size()); assertEquals(IterableUtils.toList(iterableOdd).size(), FluentIterable.of(iterableOdd).size());
} }

View File

@ -579,4 +579,9 @@ public class IterableUtilsTest {
// expected // expected
} }
} }
@Test
public void size() {
assertEquals(0, IterableUtils.size(null));
}
} }