On Sat, Jul 18, 2020 at 5:06 PM Juraj Jurčo <jjurco...@gmail.com> wrote:

> Hi Rob,
> thanks for the proposal. Yes, you're right I can use this. I haven't seen
> it before nor realize it.
> It also evokes the question whether it's self explanatory. Maybe it was
> only me who didn't know it, but I haven't seen either of my colleagues use
> it.
> I see you can use also defaults as:
> Optional.ofNullable(object)
>     .map(ObjectType::getProperty).or(() -> Optional.of(DEFAULT_PROPERTY))
>     .orElse(null);
> It seems to me a bit heavy, but I agree, it's possible.
>
> So you would recommend not including it in the library?
>

Rob just showed you how to use the JRE to accomplish the same thing, so I
am sure we'd want to add something that is so similar in this component,
which is likely to cause confusion as to why use one vs. the other.

Gary


>
> Thanks,
> Juraj+
>
>
> On Sat, 18 Jul 2020 at 15:44, Rob Spoor <apa...@icemanx.nl> wrote:
>
> > Can't you just use java.util.Optional? That was added way back (ahum) in
> > Java 8.
> > Converting your example:
> >
> >      SubSubSubProperty value = Optional.ofNullable(object)
> >              .map(ObjectType::getProperty)
> >              .map(Property::getSubProperty)
> >              .map(SubProperty::getSubSubProperty)
> >              .map(SubSubProperty::getSubSubSubProperty)
> >              .orElse(null);
> >
> >
> > On 18/07/2020 14:28, Juraj Jurčo wrote:
> > > Hi guys,
> > > I'm new in this list and I would like to contribute to Apache commons.
> > > First of all I would like get some feedback if it makes sense to
> > contribute.
> > >
> > > Java is slow in implementation of null-safe operator however sometimes
> > it's
> > > really needed. So far I didn't find any implementation of this in any
> > > library and I think it can be useful for many developers.
> > >
> > > To the point, instead of writing something like:
> > >      if(object != null
> > >          && object.getProperty() != null
> > >          && object.getProperty().getSubProperty()  != null
> > >          && object.getProperty().getSubProperty().getSubSubProperty()
> !=
> > > null  ){
> > >        Object value =
> > >
> >
> object.getProperty().getSubProperty().getSubSubProperty().getSubSubSubProperty();
> > >      }
> > >
> > > I would like to turn it into something like this:
> > >      Object value = ObjectUtils
> > >          .nullish(object)
> > >          .nullish(object::getProperty)
> > >          .nullish(Property::getSubProperty)
> > >          .nullish(SubProperty::getSubSubProperty)
> > >          .get(SubSubProperty::getSubSubSubProperty);
> > >
> > > The idea is to return null in the case any property 'on the way'
> returns
> > > null. I can implement it with defaults as well.
> > >
> > > Do you have some objections to the implementation? Do you know if it
> > > already exists somewhere?
> > >
> > > Thanks for your feedback,
> > > best, Juraj+
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> > For additional commands, e-mail: dev-h...@commons.apache.org
> >
> >
>

Reply via email to