osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [LANG] Adding isEmpty and isNotEmpty methods to ObjectUtils


Hi Benedikt,

Yes, ObjectUtils.isEmpty(null) would return true. You can review the pull
request (https://github.com/apache/commons-lang/pull/342) if you'd like to
see the entire implementation in its current state.

Thanks and best regards,
Alexander

2018-08-17 15:41 GMT+03:00 Benedikt Ritter <britter@xxxxxxxxxx>:

> Hello Alexander,
>
> welcome to the mailing list and thanks for your contribution.
>
> Am Fr., 17. Aug. 2018 um 10:43 Uhr schrieb Alexander Tsvetkov <
> alexander.tsvetkov.93@xxxxxxxxx>:
>
> > Hi all,
> >
> > First of all, apologies if I have messed something up - this is my first
> > attempt at contributing to Apache.
> >
> > With that said, I'd like to propose adding two new methods to Commons
> > Lang's ObjectUtils class:
> >   - isEmpty()
> >   - isNotEmpty()
> >
> > These would check whether the object is empty (or not empty respectively)
> > based on its type:
> >   - CharSequence - Considered empty if its length is zero.
> >   - Array - Considered empty if its length is zero.
> >   - Collection - Considered empty if it has zero elements.
> >   - Map - Considered empty if it has zero key-value mappings.
> > The object would be considered "not-empty" if its type is not one of the
> > types mentioned above.
> >
> > There is an already existing method that does exactly this in Spring's
> > ObjectUtils (see
> >
> > https://github.com/spring-projects/spring-framework/blob/
> 2ac23badee02697c5eb87c46f955387b32a0d581/spring-core/src/
> main/java/org/springframework/util/ObjectUtils.java#L134
> > ),
> > but I think it would be helpful to people (myself and my team included)
> if
> > there was a similar method in Commons Lang's ObjectUtils. That way we
> > wouldn't have to add a dependency to Spring or re-implement the method in
> > our code base.
> >
> > What do you think?
> >
>
> sounds reasonable. How would you handle null inputs? For example
> StringUtils.isEmpty(null) == true, so I would expect the same behavior from
> ObjectUtils.isEmpty
>
> Regards,
> Benedikt
>
>
> >
> > I've opened a JIRA ticket and a GitHub pull request as well:
> > https://issues.apache.org/jira/browse/LANG-1411
> > https://github.com/apache/commons-lang/pull/342
> >
> > Best regards,
> > Alexander
> >
>