List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:com.pinterest.teletraan.resource.Images.java
@GET public List<ImageBean> getImagesByAppname(@QueryParam("app") Optional<String> appName, @QueryParam("start") Optional<Integer> start, @QueryParam("size") Optional<Integer> size) throws Exception { return imageDAO.getImages(appName.orNull(), start.or(1), size.or(DEFAULT_PAGE_SIZE)); }
From source file:org.onos.yangtools.yang.model.repo.api.SourceIdentifier.java
/** * * Creates new YANG Schema source identifier. * * @param name Name of schema/*from w w w . jav a2 s . co m*/ * @param formattedRevision Revision of source in format YYYY-mm-dd. If not present, default value will be used. */ public SourceIdentifier(final String name, final Optional<String> formattedRevision) { this(name, formattedRevision.or(NOT_PRESENT_FORMATTED_REVISION)); }
From source file:com.addthis.hydra.job.web.resources.TaskResource.java
@GET @Path("/stop") @Produces(MediaType.APPLICATION_JSON)// w w w . j a va2 s .c om public Response stopTask(@QueryParam("job") Optional<String> jobId, @QueryParam("task") Optional<Integer> 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.web.resources.TaskResource.java
@GET @Path("/kill") @Produces(MediaType.APPLICATION_JSON)// w w w .j a va 2 s . c o m public Response killTask(@QueryParam("job") Optional<String> jobId, @QueryParam("task") Optional<Integer> 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:io.crate.operation.projectors.IterableRowEmitter.java
public IterableRowEmitter(RowReceiver rowReceiver, final Iterable<? extends Row> rows, Optional<Executor> executor) { this.rowReceiver = rowReceiver; this.rows = rows; this.rowsIt = rows.iterator(); this.resumeable = new ExecutorResumeHandle(executor.or(MoreExecutors.directExecutor()), this); }
From source file:com.voxelplugineering.voxelsniper.service.CommandHandlerService.java
@Override protected void _init() { Optional<String> pmsg = this.config.get("permissionsRequiredMessage", String.class); this.permissionMessage = pmsg.or("You lack the required permission for this command."); this.commands = Maps.newHashMap(); this.unique = Lists.newArrayList(); }
From source file:io.scigraph.owlapi.curies.CurieUtil.java
/*** * Returns the CURIE of an IRI, if mapped. * /*from ww w . j ava 2 s .co m*/ * @param iri * @return An {@link Optional} CURIE */ public Optional<String> getCurie(String iri) { Optional<String> candidate = Optional.absent(); for (String prefix : curieMap.inverse().keySet()) { if (checkNotNull(iri).startsWith(prefix) && candidate.or("").length() < prefix.length()) { candidate = Optional.of(prefix); } } if (candidate.isPresent()) { return Optional.of(String.format("%s:%s", curieMap.inverse().get(candidate.get()), iri.substring(candidate.get().length(), iri.length()))); } else { return Optional.absent(); } }
From source file:org.apache.rya.indexing.pcj.fluo.app.export.rya.RyaSubGraphExporter.java
private void insertTriples(TransactionBase tx, final Collection<RyaStatement> triples) { for (final RyaStatement triple : triples) { Optional<byte[]> visibility = Optional.fromNullable(triple.getColumnVisibility()); try {// ww w.j a va 2 s .co m tx.set(spoFormat(triple), FluoQueryColumns.TRIPLES, Bytes.of(visibility.or(new byte[0]))); } catch (final TripleRowResolverException e) { log.error("Could not convert a Triple into the SPO format: " + triple); } } }
From source file:com.arpnetworking.tsdcore.statistics.SumStatistic.java
/** * {@inheritDoc}//from w ww .j a v a 2 s . c om */ @Override public Quantity calculate(final List<Quantity> unorderedValues) { double sum = 0d; Optional<Unit> unit = Optional.absent(); for (final Quantity sample : unorderedValues) { sum += sample.getValue(); unit = unit.or(sample.getUnit()); } return new Quantity.Builder().setValue(sum).setUnit(unit.orNull()).build(); }
From source file:com.arpnetworking.tsdcore.statistics.MeanStatistic.java
/** * {@inheritDoc}/*from w w w . j av a 2s . c o m*/ */ @Override public Quantity calculate(final List<Quantity> orderedValues) { // TODO(vkoskela): Statistic calculation should be allowed to either fail or not return a quantity. [MAI-?] if (orderedValues.size() == 0) { return ZERO; } double sum = 0; Optional<Unit> unit = Optional.absent(); for (final Quantity sample : orderedValues) { sum += sample.getValue(); unit = unit.or(sample.getUnit()); } return new Quantity.Builder().setValue(sum / orderedValues.size()).setUnit(unit.orNull()).build(); }