src.samples.java.ex.OI_Sample Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fb-contrib Show documentation
Show all versions of fb-contrib Show documentation
An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.
package ex;
import java.util.Date;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
public class OI_Sample {
public String useDelayedExecution(Optional o, String a, String b) {
return o.orElse(String.format("%s boo %s hiss", a, b));
}
public double useDelayedExecutionWithDouble(OptionalDouble o) {
return o.orElse(Math.pow(Math.PI, Math.exp(Math.E)));
}
public String checkingOptionalReference(Optional o) {
if (o == null) {
return "";
}
return o.get();
}
public String useImmediateExecution(Optional o, final String a) {
return o.orElseGet(() -> a);
}
public int useImmediateExecutionWithInt(OptionalInt o) {
return o.orElseGet(() -> 0);
}
public Optional useWrongOptional(Optional d) {
return Optional.of(3.14);
}
public Date orElseGetNull(Optional o) {
return o.orElseGet(null);
}
public String fpDelayedOK(Optional o, String a, String b) {
return o.orElseGet(() -> String.format("%s boo %s hiss", a, b));
}
public String fpImmediateOK(Optional o, final String a) {
return o.orElse(a);
}
public String fpStringAppendingIsTooCommon(Optional o, final String a, final String b) {
return o.orElse(a + b);
}
public Long fpBoxingIsTooCommon(Optional o) {
return o.orElse(0L);
}
}