You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Rafael Santini <ra...@santini.eti.br> on 2013/07/04 20:43:43 UTC

Lang: ObjectUtils

Hi,

I would like to propose a method in ObjectUtils class that receives an array 
of objects and returns true if all objects are not null. I have implemented 
the following:

public static boolean isNull(Object object) {
    return object == null;
}

public static boolean isNotNull(Object object) {
    return isNull(object) == false;
}

public static boolean isNotNull(Object... objects) {
    for (Object object : objects) {
        if (isNull(object)) {
            return false;
        }
    }
    return true;
}

Can I submit a patch for this feature?

Thanks,

Rafael Santini




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


Re: ObjectUtils

Posted by Matt Benson <gu...@gmail.com>.
It is unfortunate that most of ArrayUtils' methods do not support varargs
because they were originally created with the array argument first.
 Semantically I think the concept of ArrayUtils#contains(Object, Object...
array) is more sensible anyway.  There is actually no technical reason why
this method and probably some others in ArrayUtils couldn't support both
syntaxes (probably deprecating the old one), but that's probably a
different discussion.

If you don't have an existing array, you can use ArrayUtils#toArray() i.e.
!ArrayUtils.contains(ArrayUtils.toArray(foo, bar, baz), null);  A little
long, but then there are always static imports.  However, it sounds like
you're trying to do something like validate method parameters.  Have you
considered, e.g.:

