---
.../sf/freecol/common/util/CollectionUtils.java | 31 +++++++++++-----------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/src/net/sf/freecol/common/util/CollectionUtils.java
b/src/net/sf/freecol/common/util/CollectionUtils.java
index 058835714a1..4e25f7d599e 100644
--- a/src/net/sf/freecol/common/util/CollectionUtils.java
+++ b/src/net/sf/freecol/common/util/CollectionUtils.java
@@ -853,45 +853,44 @@ public class CollectionUtils {
* @return The first item, or null on failure.
*/
public static <T> T first(T[] array) {
- return (array == null || array.length == 0) ? null
- : first_internal(Arrays.stream(array), null);
+ return (array == null || array.length == 0) ? null : array[0];
}
/**
- * Get the first item of a collection.
+ * Get the first item of a list.
*
* @param <T> Generic type T
* @param c The {@code Collection} to search.
* @return The first item, or null on failure.
*/
- public static <T> T first(Collection<T> c) {
- return (c == null || c.isEmpty()) ? null
- : first_internal(c.stream(), null);
+ public static <T> T first(List<T> l) {
+ return (l == null || list.isEmpty()) ? null : l.get(0);
}
/**
- * Get the first item of a stream.
+ * Get the first item of a collection.
*
* @param <T> Generic type T
- * @param stream The {@code Stream} to search.
+ * @param c The {@code Collection} to search.
* @return The first item, or null on failure.
*/
- public static <T> T first(Stream<T> stream) {
- return (stream == null) ? null : first_internal(stream, null);
+ public static <T> T first(Collection<T> c) {
+ if (c == null || c.isEmpty()) return null;
+ Iterator<T> it = c.iterator();
+ return it.hasNext() ? it.next() : null;
}
/**
- * Implement first().
+ * Get the first item of a stream.
*
* @param <T> Generic type T
* @param stream The {@code Stream} to search.
- * @param fail The value to return on failure.
- * @return The first item, or fail on failure.
+ * @return The first item, or null on failure.
*/
- private static <T> T first_internal(Stream<T> stream, T fail) {
- return stream.findFirst().orElse(fail);
+ public static <T> T first(Stream<T> stream) {
+ return (stream == null) ? null : stream.findFirst().orElse(fail);
}
-
+
/**
* Flatten an array into a stream derived from its component streams.
*
--
2.11.0.rc0.7.gbe5a750
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freecol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freecol-developers