[Android] Add isArrayEmpty & insertOrUdpate util methods
Geoffrey Métais
git at videolan.org
Thu Jul 27 17:41:21 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jul 27 17:38:31 2017 +0200| [1f832301df36f09e5c9fc73a8744ce321b8a754c] | committer: Geoffrey Métais
Add isArrayEmpty & insertOrUdpate util methods
> https://code.videolan.org/videolan/vlc-android/commit/1f832301df36f09e5c9fc73a8744ce321b8a754c
---
vlc-android/src/org/videolan/vlc/util/Util.java | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 6e2d78aa2..af7d4cfd9 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -77,6 +77,10 @@ public class Util {
return false;
}
+ public static <T> boolean isArrayEmpty(@Nullable T[] array) {
+ return array == null || array.length == 0;
+ }
+
public static boolean isListEmpty(@Nullable Collection collection) {
return collection == null || collection.isEmpty();
}
@@ -136,4 +140,19 @@ public class Util {
Collections.addAll(list, array);
return list;
}
+
+ public static <T> void insertOrUdpate(List<T> dataset, T[] items) {
+ ArrayList<T> newItems = new ArrayList<>();
+ outer:
+ for (T newItem : items) {
+ for (T oldItem : dataset) {
+ if (newItem.equals(oldItem)) {
+ oldItem = newItem;
+ continue outer;
+ }
+ }
+ newItems.add(newItem);
+ }
+ dataset.addAll(newItems);
+ }
}
More information about the Android
mailing list