List of usage examples for java.util Optional of
public static <T> Optional<T> of(T value)
From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.PerformanceSolver.java
public Optional<Double> evaluate(@NonNull SolutionPerJob solPerJob) { Optional<Double> returnValue = Optional.of(solPerJob.getThroughput()); if (solPerJob.getChanged()) { try {//from ww w.j a va 2s.c om putRemoteSubDirectory(solPerJob); Pair<List<File>, List<File>> pFiles = createWorkingFiles(solPerJob); String jobID = solPerJob.getId(); String directory = retrieveRemoteSubDirectory(solPerJob); Pair<Double, Boolean> result = run(pFiles, "class" + jobID, directory); delete(pFiles.getLeft()); if (connSettings.isCleanRemote()) cleanRemoteSubDirectory(directory); solPerJob.setError(result.getRight()); returnValue = Optional.of(result.getLeft()); removeRemoteSubDirectory(solPerJob); } catch (Exception e) { logger.error("Error in SPJ evaluation", e); solPerJob.setError(Boolean.TRUE); returnValue = Optional.empty(); } } return returnValue; }
From source file:org.trustedanalytics.cloud.cc.api.manageusers.CcOrgUser.java
@JsonIgnore public UUID getGuid() { Optional<CcOrgUser> user = Optional.of(this); return user.map(CcOrgUser::getMetadata).map(CcMetadata::getGuid).orElse(null); }
From source file:de.is24.aws.instancemetadataserver.RemoteHostRoleNameProducer.java
private Optional<String> unifyHamAndBerToPro(String rawLocTyp) { Matcher matcher = Pattern.compile("^((ber)|(ham))(.+)$").matcher(rawLocTyp); if (!matcher.find()) { return Optional.of(rawLocTyp); }//from ww w. j a v a2s .co m return Optional.ofNullable(matcher.group(4)).map((typ) -> "pro" + typ); }
From source file:org.lendingclub.mercator.aws.LaunchConfigScanner.java
@Override public Optional<String> computeArn(JsonNode n) { return Optional.of(n.path("aws_launchConfigurationARN").asText()); }
From source file:com.netflix.spinnaker.igor.config.LockManagerConfig.java
@Bean LockManager redisLockManager(Clock clock, Registry registry, ObjectMapper mapper, RedisClientDelegate redisClientDelegate) { return new RedisLockManager(null, // will fall back to running node name clock, registry, mapper, redisClientDelegate, Optional.of(lockManagerConfigProperties.getHeartbeatRateMillis()), Optional.of(lockManagerConfigProperties.getLeaseDurationMillis())); }
From source file:com.thoughtworks.go.server.persistence.ServerBackupRepository.java
public Optional<ServerBackup> lastSuccessfulBackup() { List results = (List) getHibernateTemplate().execute((HibernateCallback) session -> { Criteria criteria = session.createCriteria(ServerBackup.class); criteria.add(Restrictions.eq("status", BackupStatus.COMPLETED)); criteria.setMaxResults(1);/*from w w w . j a v a 2s . c om*/ criteria.addOrder(Order.desc("id")); return criteria.list(); }); return results.isEmpty() ? Optional.empty() : Optional.of((ServerBackup) results.get(0)); }
From source file:co.runrightfast.core.utils.ConfigUtils.java
static Optional<List<? extends Config>> getConfigList(final Config config, final String path, final String... paths) { if (!hasPath(config, path, paths)) { return Optional.empty(); }// w w w. ja v a 2 s . com return Optional.of(config.getConfigList(configPath(path, paths))); }
From source file:org.trustedanalytics.cloud.cc.api.CcServiceInstance.java
@JsonIgnore public UUID getServiceGuid() { Optional<CcServiceInstance> serviceInstance = Optional.of(this); return serviceInstance.map(CcServiceInstance::getServicePlan).map(CcServicePlan::getService) .map(CcService::getGuid).orElse(null); }
From source file:co.runrightfast.component.events.impl.ComponentEventFactoryImpl.java
@Override public ComponentEvent componentEvent(@NonNull final Event event, @NonNull final Throwable exception, final String... tags) { final ComponentEventImpl.ComponentEventImplBuilder builder = ComponentEventImpl.builder() .componentId(componentId).event(event).exception(Optional.of(exception)); if (ArrayUtils.isNotEmpty(tags)) { return builder.tags(Optional.of(ImmutableSet.copyOf(tags))).build(); }// w ww . java2s. co m return builder.build(); }
From source file:com.newtranx.util.monitoring.MonitorAspect.java
@Around("@annotation(com.newtranx.util.monitoring.Monitoring)") public Object around(final ProceedingJoinPoint pjp) throws Throwable { final MethodSignature signature = (MethodSignature) pjp.getSignature(); final Method method = getMethod(signature, pjp); final long begin = System.currentTimeMillis(); MonitorContext monitorContext = new MonitorContext() { @Override/*from w w w.j ava 2 s . c om*/ public void doReport() { long end = System.currentTimeMillis(); String name = method.getAnnotation(Monitoring.class).value().trim(); Optional<String> optName = StringUtils.isEmpty(name) ? Optional.empty() : Optional.of(name); for (Reporter r : reporters) { try { r.report(method, end - begin, optName); } catch (Throwable t) { t.printStackTrace(System.err); } } } }; Object[] args = pjp.getArgs(); AsyncHandler asyncHandler = null; for (AsyncHandler a : getAsyncHandlers()) { Object[] processedArgs = a.preProcess(method, args, monitorContext); if (monitorContext.isAsync()) { args = processedArgs; asyncHandler = a; break; } } Object result = pjp.proceed(args); if (monitorContext.isAsync()) { return asyncHandler.postProcess(result, monitorContext); } else { monitorContext.doReport(); return result; } }