commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "haiyang li (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-1074) Add removeElementAll method in class ArrayUtils
Date Mon, 15 Dec 2014 00:29:13 GMT

    [ https://issues.apache.org/jira/browse/LANG-1074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14246200#comment-14246200
] 

haiyang li commented on LANG-1074:
----------------------------------

Thanks and i agree. the name 'removeElementAll' may confuse people. i prefer to to second
approach, adding a parameter.
if i just post the code change and unit test here. anyone would help me to make the patch?

By the way, according to existing removeElement method and Map in JDK, i think the type of
the element in remove operations is ok to be Object. not T


> Add removeElementAll method in class ArrayUtils
> -----------------------------------------------
>
>                 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: Patch Needed
>
>
> 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> 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];
>         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> T[] removeElement(final T[] array, final Object element,
boolean removeAll) {
>        
>         if(!removeAll) {
>             return removeElement(array, element)
>         }
>         int index = indexOf(array, element);
>         if (index == INDEX_NOT_FOUND) {
>             return clone(array);
>         }
>         int[] indices = new int[array.length];
>         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}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message