Niedzielski has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/336832 )
Change subject: Fix: copy ArrayUtils.removeAllOccurrences() ...................................................................... Fix: copy ArrayUtils.removeAllOccurrences() Some OEMs appear to have added a pre-v3.5, possibl pre-v3.4, version of ArrayUtils to the system path which does not contain removeAllOccurences(). Add a local copy https://github.com/jamesagnew/hapi-fhir/issues/394 https://rink.hockeyapp.net/manage/apps/226650/app_versions/79/crash_reasons/156658637 https://rink.hockeyapp.net/manage/apps/226650/app_versions/79/crash_reasons/156660777 https://rink.hockeyapp.net/manage/apps/226650/app_versions/79/crash_reasons/156663157 Change-Id: Ie361c193c115a5e551ca3ab175adce743259be89 --- M app/src/main/java/org/wikipedia/database/DatabaseTable.java A app/src/main/java/org/wikipedia/util/ArrayUtils.java 2 files changed, 49 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/32/336832/1 diff --git a/app/src/main/java/org/wikipedia/database/DatabaseTable.java b/app/src/main/java/org/wikipedia/database/DatabaseTable.java index 07c821d..12beca1 100644 --- a/app/src/main/java/org/wikipedia/database/DatabaseTable.java +++ b/app/src/main/java/org/wikipedia/database/DatabaseTable.java @@ -9,8 +9,8 @@ import android.support.annotation.NonNull; import android.text.TextUtils; -import org.apache.commons.lang3.ArrayUtils; import org.wikipedia.database.column.Column; +import org.wikipedia.util.ArrayUtils; import org.wikipedia.util.log.L; public abstract class DatabaseTable<T> { diff --git a/app/src/main/java/org/wikipedia/util/ArrayUtils.java b/app/src/main/java/org/wikipedia/util/ArrayUtils.java new file mode 100644 index 0000000..596b661 --- /dev/null +++ b/app/src/main/java/org/wikipedia/util/ArrayUtils.java @@ -0,0 +1,48 @@ +package org.wikipedia.util; + +import java.util.Arrays; + +import static org.apache.commons.lang3.ArrayUtils.INDEX_NOT_FOUND; +import static org.apache.commons.lang3.ArrayUtils.indexOf; +import static org.apache.commons.lang3.ArrayUtils.removeAll; + +// Some OEMs appear to have added a pre-v3.5, possibly re-v3.4, version of ArrayUtils to the system +// path which does not contain removeAllOccurences(). This class is a partial copy of Apache +// Commons' ArrayUtils +// https://rink.hockeyapp.net/manage/apps/226650/app_versions/79/crash_reasons/156658637 +public final class ArrayUtils { + /** + * Removes the occurrences of the specified element from the specified array. + * + * <p> + * All subsequent elements are shifted to the left (subtracts one from their indices). + * If the array doesn't contains such an element, no elements are removed from the array. + * <code>null</code> will be returned if the input array is <code>null</code>. + * </p> + * + * @param <T> the type of object in the array + * @param element the element to remove + * @param array the input array + * + * @return A new array containing the existing elements except the occurrences of the specified element. + * @since 3.5 + */ + public static <T> T[] removeAllOccurences(final T[] array, final T element) { + int index = indexOf(array, element); + if (index == INDEX_NOT_FOUND) { + return org.apache.commons.lang3.ArrayUtils.clone(array); + } + + int[] indices = new int[array.length - index]; + indices[0] = index; + int count = 1; + + while ((index = indexOf(array, element, indices[count - 1] + 1)) != INDEX_NOT_FOUND) { + indices[count++] = index; + } + + return removeAll(array, Arrays.copyOf(indices, count)); + } + + private ArrayUtils() { } +} -- To view, visit https://gerrit.wikimedia.org/r/336832 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie361c193c115a5e551ca3ab175adce743259be89 Gerrit-PatchSet: 1 Gerrit-Project: apps/android/wikipedia Gerrit-Branch: master Gerrit-Owner: Niedzielski <[email protected]> Gerrit-Reviewer: Sniedzielski <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
