Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-13 Thread Paul Sandoz
On Feb 12, 2015, at 10:16 PM, Louis Wasserman wrote: > Sure. The "if present":"if present else":"if absent" ratio is ~24:6:1. > Thanks! Given those rations i think we are good with just one extra method. I have added you as a reviewer. Paul.

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-12 Thread Paul Sandoz
On Feb 12, 2015, at 8:29 PM, Louis Wasserman wrote: > I'm not sure I can share hard numbers, but the ratio of > > if (optional.isPresent()) { > // non-returning statements here > } > > to > > if (optional.isPresent()) { // or negated > // non-returning statements here > } else { > //

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-12 Thread Daniel Fuchs
The new version looks good Paul! -- daniel On 2/12/15 6:50 PM, Paul Sandoz wrote: On Feb 12, 2015, at 3:50 PM, Daniel Fuchs wrote: Hi Paul, This looks good - I have noticed one copy/paste error in the javadoc though: OptionalInt.java: looks like the throws clause of ifPresent and ifPresen

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-12 Thread Paul Sandoz
On Feb 12, 2015, at 7:27 PM, Louis Wasserman wrote: > I get that ifPresent is already available; I'm curious if you examined how > often there is actually an "if absent" case in practice, relative to the > "only do something if present" case. > > If you don't have statistics, No, since this is

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-12 Thread Louis Wasserman
I get that ifPresent is already available; I'm curious if you examined how often there is actually an "if absent" case in practice, relative to the "only do something if present" case. If you don't have statistics, I could fairly easily get statistics on Google's codebase for what usages of Guava'

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-12 Thread Paul Sandoz
On Feb 12, 2015, at 7:00 PM, Louis Wasserman wrote: > How often does the case when you "have a lambda handy already" come up in > practice? If this leads to people using this method instead of ifPresent, > that seems wasteful. > A lambda bearing ifPresent is already "present" (sorry!) :-) t

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-12 Thread Paul Sandoz
On Feb 12, 2015, at 3:50 PM, Daniel Fuchs wrote: > Hi Paul, > > This looks good - I have noticed one copy/paste error in the javadoc > though: > > OptionalInt.java: > > looks like the throws clause of ifPresent and ifPresentOrElse have been > interverted: > > 138 * @throws NullPointerEx

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-12 Thread Daniel Fuchs
Hi Paul, This looks good - I have noticed one copy/paste error in the javadoc though: OptionalInt.java: looks like the throws clause of ifPresent and ifPresentOrElse have been interverted: 138 * @throws NullPointerException if a value is present and {@code action} is 139 * null, o

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-03 Thread Paul Sandoz
On Feb 3, 2015, at 4:47 PM, Stephen Colebourne wrote: > Can't say I've used isPresent() much, as map()/flatMap()/orElse() take > care of most use cases. > Yes, i suspect terminal action-based processing is less used than value transformation. > What is an issue is that the primitive optional

Re: RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-03 Thread Stephen Colebourne
Can't say I've used isPresent() much, as map()/flatMap()/orElse() take care of most use cases. What is an issue is that the primitive optional classes do not have ofNullable(), filter(), map() or flatMap(). It seems odd to be adding an additional new method to the primitive optional classes withou

RFR 8071670: java.util.Optional: please add a way to specify if-else behavior

2015-02-03 Thread Paul Sandoz
Hi, http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8071670-Optional-ifPresentOrElse/webrev/ Here is another tweak to Optional (and primitives) that has some weight: /** * If a value is present, perform the given action with the value, * otherwise perform the given empty-based action. * * @para