Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F32381729C for ; Fri, 20 Mar 2015 16:44:17 +0000 (UTC) Received: (qmail 57332 invoked by uid 500); 20 Mar 2015 16:36:38 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 57223 invoked by uid 500); 20 Mar 2015 16:36:38 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 57211 invoked by uid 99); 20 Mar 2015 16:36:38 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Mar 2015 16:36:38 +0000 Date: Fri, 20 Mar 2015 16:36:38 +0000 (UTC) From: "haiyang li (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (LANG-1074) Add a method to ArrayUtils for removing all occurrences of a given element MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LANG-1074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14371581#comment-14371581 ] haiyang li commented on LANG-1074: ---------------------------------- please try the new patch file: LANG-1074_20150320.patch created with cmd svm diff from Windows console. I created the previous patch file by eclipse plugin subclipse. > Add a method to ArrayUtils for removing all occurrences of a given element > -------------------------------------------------------------------------- > > Key: LANG-1074 > URL: https://issues.apache.org/jira/browse/LANG-1074 > Project: Commons Lang > Issue Type: Improvement > Components: lang.* > Affects Versions: 3.3.2 > Reporter: haiyang li > Priority: Minor > Fix For: Review Patch > > Attachments: LANG-1074.patch.txt, LANG-1074_20150320.patch > > > Could we add the method: removeElementAll to remove all the occurrences of the specified element from the specified (boolean/char/byte/short/int/long/float/double/Object) array: > {code:title=org.apache.commons.lang3.ArrayUtils.java|borderStyle=solid} > public static T[] removeElementAll(final T[] array, final Object element) { > int index = indexOf(array, element); > if (index == INDEX_NOT_FOUND) { > return clone(array); > } > int[] indices = new int[array.length - index]; > int count = 0; > indices[count++] = index; > for (;;) { > index = indexOf(array, element, ++index); > if (index == INDEX_NOT_FOUND) { > break; > } else { > indices[count++] = index; > } > } > return (T[]) removeAll((Object) array, Arrays.copyOfRange(indices, 0, count)); > } > {code} > or maybe better: > {code:title=org.apache.commons.lang3.ArrayUtils.java|borderStyle=solid} > public static T[] removeElement(final T[] a, final Object element, boolean removeAll) { > int index = indexOf(a, element); > if (index == INDEX_NOT_FOUND) { > return clone(a); > } else if (!removeAll || index >= a.length - 1) { > return remove(a, index); > } else { > int[] indices = new int[a.length - index]; > int count = 0; > indices[count++] = index++; > > for (int len = a.length; index < len; index++) { > if ((a[index] == null) ? element == null : (element == null ? false : a[index].equals(element))) { > indices[count++] = index; > } > } > return (T[]) removeAll((Object) a, Arrays.copyOfRange(indices, 0, count)); > } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)