Validate.noNullElements(Arrays.asList(foo, bar, baz), "some required
argument was null");

?

Matt


On Mon, Jul 8, 2013 at 12:58 PM, Rafael Santini <ra...@santini.eti.br>wrote:

> Hi Matt,
>
> I don't have an array of objects. I have some variables that need to be
> checked whether are null or not.
>
>
> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>   // Do something...
> }
>
> To use ArrayUtils.contations(), I need to code something like:
>
> if (ArrayUtils.contains(new Object[] {obj1, obj2, obj3, obj4}, null) ==
> false) {
>    // Do something...
> }
>
> This example is related to some business code that I'm refactoring. In
> general, I need to check few objects.
>
> I'm worry about readability. So, I think that isNotNull(obj1, obj2, obj3,
> obj4) is more clear and is so readable like String.isNotBlank() that I use
> a lot.
>
>
> Rafael Santini
>
> -----Mensagem Original----- From: Matt Benson
> Sent: Monday, July 08, 2013 2:16 PM
> To: Commons Developers List
> Subject: Re: ObjectUtils
>
>
> I don't know exactly why this thread is getting split, but I think several
> of us are taking the implicit position that we shouldn't necessarily
> include a separate utility method for things that can be accomplished with
> existing utility methods.  It's arguably best that these (and any?) classes
> be kept as lean as possible.  The comparison to StringUtils methods is a
> little inept IMO; you are dealing with multiple object references, and
> attempting to present them with a varargs API.  The implication, then, is
> that arrays, rather than objects, are the relevant concept.  That puts us
> into the realm of the ArrayUtils class.  From a semantic standpoint, I
> would be concerned by a method e.g. ArrayUtils#isNotNull(Object... array).
> "is" is a singular verb and my inclination would be to think of the array
> itself as the object of that verb.  Is the array not null?  That check is
> of course more easily and efficiently accomplished with `array != null`.
> You could then opt to name the method something like
> ArrayUtils#**containsNoNullElements(Object.**.. array) but then, again,
> you can
> just as clearly, and in fewer characters, use `!ArrayUtils.contains(array,
> null)`.  Does that make sense?
>
> Matt
>
>
> On Mon, Jul 8, 2013 at 12:01 PM, Rafael Santini <rafael@santini.eti.br
> >wrote:
>
>  Hi,
>>
>> The proposed method is related to objects. As we have
>> StringUtils.isBlank(), isNotBlank(), isEmpty() etc., the
>> ObjectUtils.isNotNull(Object..****. objs) is intended to check if all
>>
>> objects are not null. So, instead of
>>
>>
>> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>>    // Do something...
>> }
>>
>> we have
>>
>> if (isNotNull(obj1, obj2, obj3, obj4) {
>>    // Do something...
>> }
>>
>> The StringUtils.firstNonNull() returns the first object that is not null
>> (equivalent to something that returns true if there is at least one object
>> that is not null). The isNotNull() returns true if all objects are not
>> null.
>>
>> Rafael Santini
>>
>> -----Mensagem Original----- From: Matt Benson
>> Sent: Monday, July 08, 2013 1:20 PM
>>
>> To: Commons Developers List
>> Subject: Re: Lang: ObjectUtils
>>
>> WRT #firstNonNull, I don't know why I couldn't find it before.  I do now,
>> and I agree it would seem to fit better in ArrayUtils.
>>
>> Matt
>>
>>
>> On Mon, Jul 8, 2013 at 10:04 AM, Jörg Schaible
>> <Jo...@scalaris.com>****wrote:
>>
>>  Hi Matt,
>>
>>>
>>> Matt Benson wrote:
>>>
>>> > On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
>>> > <Jo...@scalaris.com>****wrote:
>>>
>>> >
>>> >> Hi Hen,
>>> >>
>>> >> Henri Yandell wrote:
>>> >>
>>> >> > I don't see any value having the first two methods - replacing the
>>> '=='
>>> >> > sign is a bit too far in the 'provide simple methods' direction I
>>> think
>>> >> :)
>>> >> >
>>> >> > I think the third method is already in Lang as:
>>> >> >
>>> >> >     ArrayUtils.contains(array, null);
>>> >>
>>> >>
>>> >> Well, no, this is not, what the method does!
>>> >
>>> >
>>> > Correct, but to be fair, it's simple enough to use this method to
>>> > implement
>>> > the desired check.  Negate the result.
>>> >
>>> >
>>> >> With Lang we could use now:
>>> >>
>>> >>     ObjectUtils.firstNotNull(****array) != null
>>>
>>> >>
>>> >
>>> > I don't see such a method as this.
>>>
>>>
>>> http://commons.apache.org/****proper/commons-lang/javadocs/****<http://commons.apache.org/**proper/commons-lang/javadocs/**>
>>> api-release/org/apache/****commons/lang3/ObjectUtils.****
>>> html#firstNonNull(T<http://**commons.apache.org/proper/**
>>> commons-lang/javadocs/api-**release/org/apache/commons/**
>>> lang3/ObjectUtils.html#**firstNonNull(T<http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ObjectUtils.html#firstNonNull(T>
>>> >
>>>
>>> ..
>>> .)
>>>
>>> > If it did exist, it still wouldn't
>>> > implement the feature requested (check that no element of the array is
>>> > null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.
>>>
>>> I've re-read the original code and you're right.
>>>
>>> - Jörg
>>>
>>>
>>> ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>>> <de...@commons.apache.org>
>>> >
>>>
>>>
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>>
>>>
>> ------------------------------****----------------------------**
>> --**---------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>> <de...@commons.apache.org>
>> >
>>
>>
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: ObjectUtils

Posted by Rafael Santini <ra...@santini.eti.br>.
Hi Matt,

I don't have an array of objects. I have some variables that need to be 
checked whether are null or not.

if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
   // Do something...
}

To use ArrayUtils.contations(), I need to code something like:

if (ArrayUtils.contains(new Object[] {obj1, obj2, obj3, obj4}, null) == 
false) {
    // Do something...
}

This example is related to some business code that I'm refactoring. In 
general, I need to check few objects.

I'm worry about readability. So, I think that isNotNull(obj1, obj2, obj3, 
obj4) is more clear and is so readable like String.isNotBlank() that I use a 
lot.

Rafael Santini

-----Mensagem Original----- 
From: Matt Benson
Sent: Monday, July 08, 2013 2:16 PM
To: Commons Developers List
Subject: Re: ObjectUtils

I don't know exactly why this thread is getting split, but I think several
of us are taking the implicit position that we shouldn't necessarily
include a separate utility method for things that can be accomplished with
existing utility methods.  It's arguably best that these (and any?) classes
be kept as lean as possible.  The comparison to StringUtils methods is a
little inept IMO; you are dealing with multiple object references, and
attempting to present them with a varargs API.  The implication, then, is
that arrays, rather than objects, are the relevant concept.  That puts us
into the realm of the ArrayUtils class.  From a semantic standpoint, I
would be concerned by a method e.g. ArrayUtils#isNotNull(Object... array).
"is" is a singular verb and my inclination would be to think of the array
itself as the object of that verb.  Is the array not null?  That check is
of course more easily and efficiently accomplished with `array != null`.
You could then opt to name the method something like
ArrayUtils#containsNoNullElements(Object... array) but then, again, you can
just as clearly, and in fewer characters, use `!ArrayUtils.contains(array,
null)`.  Does that make sense?

Matt


On Mon, Jul 8, 2013 at 12:01 PM, Rafael Santini 
<ra...@santini.eti.br>wrote:

> Hi,
>
> The proposed method is related to objects. As we have
> StringUtils.isBlank(), isNotBlank(), isEmpty() etc., the
> ObjectUtils.isNotNull(Object..**. objs) is intended to check if all
> objects are not null. So, instead of
>
>
> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>    // Do something...
> }
>
> we have
>
> if (isNotNull(obj1, obj2, obj3, obj4) {
>    // Do something...
> }
>
> The StringUtils.firstNonNull() returns the first object that is not null
> (equivalent to something that returns true if there is at least one object
> that is not null). The isNotNull() returns true if all objects are not 
> null.
>
> Rafael Santini
>
> -----Mensagem Original----- From: Matt Benson
> Sent: Monday, July 08, 2013 1:20 PM
>
> To: Commons Developers List
> Subject: Re: Lang: ObjectUtils
>
> WRT #firstNonNull, I don't know why I couldn't find it before.  I do now,
> and I agree it would seem to fit better in ArrayUtils.
>
> Matt
>
>
> On Mon, Jul 8, 2013 at 10:04 AM, Jörg Schaible
> <Jo...@scalaris.com>**wrote:
>
>  Hi Matt,
>>
>> Matt Benson wrote:
>>
>> > On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
>> > <Jo...@scalaris.com>**wrote:
>> >
>> >> Hi Hen,
>> >>
>> >> Henri Yandell wrote:
>> >>
>> >> > I don't see any value having the first two methods - replacing the
>> '=='
>> >> > sign is a bit too far in the 'provide simple methods' direction I
>> think
>> >> :)
>> >> >
>> >> > I think the third method is already in Lang as:
>> >> >
>> >> >     ArrayUtils.contains(array, null);
>> >>
>> >>
>> >> Well, no, this is not, what the method does!
>> >
>> >
>> > Correct, but to be fair, it's simple enough to use this method to
>> > implement
>> > the desired check.  Negate the result.
>> >
>> >
>> >> With Lang we could use now:
>> >>
>> >>     ObjectUtils.firstNotNull(**array) != null
>> >>
>> >
>> > I don't see such a method as this.
>>
>>
>> http://commons.apache.org/**proper/commons-lang/javadocs/**
>> api-release/org/apache/**commons/lang3/ObjectUtils.**html#firstNonNull(T<http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ObjectUtils.html#firstNonNull(T>
>> ..
>> .)
>>
>> > If it did exist, it still wouldn't
>> > implement the feature requested (check that no element of the array is
>> > null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.
>>
>> I've re-read the original code and you're right.
>>
>> - Jörg
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: 
>> dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
>>
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: 
> dev-unsubscribe@commons.**apache.org<de...@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: ObjectUtils

Posted by Matt Benson <gu...@gmail.com>.
I don't know exactly why this thread is getting split, but I think several
of us are taking the implicit position that we shouldn't necessarily
include a separate utility method for things that can be accomplished with
existing utility methods.  It's arguably best that these (and any?) classes
be kept as lean as possible.  The comparison to StringUtils methods is a
little inept IMO; you are dealing with multiple object references, and
attempting to present them with a varargs API.  The implication, then, is
that arrays, rather than objects, are the relevant concept.  That puts us
into the realm of the ArrayUtils class.  From a semantic standpoint, I
would be concerned by a method e.g. ArrayUtils#isNotNull(Object... array).
 "is" is a singular verb and my inclination would be to think of the array
itself as the object of that verb.  Is the array not null?  That check is
of course more easily and efficiently accomplished with `array != null`.
 You could then opt to name the method something like
ArrayUtils#containsNoNullElements(Object... array) but then, again, you can
just as clearly, and in fewer characters, use `!ArrayUtils.contains(array,
null)`.  Does that make sense?

Matt


On Mon, Jul 8, 2013 at 12:01 PM, Rafael Santini <ra...@santini.eti.br>wrote:

> Hi,
>
> The proposed method is related to objects. As we have
> StringUtils.isBlank(), isNotBlank(), isEmpty() etc., the
> ObjectUtils.isNotNull(Object..**. objs) is intended to check if all
> objects are not null. So, instead of
>
>
> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>    // Do something...
> }
>
> we have
>
> if (isNotNull(obj1, obj2, obj3, obj4) {
>    // Do something...
> }
>
> The StringUtils.firstNonNull() returns the first object that is not null
> (equivalent to something that returns true if there is at least one object
> that is not null). The isNotNull() returns true if all objects are not null.
>
> Rafael Santini
>
> -----Mensagem Original----- From: Matt Benson
> Sent: Monday, July 08, 2013 1:20 PM
>
> To: Commons Developers List
> Subject: Re: Lang: ObjectUtils
>
> WRT #firstNonNull, I don't know why I couldn't find it before.  I do now,
> and I agree it would seem to fit better in ArrayUtils.
>
> Matt
>
>
> On Mon, Jul 8, 2013 at 10:04 AM, Jörg Schaible
> <Jo...@scalaris.com>**wrote:
>
>  Hi Matt,
>>
>> Matt Benson wrote:
>>
>> > On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
>> > <Jo...@scalaris.com>**wrote:
>> >
>> >> Hi Hen,
>> >>
>> >> Henri Yandell wrote:
>> >>
>> >> > I don't see any value having the first two methods - replacing the
>> '=='
>> >> > sign is a bit too far in the 'provide simple methods' direction I
>> think
>> >> :)
>> >> >
>> >> > I think the third method is already in Lang as:
>> >> >
>> >> >     ArrayUtils.contains(array, null);
>> >>
>> >>
>> >> Well, no, this is not, what the method does!
>> >
>> >
>> > Correct, but to be fair, it's simple enough to use this method to
>> > implement
>> > the desired check.  Negate the result.
>> >
>> >
>> >> With Lang we could use now:
>> >>
>> >>     ObjectUtils.firstNotNull(**array) != null
>> >>
>> >
>> > I don't see such a method as this.
>>
>>
>> http://commons.apache.org/**proper/commons-lang/javadocs/**
>> api-release/org/apache/**commons/lang3/ObjectUtils.**html#firstNonNull(T<http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ObjectUtils.html#firstNonNull(T>
>> ..
>> .)
>>
>> > If it did exist, it still wouldn't
>> > implement the feature requested (check that no element of the array is
>> > null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.
>>
>> I've re-read the original code and you're right.
>>
>> - Jörg
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
>>
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
>
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: ObjectUtils

Posted by Rafael Santini <ra...@santini.eti.br>.
Hi,

The proposed method is related to objects. As we have StringUtils.isBlank(), 
isNotBlank(), isEmpty() etc., the ObjectUtils.isNotNull(Object... objs) is 
intended to check if all objects are not null. So, instead of

if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
    // Do something...
}

we have

if (isNotNull(obj1, obj2, obj3, obj4) {
    // Do something...
}

The StringUtils.firstNonNull() returns the first object that is not null 
(equivalent to something that returns true if there is at least one object 
that is not null). The isNotNull() returns true if all objects are not null.

Rafael Santini

-----Mensagem Original----- 
From: Matt Benson
Sent: Monday, July 08, 2013 1:20 PM
To: Commons Developers List
Subject: Re: Lang: ObjectUtils

WRT #firstNonNull, I don't know why I couldn't find it before.  I do now,
and I agree it would seem to fit better in ArrayUtils.

Matt


On Mon, Jul 8, 2013 at 10:04 AM, Jörg Schaible
<Jo...@scalaris.com>wrote:

> Hi Matt,
>
> Matt Benson wrote:
>
> > On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
> > <Jo...@scalaris.com>wrote:
> >
> >> Hi Hen,
> >>
> >> Henri Yandell wrote:
> >>
> >> > I don't see any value having the first two methods - replacing the
> '=='
> >> > sign is a bit too far in the 'provide simple methods' direction I
> think
> >> :)
> >> >
> >> > I think the third method is already in Lang as:
> >> >
> >> >     ArrayUtils.contains(array, null);
> >>
> >>
> >> Well, no, this is not, what the method does!
> >
> >
> > Correct, but to be fair, it's simple enough to use this method to
> > implement
> > the desired check.  Negate the result.
> >
> >
> >> With Lang we could use now:
> >>
> >>     ObjectUtils.firstNotNull(array) != null
> >>
> >
> > I don't see such a method as this.
>
>
> http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ObjectUtils.html#firstNonNull(T..
> .)
>
> > If it did exist, it still wouldn't
> > implement the feature requested (check that no element of the array is
> > null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.
>
> I've re-read the original code and you're right.
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> 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: ObjectUtils

Posted by Matt Benson <gu...@gmail.com>.
WRT #firstNonNull, I don't know why I couldn't find it before.  I do now,
and I agree it would seem to fit better in ArrayUtils.

Matt


On Mon, Jul 8, 2013 at 10:04 AM, Jörg Schaible
<Jo...@scalaris.com>wrote:

> Hi Matt,
>
> Matt Benson wrote:
>
> > On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
> > <Jo...@scalaris.com>wrote:
> >
> >> Hi Hen,
> >>
> >> Henri Yandell wrote:
> >>
> >> > I don't see any value having the first two methods - replacing the
> '=='
> >> > sign is a bit too far in the 'provide simple methods' direction I
> think
> >> :)
> >> >
> >> > I think the third method is already in Lang as:
> >> >
> >> >     ArrayUtils.contains(array, null);
> >>
> >>
> >> Well, no, this is not, what the method does!
> >
> >
> > Correct, but to be fair, it's simple enough to use this method to
> > implement
> > the desired check.  Negate the result.
> >
> >
> >> With Lang we could use now:
> >>
> >>     ObjectUtils.firstNotNull(array) != null
> >>
> >
> > I don't see such a method as this.
>
>
> http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ObjectUtils.html#firstNonNull(T..
> .)
>
> > If it did exist, it still wouldn't
> > implement the feature requested (check that no element of the array is
> > null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.
>
> I've re-read the original code and you're right.
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: Lang: ObjectUtils

Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi Matt,

Matt Benson wrote:

> On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
> <Jo...@scalaris.com>wrote:
> 
>> Hi Hen,
>>
>> Henri Yandell wrote:
>>
>> > I don't see any value having the first two methods - replacing the '=='
>> > sign is a bit too far in the 'provide simple methods' direction I think
>> :)
>> >
>> > I think the third method is already in Lang as:
>> >
>> >     ArrayUtils.contains(array, null);
>>
>>
>> Well, no, this is not, what the method does!
> 
> 
> Correct, but to be fair, it's simple enough to use this method to
> implement
> the desired check.  Negate the result.
> 
> 
>> With Lang we could use now:
>>
>>     ObjectUtils.firstNotNull(array) != null
>>
> 
> I don't see such a method as this.

http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ObjectUtils.html#firstNonNull(T...)

> If it did exist, it still wouldn't
> implement the feature requested (check that no element of the array is
> null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.

I've re-read the original code and you're right.

- Jörg


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


Re: Lang: ObjectUtils

Posted by Matt Benson <gu...@gmail.com>.
On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
<Jo...@scalaris.com>wrote:

> Hi Hen,
>
> Henri Yandell wrote:
>
> > I don't see any value having the first two methods - replacing the '=='
> > sign is a bit too far in the 'provide simple methods' direction I think
> :)
> >
> > I think the third method is already in Lang as:
> >
> >     ArrayUtils.contains(array, null);
>
>
> Well, no, this is not, what the method does!


Correct, but to be fair, it's simple enough to use this method to implement
the desired check.  Negate the result.


> With Lang we could use now:
>
>     ObjectUtils.firstNotNull(array) != null
>

I don't see such a method as this.  If it did exist, it still wouldn't
implement the feature requested (check that no element of the array is
null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.

Matt


>
> > Having a containsNull is semantically nice, but I'm not sure it's needed.
>
> The question is here more, why the method is part of ObjectUtils, since it
> operates on an Array and I did not find it immediately (and I am probably
> not alone).
>
> Cheers,
> Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: Lang: ObjectUtils

Posted by Jörg Schaible <Jo...@scalaris.com>.
Hi Hen,

Henri Yandell wrote:

> I don't see any value having the first two methods - replacing the '=='
> sign is a bit too far in the 'provide simple methods' direction I think :)
> 
> I think the third method is already in Lang as:
> 
>     ArrayUtils.contains(array, null);


Well, no, this is not, what the method does! With Lang we could use now:

    ObjectUtils.firstNotNull(array) != null


> Having a containsNull is semantically nice, but I'm not sure it's needed.

The question is here more, why the method is part of ObjectUtils, since it 
operates on an Array and I did not find it immediately (and I am probably 
not alone).

Cheers,
Jörg


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


Re: Lang: ObjectUtils

Posted by Henri Yandell <fl...@gmail.com>.
I don't see any value having the first two methods - replacing the '=='
sign is a bit too far in the 'provide simple methods' direction I think :)

I think the third method is already in Lang as:

    ArrayUtils.contains(array, null);

Having a containsNull is semantically nice, but I'm not sure it's needed.

Hen

On Thu, Jul 4, 2013 at 11:43 AM, Rafael Santini <ra...@santini.eti.br>wrote:

> Hi,
>
> I would like to propose a method in ObjectUtils class that receives an
> array of objects and returns true if all objects are not null. I have
> implemented the following:
>
> public static boolean isNull(Object object) {
>    return object == null;
> }
>
> public static boolean isNotNull(Object object) {
>    return isNull(object) == false;
> }
>
> public static boolean isNotNull(Object... objects) {
>    for (Object object : objects) {
>        if (isNull(object)) {
>            return false;
>        }
>    }
>    return true;
> }
>
> Can I submit a patch for this feature?
>
> Thanks,
>
> Rafael Santini
>
>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: Lang: ObjectUtils

Posted by Duncan Jones <du...@wortharead.com>.
On 4 July 2013 19:43, Rafael Santini <ra...@santini.eti.br> wrote:
> Hi,
>
> I would like to propose a method in ObjectUtils class that receives an array
> of objects and returns true if all objects are not null. I have implemented
> the following:
>
> public static boolean isNull(Object object) {
>    return object == null;
> }
>
> public static boolean isNotNull(Object object) {
>    return isNull(object) == false;
> }
>
> public static boolean isNotNull(Object... objects) {
>    for (Object object : objects) {
>        if (isNull(object)) {
>            return false;
>        }
>    }
>    return true;
> }
>
> Can I submit a patch for this feature?

To directly answer your question, patches should be submitted as an
enhancement request on the issue tracking system
(http://commons.apache.org/proper/commons-lang/issue-tracking.html).
Please include thorough unit tests in your patch.

Duncan

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


Re: Lang: ObjectUtils

Posted by Anshul Zunke <an...@gmail.com>.
I second Ted. Do we really need this function at all? Just for the sake of
adding a piece of code should not run the purpose of adding an API
function.


On Fri, Jul 5, 2013 at 1:24 AM, Benedikt Ritter <br...@apache.org> wrote:

> You could do this with with CollectionsUtils from [Collections].
> But I think we all agree that implementing a Predicate inline is a lot more
> verbose than the proposed method.
>
>
> 2013/7/4 Ted Dunning <te...@gmail.com>
>
> > A bigger question is why this is needed at all.
> >
> > Why not just use composition?  In guava, one would do this:
> >
> >         Iterables.all(Arrays.asList(foo), new Predicate<Double>() {
> >             @Override
> >             public boolean apply(Double input) {
> >                 return input != null;
> >             }
> >         });
> >
> > Surely the same is already possible with commons.
> >
> >
> >
> > On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <dbrosius@mebigfatguy.com
> > >wrote:
> >
> > > This implies that having arrays with some null elements is
> > >
> > > a) somewhat common
> > > 2) a good idea
> > >
> > >
> > > I'd say both are not true.
> > >
> > > I'm not sure the library should promote that the above is the case.
> > >
> > >
> > >
> > > On 07/04/2013 02:43 PM, Rafael Santini wrote:
> > >
> > >> Hi,
> > >>
> > >> I would like to propose a method in ObjectUtils class that receives an
> > >> array of objects and returns true if all objects are not null. I have
> > >> implemented the following:
> > >>
> > >> public static boolean isNull(Object object) {
> > >>    return object == null;
> > >> }
> > >>
> > >> public static boolean isNotNull(Object object) {
> > >>    return isNull(object) == false;
> > >> }
> > >>
> > >> public static boolean isNotNull(Object... objects) {
> > >>    for (Object object : objects) {
> > >>        if (isNull(object)) {
> > >>            return false;
> > >>        }
> > >>    }
> > >>    return true;
> > >> }
> > >>
> > >> Can I submit a patch for this feature?
> > >>
> > >> Thanks,
> > >>
> > >> Rafael Santini
> > >>
> > >>
> > >>
> > >>
> > >>
> > ------------------------------**------------------------------**---------
> > >> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<
> > dev-unsubscribe@commons.apache.org>
> > >> For additional commands, e-mail: dev-help@commons.apache.org
> > >>
> > >>
> > >>
> > >
> > >
> ------------------------------**------------------------------**---------
> > > To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<
> > dev-unsubscribe@commons.apache.org>
> > > For additional commands, e-mail: dev-help@commons.apache.org
> > >
> > >
> >
>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter
>



-- 
Anshul Zunke

Re: Lang: ObjectUtils

Posted by Jörg Schaible <Jo...@scalaris.com>.
Benedikt Ritter wrote:

> You could do this with with CollectionsUtils from [Collections].
> But I think we all agree that implementing a Predicate inline is a lot
> more verbose than the proposed method.

+1

We have traditionally such convenience methods in lang.

When I look at the current arguments, we would have to deprecate and remove  
StingUtils.isEmpty().

Cheers,
Jörg


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


Re: Lang: ObjectUtils

Posted by Benedikt Ritter <br...@apache.org>.
You could do this with with CollectionsUtils from [Collections].
But I think we all agree that implementing a Predicate inline is a lot more
verbose than the proposed method.


2013/7/4 Ted Dunning <te...@gmail.com>

> A bigger question is why this is needed at all.
>
> Why not just use composition?  In guava, one would do this:
>
>         Iterables.all(Arrays.asList(foo), new Predicate<Double>() {
>             @Override
>             public boolean apply(Double input) {
>                 return input != null;
>             }
>         });
>
> Surely the same is already possible with commons.
>
>
>
> On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <dbrosius@mebigfatguy.com
> >wrote:
>
> > This implies that having arrays with some null elements is
> >
> > a) somewhat common
> > 2) a good idea
> >
> >
> > I'd say both are not true.
> >
> > I'm not sure the library should promote that the above is the case.
> >
> >
> >
> > On 07/04/2013 02:43 PM, Rafael Santini wrote:
> >
> >> Hi,
> >>
> >> I would like to propose a method in ObjectUtils class that receives an
> >> array of objects and returns true if all objects are not null. I have
> >> implemented the following:
> >>
> >> public static boolean isNull(Object object) {
> >>    return object == null;
> >> }
> >>
> >> public static boolean isNotNull(Object object) {
> >>    return isNull(object) == false;
> >> }
> >>
> >> public static boolean isNotNull(Object... objects) {
> >>    for (Object object : objects) {
> >>        if (isNull(object)) {
> >>            return false;
> >>        }
> >>    }
> >>    return true;
> >> }
> >>
> >> Can I submit a patch for this feature?
> >>
> >> Thanks,
> >>
> >> Rafael Santini
> >>
> >>
> >>
> >>
> >>
> ------------------------------**------------------------------**---------
> >> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<
> dev-unsubscribe@commons.apache.org>
> >> For additional commands, e-mail: dev-help@commons.apache.org
> >>
> >>
> >>
> >
> > ------------------------------**------------------------------**---------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<
> dev-unsubscribe@commons.apache.org>
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
> >
>



-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Re: ObjectUtils

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Contains(null) doesnt test all values
Le 5 juil. 2013 05:21, "Julien Aymé" <ju...@gmail.com> a écrit :

> Hi,
>
> Instead of using a predicate, wouldn't it be simpler to just use
> if (false == Arrays.asList(obj1, obj2, ...).contains(null)) ?
>
> Just my 2 cents,
> Julien
>
> 2013/7/5 Romain Manni-Bucau <rm...@gmail.com>:
> > Hi
> >
> > I'd just provide a IsNullPredicate class (a singleton) and then use
> > commons-collection to select the subcollection and if size is 0 or
> original
> > size (depend what you test) it would be true
> >
> > That said with next java version it will be quite useless IMO
> > Le 4 juil. 2013 22:04, "Rafael Santini" <ra...@santini.eti.br> a écrit
> :
> >
> >> Hi Ted,
> >>
> >> I have some codes that needs to test whether a set of objects are all
> true
> >> or not. For example:
> >>
> >> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
> >>    // Do something...
> >> }
> >>
> >> So, for readability reason, I have replaced for:
> >>
> >> if (isNotTrue(obj1, obj2, obj3, obj4) {
> >>    // Do something...
> >> }
> >>
> >> So I would like something like the isNotNull(Object... objects) method
> in
> >> Commons Lang instead of maintain this method in my own framework.
> >>
> >> Thanks,
> >>
> >> Rafael Santini
> >>
> >> -----Mensagem Original----- From: Ted Dunning
> >> Sent: Thursday, July 04, 2013 4:34 PM
> >> To: Commons Developers List
> >> Subject: Re: Lang: ObjectUtils
> >>
> >> A bigger question is why this is needed at all.
> >>
> >> Why not just use composition?  In guava, one would do this:
> >>
> >>        Iterables.all(Arrays.asList(**foo), new Predicate<Double>() {
> >>            @Override
> >>            public boolean apply(Double input) {
> >>                return input != null;
> >>            }
> >>        });
> >>
> >> Surely the same is already possible with commons.
> >>
> >>
> >>
> >> On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <dbrosius@mebigfatguy.com
> >**
> >> wrote:
> >>
> >>  This implies that having arrays with some null elements is
> >>>
> >>> a) somewhat common
> >>> 2) a good idea
> >>>
> >>>
> >>> I'd say both are not true.
> >>>
> >>> I'm not sure the library should promote that the above is the case.
> >>>
> >>>
> >>>
> >>> On 07/04/2013 02:43 PM, Rafael Santini wrote:
> >>>
> >>>  Hi,
> >>>>
> >>>> I would like to propose a method in ObjectUtils class that receives an
> >>>> array of objects and returns true if all objects are not null. I have
> >>>> implemented the following:
> >>>>
> >>>> public static boolean isNull(Object object) {
> >>>>    return object == null;
> >>>> }
> >>>>
> >>>> public static boolean isNotNull(Object object) {
> >>>>    return isNull(object) == false;
> >>>> }
> >>>>
> >>>> public static boolean isNotNull(Object... objects) {
> >>>>    for (Object object : objects) {
> >>>>        if (isNull(object)) {
> >>>>            return false;
> >>>>        }
> >>>>    }
> >>>>    return true;
> >>>> }
> >>>>
> >>>> Can I submit a patch for this feature?
> >>>>
> >>>> Thanks,
> >>>>
> >>>> Rafael Santini
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> ------------------------------****----------------------------**
> >>>> --**---------
> >>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<
> http://apache.org>
> >>>> <dev-unsubscribe@**commons.apache.org<
> dev-unsubscribe@commons.apache.org>
> >>>> >
> >>>> For additional commands, e-mail: dev-help@commons.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>> ------------------------------****----------------------------**
> >>> --**---------
> >>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<
> http://apache.org>
> >>> <dev-unsubscribe@**commons.apache.org<
> dev-unsubscribe@commons.apache.org>
> >>> >
> >>> For additional commands, e-mail: dev-help@commons.apache.org
> >>>
> >>>
> >>>
> >>
> >>
> ------------------------------**------------------------------**---------
> >> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<
> 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: ObjectUtils

Posted by Romain Manni-Bucau <rm...@gmail.com>.
But you cant test all are null this way...maybe not that important
Le 5 juil. 2013 07:15, "Dave Brosius" <db...@mebigfatguy.com> a écrit :

> Nice. Seems like the right solution.
>
> On 07/04/2013 11:20 PM, Julien Aymé wrote:
>
>> Hi,
>>
>> Instead of using a predicate, wouldn't it be simpler to just use
>> if (false == Arrays.asList(obj1, obj2, ...).contains(null)) ?
>>
>> Just my 2 cents,
>> Julien
>>
>> 2013/7/5 Romain Manni-Bucau <rm...@gmail.com>:
>>
>>> Hi
>>>
>>> I'd just provide a IsNullPredicate class (a singleton) and then use
>>> commons-collection to select the subcollection and if size is 0 or
>>> original
>>> size (depend what you test) it would be true
>>>
>>> That said with next java version it will be quite useless IMO
>>> Le 4 juil. 2013 22:04, "Rafael Santini" <ra...@santini.eti.br> a écrit
>>> :
>>>
>>>  Hi Ted,
>>>>
>>>> I have some codes that needs to test whether a set of objects are all
>>>> true
>>>> or not. For example:
>>>>
>>>> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>>>>     // Do something...
>>>> }
>>>>
>>>> So, for readability reason, I have replaced for:
>>>>
>>>> if (isNotTrue(obj1, obj2, obj3, obj4) {
>>>>     // Do something...
>>>> }
>>>>
>>>> So I would like something like the isNotNull(Object... objects) method
>>>> in
>>>> Commons Lang instead of maintain this method in my own framework.
>>>>
>>>> Thanks,
>>>>
>>>> Rafael Santini
>>>>
>>>> -----Mensagem Original----- From: Ted Dunning
>>>> Sent: Thursday, July 04, 2013 4:34 PM
>>>> To: Commons Developers List
>>>> Subject: Re: Lang: ObjectUtils
>>>>
>>>> A bigger question is why this is needed at all.
>>>>
>>>> Why not just use composition?  In guava, one would do this:
>>>>
>>>>         Iterables.all(Arrays.asList(****foo), new Predicate<Double>() {
>>>>             @Override
>>>>             public boolean apply(Double input) {
>>>>                 return input != null;
>>>>             }
>>>>         });
>>>>
>>>> Surely the same is already possible with commons.
>>>>
>>>>
>>>>
>>>> On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <dbrosius@mebigfatguy.com
>>>> >**
>>>> wrote:
>>>>
>>>>   This implies that having arrays with some null elements is
>>>>
>>>>> a) somewhat common
>>>>> 2) a good idea
>>>>>
>>>>>
>>>>> I'd say both are not true.
>>>>>
>>>>> I'm not sure the library should promote that the above is the case.
>>>>>
>>>>>
>>>>>
>>>>> On 07/04/2013 02:43 PM, Rafael Santini wrote:
>>>>>
>>>>>   Hi,
>>>>>
>>>>>> I would like to propose a method in ObjectUtils class that receives an
>>>>>> array of objects and returns true if all objects are not null. I have
>>>>>> implemented the following:
>>>>>>
>>>>>> public static boolean isNull(Object object) {
>>>>>>     return object == null;
>>>>>> }
>>>>>>
>>>>>> public static boolean isNotNull(Object object) {
>>>>>>     return isNull(object) == false;
>>>>>> }
>>>>>>
>>>>>> public static boolean isNotNull(Object... objects) {
>>>>>>     for (Object object : objects) {
>>>>>>         if (isNull(object)) {
>>>>>>             return false;
>>>>>>         }
>>>>>>     }
>>>>>>     return true;
>>>>>> }
>>>>>>
>>>>>> Can I submit a patch for this feature?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Rafael Santini
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ------------------------------******--------------------------**--**
>>>>>> --**---------
>>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.****apac**he.org<
>>>>>> http://apache.org**>
>>>>>> <dev-unsubscribe@**commons.**apache.org <http://commons.apache.org><
>>>>>> dev-unsubscribe@**commons.apache.org<de...@commons.apache.org>
>>>>>> >
>>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>  ------------------------------******--------------------------**--**
>>>>> --**---------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.****apac**he.org<
>>>>> http://apache.org**>
>>>>> <dev-unsubscribe@**commons.**apache.org <http://commons.apache.org><
>>>>> dev-unsubscribe@**commons.apache.org<de...@commons.apache.org>
>>>>> >
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>>>
>>>>>
>>>>>  ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>>>> <de...@commons.apache.org>
>>>> >
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>>  ------------------------------**------------------------------**
>> ---------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: ObjectUtils

Posted by Dave Brosius <db...@mebigfatguy.com>.
Nice. Seems like the right solution.

On 07/04/2013 11:20 PM, Julien Aymé wrote:
> Hi,
>
> Instead of using a predicate, wouldn't it be simpler to just use
> if (false == Arrays.asList(obj1, obj2, ...).contains(null)) ?
>
> Just my 2 cents,
> Julien
>
> 2013/7/5 Romain Manni-Bucau <rm...@gmail.com>:
>> Hi
>>
>> I'd just provide a IsNullPredicate class (a singleton) and then use
>> commons-collection to select the subcollection and if size is 0 or original
>> size (depend what you test) it would be true
>>
>> That said with next java version it will be quite useless IMO
>> Le 4 juil. 2013 22:04, "Rafael Santini" <ra...@santini.eti.br> a écrit :
>>
>>> Hi Ted,
>>>
>>> I have some codes that needs to test whether a set of objects are all true
>>> or not. For example:
>>>
>>> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>>>     // Do something...
>>> }
>>>
>>> So, for readability reason, I have replaced for:
>>>
>>> if (isNotTrue(obj1, obj2, obj3, obj4) {
>>>     // Do something...
>>> }
>>>
>>> So I would like something like the isNotNull(Object... objects) method in
>>> Commons Lang instead of maintain this method in my own framework.
>>>
>>> Thanks,
>>>
>>> Rafael Santini
>>>
>>> -----Mensagem Original----- From: Ted Dunning
>>> Sent: Thursday, July 04, 2013 4:34 PM
>>> To: Commons Developers List
>>> Subject: Re: Lang: ObjectUtils
>>>
>>> A bigger question is why this is needed at all.
>>>
>>> Why not just use composition?  In guava, one would do this:
>>>
>>>         Iterables.all(Arrays.asList(**foo), new Predicate<Double>() {
>>>             @Override
>>>             public boolean apply(Double input) {
>>>                 return input != null;
>>>             }
>>>         });
>>>
>>> Surely the same is already possible with commons.
>>>
>>>
>>>
>>> On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <db...@mebigfatguy.com>**
>>> wrote:
>>>
>>>   This implies that having arrays with some null elements is
>>>> a) somewhat common
>>>> 2) a good idea
>>>>
>>>>
>>>> I'd say both are not true.
>>>>
>>>> I'm not sure the library should promote that the above is the case.
>>>>
>>>>
>>>>
>>>> On 07/04/2013 02:43 PM, Rafael Santini wrote:
>>>>
>>>>   Hi,
>>>>> I would like to propose a method in ObjectUtils class that receives an
>>>>> array of objects and returns true if all objects are not null. I have
>>>>> implemented the following:
>>>>>
>>>>> public static boolean isNull(Object object) {
>>>>>     return object == null;
>>>>> }
>>>>>
>>>>> public static boolean isNotNull(Object object) {
>>>>>     return isNull(object) == false;
>>>>> }
>>>>>
>>>>> public static boolean isNotNull(Object... objects) {
>>>>>     for (Object object : objects) {
>>>>>         if (isNull(object)) {
>>>>>             return false;
>>>>>         }
>>>>>     }
>>>>>     return true;
>>>>> }
>>>>>
>>>>> Can I submit a patch for this feature?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Rafael Santini
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ------------------------------****----------------------------**
>>>>> --**---------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>>>>> <de...@commons.apache.org>
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>> ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>>>> <de...@commons.apache.org>
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>>
>>> ------------------------------**------------------------------**---------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@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
>
>


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


Re: ObjectUtils

Posted by Julien Aymé <ju...@gmail.com>.
Hi,

Instead of using a predicate, wouldn't it be simpler to just use
if (false == Arrays.asList(obj1, obj2, ...).contains(null)) ?

Just my 2 cents,
Julien

2013/7/5 Romain Manni-Bucau <rm...@gmail.com>:
> Hi
>
> I'd just provide a IsNullPredicate class (a singleton) and then use
> commons-collection to select the subcollection and if size is 0 or original
> size (depend what you test) it would be true
>
> That said with next java version it will be quite useless IMO
> Le 4 juil. 2013 22:04, "Rafael Santini" <ra...@santini.eti.br> a écrit :
>
>> Hi Ted,
>>
>> I have some codes that needs to test whether a set of objects are all true
>> or not. For example:
>>
>> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>>    // Do something...
>> }
>>
>> So, for readability reason, I have replaced for:
>>
>> if (isNotTrue(obj1, obj2, obj3, obj4) {
>>    // Do something...
>> }
>>
>> So I would like something like the isNotNull(Object... objects) method in
>> Commons Lang instead of maintain this method in my own framework.
>>
>> Thanks,
>>
>> Rafael Santini
>>
>> -----Mensagem Original----- From: Ted Dunning
>> Sent: Thursday, July 04, 2013 4:34 PM
>> To: Commons Developers List
>> Subject: Re: Lang: ObjectUtils
>>
>> A bigger question is why this is needed at all.
>>
>> Why not just use composition?  In guava, one would do this:
>>
>>        Iterables.all(Arrays.asList(**foo), new Predicate<Double>() {
>>            @Override
>>            public boolean apply(Double input) {
>>                return input != null;
>>            }
>>        });
>>
>> Surely the same is already possible with commons.
>>
>>
>>
>> On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <db...@mebigfatguy.com>**
>> wrote:
>>
>>  This implies that having arrays with some null elements is
>>>
>>> a) somewhat common
>>> 2) a good idea
>>>
>>>
>>> I'd say both are not true.
>>>
>>> I'm not sure the library should promote that the above is the case.
>>>
>>>
>>>
>>> On 07/04/2013 02:43 PM, Rafael Santini wrote:
>>>
>>>  Hi,
>>>>
>>>> I would like to propose a method in ObjectUtils class that receives an
>>>> array of objects and returns true if all objects are not null. I have
>>>> implemented the following:
>>>>
>>>> public static boolean isNull(Object object) {
>>>>    return object == null;
>>>> }
>>>>
>>>> public static boolean isNotNull(Object object) {
>>>>    return isNull(object) == false;
>>>> }
>>>>
>>>> public static boolean isNotNull(Object... objects) {
>>>>    for (Object object : objects) {
>>>>        if (isNull(object)) {
>>>>            return false;
>>>>        }
>>>>    }
>>>>    return true;
>>>> }
>>>>
>>>> Can I submit a patch for this feature?
>>>>
>>>> Thanks,
>>>>
>>>> Rafael Santini
>>>>
>>>>
>>>>
>>>>
>>>> ------------------------------****----------------------------**
>>>> --**---------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>>>> <de...@commons.apache.org>
>>>> >
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>>
>>>>
>>> ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>>> <de...@commons.apache.org>
>>> >
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@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: ObjectUtils

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

I'd just provide a IsNullPredicate class (a singleton) and then use
commons-collection to select the subcollection and if size is 0 or original
size (depend what you test) it would be true

That said with next java version it will be quite useless IMO
Le 4 juil. 2013 22:04, "Rafael Santini" <ra...@santini.eti.br> a écrit :

> Hi Ted,
>
> I have some codes that needs to test whether a set of objects are all true
> or not. For example:
>
> if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
>    // Do something...
> }
>
> So, for readability reason, I have replaced for:
>
> if (isNotTrue(obj1, obj2, obj3, obj4) {
>    // Do something...
> }
>
> So I would like something like the isNotNull(Object... objects) method in
> Commons Lang instead of maintain this method in my own framework.
>
> Thanks,
>
> Rafael Santini
>
> -----Mensagem Original----- From: Ted Dunning
> Sent: Thursday, July 04, 2013 4:34 PM
> To: Commons Developers List
> Subject: Re: Lang: ObjectUtils
>
> A bigger question is why this is needed at all.
>
> Why not just use composition?  In guava, one would do this:
>
>        Iterables.all(Arrays.asList(**foo), new Predicate<Double>() {
>            @Override
>            public boolean apply(Double input) {
>                return input != null;
>            }
>        });
>
> Surely the same is already possible with commons.
>
>
>
> On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <db...@mebigfatguy.com>**
> wrote:
>
>  This implies that having arrays with some null elements is
>>
>> a) somewhat common
>> 2) a good idea
>>
>>
>> I'd say both are not true.
>>
>> I'm not sure the library should promote that the above is the case.
>>
>>
>>
>> On 07/04/2013 02:43 PM, Rafael Santini wrote:
>>
>>  Hi,
>>>
>>> I would like to propose a method in ObjectUtils class that receives an
>>> array of objects and returns true if all objects are not null. I have
>>> implemented the following:
>>>
>>> public static boolean isNull(Object object) {
>>>    return object == null;
>>> }
>>>
>>> public static boolean isNotNull(Object object) {
>>>    return isNull(object) == false;
>>> }
>>>
>>> public static boolean isNotNull(Object... objects) {
>>>    for (Object object : objects) {
>>>        if (isNull(object)) {
>>>            return false;
>>>        }
>>>    }
>>>    return true;
>>> }
>>>
>>> Can I submit a patch for this feature?
>>>
>>> Thanks,
>>>
>>> Rafael Santini
>>>
>>>
>>>
>>>
>>> ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>>> <de...@commons.apache.org>
>>> >
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>>
>>>
>> ------------------------------****----------------------------**
>> --**---------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apac**he.org<http://apache.org>
>> <de...@commons.apache.org>
>> >
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: ObjectUtils

Posted by Rafael Santini <ra...@santini.eti.br>.
Hi Ted,

I have some codes that needs to test whether a set of objects are all true 
or not. For example:

if (obj1 != null && obj2 != null && obj3 != null && obj4 != null) {
    // Do something...
}

So, for readability reason, I have replaced for:

if (isNotTrue(obj1, obj2, obj3, obj4) {
    // Do something...
}

So I would like something like the isNotNull(Object... objects) method in 
Commons Lang instead of maintain this method in my own framework.

Thanks,

Rafael Santini

-----Mensagem Original----- 
From: Ted Dunning
Sent: Thursday, July 04, 2013 4:34 PM
To: Commons Developers List
Subject: Re: Lang: ObjectUtils

A bigger question is why this is needed at all.

Why not just use composition?  In guava, one would do this:

        Iterables.all(Arrays.asList(foo), new Predicate<Double>() {
            @Override
            public boolean apply(Double input) {
                return input != null;
            }
        });

Surely the same is already possible with commons.



On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius 
<db...@mebigfatguy.com>wrote:

> This implies that having arrays with some null elements is
>
> a) somewhat common
> 2) a good idea
>
>
> I'd say both are not true.
>
> I'm not sure the library should promote that the above is the case.
>
>
>
> On 07/04/2013 02:43 PM, Rafael Santini wrote:
>
>> Hi,
>>
>> I would like to propose a method in ObjectUtils class that receives an
>> array of objects and returns true if all objects are not null. I have
>> implemented the following:
>>
>> public static boolean isNull(Object object) {
>>    return object == null;
>> }
>>
>> public static boolean isNotNull(Object object) {
>>    return isNull(object) == false;
>> }
>>
>> public static boolean isNotNull(Object... objects) {
>>    for (Object object : objects) {
>>        if (isNull(object)) {
>>            return false;
>>        }
>>    }
>>    return true;
>> }
>>
>> Can I submit a patch for this feature?
>>
>> Thanks,
>>
>> Rafael Santini
>>
>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: 
>> dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: 
> dev-unsubscribe@commons.**apache.org<de...@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: ObjectUtils

Posted by Ted Dunning <te...@gmail.com>.
A bigger question is why this is needed at all.

Why not just use composition?  In guava, one would do this:

        Iterables.all(Arrays.asList(foo), new Predicate<Double>() {
            @Override
            public boolean apply(Double input) {
                return input != null;
            }
        });

Surely the same is already possible with commons.



On Thu, Jul 4, 2013 at 12:23 PM, Dave Brosius <db...@mebigfatguy.com>wrote:

> This implies that having arrays with some null elements is
>
> a) somewhat common
> 2) a good idea
>
>
> I'd say both are not true.
>
> I'm not sure the library should promote that the above is the case.
>
>
>
> On 07/04/2013 02:43 PM, Rafael Santini wrote:
>
>> Hi,
>>
>> I would like to propose a method in ObjectUtils class that receives an
>> array of objects and returns true if all objects are not null. I have
>> implemented the following:
>>
>> public static boolean isNull(Object object) {
>>    return object == null;
>> }
>>
>> public static boolean isNotNull(Object object) {
>>    return isNull(object) == false;
>> }
>>
>> public static boolean isNotNull(Object... objects) {
>>    for (Object object : objects) {
>>        if (isNull(object)) {
>>            return false;
>>        }
>>    }
>>    return true;
>> }
>>
>> Can I submit a patch for this feature?
>>
>> Thanks,
>>
>> Rafael Santini
>>
>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: dev-unsubscribe@commons.**apache.org<de...@commons.apache.org>
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: Lang: ObjectUtils

Posted by Dave Brosius <db...@mebigfatguy.com>.
This implies that having arrays with some null elements is

a) somewhat common
2) a good idea


I'd say both are not true.

I'm not sure the library should promote that the above is the case.



On 07/04/2013 02:43 PM, Rafael Santini wrote:
> Hi,
>
> I would like to propose a method in ObjectUtils class that receives an 
> array of objects and returns true if all objects are not null. I have 
> implemented the following:
>
> public static boolean isNull(Object object) {
>    return object == null;
> }
>
> public static boolean isNotNull(Object object) {
>    return isNull(object) == false;
> }
>
> public static boolean isNotNull(Object... objects) {
>    for (Object object : objects) {
>        if (isNull(object)) {
>            return false;
>        }
>    }
>    return true;
> }
>
> Can I submit a patch for this feature?
>
> Thanks,
>
> Rafael Santini
>
>
>
>
> ---------------------------------------------------------------------
> 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