List of usage examples for java.util Optional ofNullable
@SuppressWarnings("unchecked") public static <T> Optional<T> ofNullable(T value)
From source file:io.curly.artifact.service.DefaultArtifactCommand.java
@Override @Loggable/*from ww w. j ava2s .c o m*/ @HystrixCommand(fallbackMethod = "defaultFindAllOwned", ignoreExceptions = IllegalStateException.class, commandProperties = @HystrixProperty(name = EXECUTION_ISOLATION, value = SEMAPHORE)) public Observable<Optional<Page<Artifact>>> findAllOwned(Pageable pageable, User user) { return new ObservableResult<Optional<Page<Artifact>>>() { @Override public Optional<Page<Artifact>> invoke() { return Optional.ofNullable(artifactService.findAllOwned(pageable, user)); } }; }
From source file:com.toptal.conf.SecurityUtils.java
/** * Authentication object.//from w w w . j a v a2 s. c o m * @return Authentication. */ private static Optional<Authentication> getAuthentication() { return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()); }
From source file:at.gridtec.lambda4j.function.bi.BiBooleanFunction.java
/** * Lifts a partial {@link BiBooleanFunction} into a total {@link BiBooleanFunction} that returns an {@link Optional} * result./* ww w. ja v a2 s .c o m*/ * * @param <R> The type of return value from the function * @param partial A function that is only defined for some values in its domain * @return A partial {@code BiBooleanFunction} lifted into a total {@code BiBooleanFunction} that returns an {@code * Optional} result. * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <R> BiBooleanFunction<Optional<R>> lift(@Nonnull final BiBooleanFunction<? extends R> partial) { Objects.requireNonNull(partial); return (value1, value2) -> Optional.ofNullable(partial.apply(value1, value2)); }
From source file:io.github.retz.db.Jobs.java
public Optional<Job> getJob(int id) throws SQLException, IOException { try (PreparedStatement p = conn.prepareStatement("SELECT json FROM jobs WHERE id=?")) { p.setInt(1, id);/*www.java2 s.co m*/ try (ResultSet res = p.executeQuery()) { if (res.next()) { String json = res.getString("json"); return Optional.ofNullable(mapper.readValue(json, Job.class)); } } } return Optional.empty(); }
From source file:utils.gce.GoogleComputeEngineClient.java
public void setZone(String zoneName) { GoogleComputeEngineClient.zoneName = Optional.ofNullable(zoneName); }
From source file:com.github.robozonky.app.runtime.LivenessCheck.java
@Override protected Optional<String> transform(final String source) { return Optional.ofNullable(source); }
From source file:com.devicehive.handler.command.CommandSubscribeRequestHandler.java
private Collection<DeviceCommand> findCommands(String device, Collection<String> names, Date timestamp) { return Optional.ofNullable(timestamp).map(t -> hazelcastService.find(null, names, Collections.singleton(device), LIMIT, t, null, null, DeviceCommand.class)) .orElse(Collections.emptyList()); }
From source file:at.gridtec.lambda4j.function.tri.TriFunction.java
/** * Lifts a partial {@link TriFunction} into a total {@link TriFunction} that returns an {@link Optional} result. * * @param <T> The type of the first argument to the function * @param <U> The type of the second argument to the function * @param <V> The type of the third argument to the function * @param <R> The type of return value from the function * @param partial A function that is only defined for some values in its domain * @return A partial {@code TriFunction} lifted into a total {@code TriFunction} that returns an {@code Optional} * result./*from w ww .ja v a 2 s . co m*/ * @throws NullPointerException If given argument is {@code null} */ @Nonnull static <T, U, V, R> TriFunction<T, U, V, Optional<R>> lift( @Nonnull final TriFunction<? super T, ? super U, ? super V, ? extends R> partial) { Objects.requireNonNull(partial); return (t, u, v) -> Optional.ofNullable(partial.apply(t, u, v)); }
From source file:fi.hsl.parkandride.core.service.PredictionService.java
private Optional<Predictor> getPredictor(String predictorType) { Optional<Predictor> predictor = Optional.ofNullable(predictorsByType.get(predictorType)); if (!predictor.isPresent()) { log.warn("Predictor {} not installed", predictorType); }/*from w w w. j a va2 s .c o m*/ return predictor; }
From source file:org.eclipse.hono.service.auth.device.CredentialsApiAuthProvider.java
/** * Registers a check that verifies connection to Hono's <em>Credentials</em> * service.// w ww . j a v a 2 s.c o m */ @Override public void registerReadinessChecks(final HealthCheckHandler readinessHandler) { readinessHandler.register("connected-to-credentials-service", status -> { Future<Boolean> checkResult = Optional.ofNullable(credentialsClient).map(client -> client.isConnected()) .orElse(Future.succeededFuture(Boolean.FALSE)); checkResult.map(connected -> { if (connected) { status.tryComplete(Status.OK()); } else { status.tryComplete(Status.KO()); } return null; }); }); }