List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:io.crate.operation.merge.IteratorPageDownstream.java
public IteratorPageDownstream(final RowReceiver rowReceiver, final PagingIterator<Void, Row> pagingIterator, Optional<Executor> executor) { this.pagingIterator = pagingIterator; lastIterator = pagingIterator;/*from ww w. jav a 2s . co m*/ this.executor = executor.or(MoreExecutors.directExecutor()); this.rowReceiver = rowReceiver; }
From source file:com.facebook.buck.shell.ExportFileRule.java
@VisibleForTesting ExportFileRule(CachingBuildRuleParams params, Optional<String> src, Optional<String> out) { super(params); String shortName = params.getBuildTarget().getShortName(); this.src = src.or(shortName); final String outName = out.or(shortName); this.out = Suppliers.memoize(new Supplier<File>() { @Override// ww w.j a v a 2 s . c om public File get() { String name = new File(outName).getName(); String outputPath = String.format("%s/%s%s", BuckConstant.GEN_DIR, getBuildTarget().getBasePathWithSlash(), name); return new File(outputPath); } }); }
From source file:com.pinterest.teletraan.resource.EnvCapacities.java
@GET public List<String> get(@PathParam("envName") String envName, @PathParam("stageName") String stageName, @QueryParam("capacityType") Optional<CapacityType> capacityType) throws Exception { EnvironBean envBean = Utils.getEnvStage(environDAO, envName, stageName); if (capacityType.or(CapacityType.GROUP) == CapacityType.GROUP) { return groupDAO.getCapacityGroups(envBean.getEnv_id()); } else {// ww w. j av a 2 s. co m return groupDAO.getCapacityHosts(envBean.getEnv_id()); } }
From source file:org.apache.usergrid.corepersistence.pipeline.read.search.AbstractElasticSearchFilter.java
@Override public Observable<FilterResult<Candidate>> call(final Observable<FilterResult<Id>> observable) { //get the graph manager final EntityIndex applicationEntityIndex = entityIndexFactory.createEntityIndex( indexLocationStrategyFactory.getIndexLocationStrategy(pipelineContext.getApplicationScope())); final int limit = pipelineContext.getLimit(); final SearchTypes searchTypes = getSearchTypes(); //return all ids that are emitted from this edge return observable.flatMap(idFilterResult -> { final SearchEdge searchEdge = getSearchEdge(idFilterResult.getValue()); final Observable<FilterResult<Candidate>> candidates = Observable.create(subscriber -> { //our offset to our start value. This will be set the first time we emit //after we receive new ids, we want to reset this to 0 //set our our constant state final Optional<Integer> startFromCursor = getSeekValue(); final int startOffset = startFromCursor.or(0); int currentOffSet = startOffset; subscriber.onStart();/*from ww w . jav a2 s . c o m*/ //emit while we have values from ES and someone is subscribed while (!subscriber.isUnsubscribed()) { try { final CandidateResults candidateResults = applicationEntityIndex.search(searchEdge, searchTypes, query, limit, currentOffSet); Collection<SelectFieldMapping> fieldMappingCollection = candidateResults .getGetFieldMappings(); for (CandidateResult candidateResult : candidateResults) { //our subscriber unsubscribed, break out if (subscriber.isUnsubscribed()) { return; } final Candidate candidate = new Candidate(candidateResult, searchEdge, fieldMappingCollection); final FilterResult<Candidate> result = createFilterResult(candidate, currentOffSet, idFilterResult.getPath()); subscriber.onNext(result); currentOffSet++; } /** * No candidates, we're done */ if (candidateResults.size() < limit) { subscriber.onCompleted(); return; } } catch (Throwable t) { logger.error("Unable to search candidates", t); subscriber.onError(t); } } }); //add a timer around our observable ObservableTimer.time(candidates, searchTimer); return candidates; }); }
From source file:com.facebook.buck.java.ExternalJavac.java
public ExternalJavac(final Path pathToJavac) { this.pathToJavac = pathToJavac; this.version = Suppliers.memoize(new Supplier<JavacVersion>() { @Override/* ww w . j a v a2 s . com*/ public JavacVersion get() { ProcessExecutorParams params = ProcessExecutorParams.builder() .setCommand(ImmutableList.of(pathToJavac.toString(), "-version")).build(); ProcessExecutor.Result result; try (PrintStream stdout = new PrintStream(new ByteArrayOutputStream()); PrintStream stderr = new PrintStream(new ByteArrayOutputStream())) { result = createProcessExecutor(stdout, stderr).launchAndExecute(params); } catch (InterruptedException | IOException e) { throw new RuntimeException(e); } Optional<String> stderr = result.getStderr(); String output = stderr.or("").trim(); if (Strings.isNullOrEmpty(output)) { return DEFAULT_VERSION; } else { return JavacVersion.of(output); } } }); }
From source file:com.pinterest.teletraan.resource.EnvHistory.java
@GET public List<ConfigHistoryBean> get(@PathParam("envName") String envName, @PathParam("stageName") String stageName, @QueryParam("pageIndex") Optional<Integer> pageIndex, @QueryParam("pageSize") Optional<Integer> pageSize) throws Exception { EnvironBean envBean = Utils.getEnvStage(environDAO, envName, stageName); return configHistoryDAO.getByConfigId(envBean.getEnv_id(), pageIndex.or(1), pageSize.or(DEFAULT_SIZE)); }
From source file:com.google.template.soy.jbcsrc.api.PrecompiledSoyModule.java
@Provides @Singleton/*from w w w.j a v a2s . c om*/ @Precompiled SoySauce provideSoySauce(SoySauceImpl.Factory factory, @Deltemplates Optional<ImmutableSet<String>> allDeltemplates, ImmutableMap<String, ? extends SoyFunction> functions, ImmutableMap<String, ? extends SoyPrintDirective> printDirectives) { return factory.create(new CompiledTemplates(allDeltemplates.or(ImmutableSet.<String>of())), functions, printDirectives); }
From source file:com.addthis.hydra.job.spawn.resources.TaskResource.java
@GET @Path("/stop") @Produces(MediaType.APPLICATION_JSON)/*w w w. ja v a2 s . c o m*/ public Response stopTask(@QueryParam("job") Optional<String> jobId, @QueryParam("task") Optional<Integer> task) { // emitLogLineForAction(kv, "stop task " + job + "/" + task); try { spawn.stopTask(jobId.or(""), task.or(-1)); return Response.ok().build(); } catch (Exception ex) { return Response.serverError().entity(ex.getMessage()).build(); } }
From source file:com.addthis.hydra.job.spawn.resources.TaskResource.java
@GET @Path("/kill") @Produces(MediaType.APPLICATION_JSON)/*from www. j a v a 2 s . com*/ public Response killTask(@QueryParam("job") Optional<String> jobId, @QueryParam("task") Optional<Integer> task) { // emitLogLineForAction(kv, "kill task " + job + "/" + task); try { spawn.killTask(jobId.or(""), task.or(-1)); return Response.ok().build(); } catch (Exception ex) { return Response.serverError().entity(ex.getMessage()).build(); } }
From source file:org.jclouds.rest.config.ReadAnnotationsAndProperties.java
@Override public Optional<Long> getTimeoutNanos(Invocation in) { String commandName = getCommandName(in); Optional<Long> defaultMillis = fromNullable(timeouts.get("default")); Optional<Long> timeoutMillis = fromNullable(timeouts.get(commandName)); Invokable<?, ?> invoked = in.getInvokable(); if (invoked.isAnnotationPresent(Named.class)) { timeoutMillis = timeoutMillis.or(defaultMillis); } else {/*from w ww . j a va2 s . c om*/ // TODO: remove old logic once Named annotations are on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); timeoutMillis = timeoutMillis.or(fromNullable(timeouts.get(className))).or(defaultMillis); } if (timeoutMillis.isPresent()) return Optional.of(MILLISECONDS.toNanos(timeoutMillis.get())); return Optional.absent(); }