You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Henri Yandell <fl...@gmail.com> on 2009/11/14 10:32:41 UTC

[lang] ArrayUtils issues

Wrapping 5 ArrayUtils issues up in one email to see if we can make
decisions on them.

LANG-470  	Add containsAll(Object[], Object[]) methods to ArrayUtils
LANG-531 	Add defaultIfEmpty or nullIfEmpty to ArrayUtils
LANG-536 	Add isSorted() to ArrayUtils
LANG-537 	Add ArrayUtils.toArray to create generic arrays
LANG-534 	ArrayUtils should have method to convert null arrays to
empty ones to help with Defensive coding

Going through each:

LANG-470.
  Vaguely interesting, but I don't know what containsAll( array, null
) and containsAll( null, null ) would do. This is effectively a set
method on arrays, so I'm thinking more in the direction of adding an
Set<T> ArrayUtils.toSet(T[]) method. It would mean a, potentially
non-public, ArraySet class.

LANG-531.
  I don't get the usefulness of the nullIfEmpty notion. Seems like an
odd paradigm to prefer null over empty (i.e. null safe) values. I'm
inclined to WONTFIX.

LANG-536.
  Needs tests, but I'm +1 to add this. Feels valuable despite the
annoyance of more primitive[] overloads bloating code.

LANG-537.
  I don't get this one. Presumably I'm missing something.

LANG-534.
  More irritating code bloat, but feels like a fair enough feature.
Opposite of LANG-531 and the more common pattern imo.


Thoughts?

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang] ArrayUtils issues

Posted by Henri Yandell <fl...@gmail.com>.
On Mon, Nov 16, 2009 at 1:10 PM, Jörg Schaible <jo...@gmx.de> wrote:
> Hi Hen,
>
> Henri Yandell wrote at Samstag, 14. November 2009 10:32:
>
>> Wrapping 5 ArrayUtils issues up in one email to see if we can make
>> decisions on them.
>>
>> LANG-470      Add containsAll(Object[], Object[]) methods to ArrayUtils
>> LANG-531      Add defaultIfEmpty or nullIfEmpty to ArrayUtils
>> LANG-536      Add isSorted() to ArrayUtils
>> LANG-537      Add ArrayUtils.toArray to create generic arrays
>> LANG-534      ArrayUtils should have method to convert null arrays to
>> empty ones to help with Defensive coding
>>
>> Going through each:
>>
> [snip]
>>
>> LANG-537.
>>   I don't get this one. Presumably I'm missing something.
>
> Have a look at the javadoc for this. In short: You cannot create an array
> for a generic type with
>
>   T array[] = new T[]{a,b,c};
>
> However, this can be done with:
>
>   T array[] = ArrayUtils.toArray(a,b,c);
>

Ahh. Seems useful then :) I'll see if the javadoc maybe needs more
example wise for dozy sods like me.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang] ArrayUtils issues

Posted by Jörg Schaible <jo...@gmx.de>.
Hi Hen,

Henri Yandell wrote at Samstag, 14. November 2009 10:32:

> Wrapping 5 ArrayUtils issues up in one email to see if we can make
> decisions on them.
> 
> LANG-470      Add containsAll(Object[], Object[]) methods to ArrayUtils
> LANG-531      Add defaultIfEmpty or nullIfEmpty to ArrayUtils
> LANG-536      Add isSorted() to ArrayUtils
> LANG-537      Add ArrayUtils.toArray to create generic arrays
> LANG-534      ArrayUtils should have method to convert null arrays to
> empty ones to help with Defensive coding
> 
> Going through each:
> 
[snip]
> 
> LANG-537.
>   I don't get this one. Presumably I'm missing something.

Have a look at the javadoc for this. In short: You cannot create an array
for a generic type with

  T array[] = new T[]{a,b,c};

However, this can be done with:

  T array[] = ArrayUtils.toArray(a,b,c);

[snip]

- Jörg



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang] ArrayUtils issues

Posted by sebb <se...@gmail.com>.
On 14/11/2009, Hasan Diwan <ha...@gmail.com> wrote:
> 2009/11/14 Henri Yandell <fl...@gmail.com>:
>
> > LANG-470        Add containsAll(Object[], Object[]) methods to ArrayUtils
>
>
> public static containsAll(Object[] first, Object[] second) {
>
>   for (Object o : first) {
>     if (ArrayUtils.contains(second, o) == false) return false;
>   }
>   return ArrayUtils.getLength(first) == ArrayUtils.getLength(second)
>
> }

AFAICT this does not work for arrays with duplicate entries.

>
>  > LANG-537        Add ArrayUtils.toArray to create generic arrays
>
>
> public static toArray(Object [] o){
>   return o;
>  }
>  These are needed to be compliant to java.util.Collections. I agree,
>  both seem a little silly.
>
> --
>  Sent from my mobile device
>  Envoyait de mon telephone mobil
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>  For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang] ArrayUtils issues

Posted by Hasan Diwan <ha...@gmail.com>.
2009/11/14 Henri Yandell <fl...@gmail.com>:
> LANG-470        Add containsAll(Object[], Object[]) methods to ArrayUtils

public static containsAll(Object[] first, Object[] second) {
  for (Object o : first) {
    if (ArrayUtils.contains(second, o) == false) return false;
  }
  return ArrayUtils.getLength(first) == ArrayUtils.getLength(second)
}

> LANG-537        Add ArrayUtils.toArray to create generic arrays

public static toArray(Object [] o){
  return o;
}
These are needed to be compliant to java.util.Collections. I agree,
both seem a little silly.
-- 
Sent from my mobile device
Envoyait de mon telephone mobil

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org