List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:com.eucalyptus.util.CollectionUtils.java
public static <T> Function<Optional<T>, T> optionalOr(final T value) { return new Function<Optional<T>, T>() { @Nullable/*w ww.jav a 2s .co m*/ @Override public T apply(final Optional<T> optional) { return optional == null ? null : optional.or(value); } }; }
From source file:org.onos.yangtools.yang.model.util.ExtendedType.java
/** * * Creates Builder for extended / derived type. * * @param typeName QName of derived type * @param baseType Base type of derived type * @param description Description of type * @param reference Reference of Type/* w w w. j ava2 s . c om*/ * @param path Schema path to type definition. */ public static final Builder builder(final QName typeName, final TypeDefinition<?> baseType, final Optional<String> description, final Optional<String> reference, final SchemaPath path) { return new Builder(typeName, baseType, description.or(""), reference.or(""), path); }
From source file:eu.eubrazilcc.lvl.service.cache.SequenceGeolocationCache.java
private static FeatureCollection findNearbySequences(final String collection, final Point point, final double maxDistance, final boolean group, final boolean heatmap) { Optional<FeatureCollection> features = absent(); try {/*from ww w . ja v a2 s . c om*/ features = CACHE.get(key(collection, point, maxDistance, group, heatmap)); } catch (ExecutionException e) { LOGGER.error("Failed to get sequence geolocation from cache", e); } return features.or(FeatureCollection.builder().build()); }
From source file:org.apache.lens.server.common.RestAPITestUtil.java
public static Response postQuery(final WebTarget target, final Optional<LensSessionHandle> sessionId, final Optional<String> query, final Optional<String> operation, Optional<LensConf> lensConfOptional, MediaType mt) {//from ww w . ja v a 2 s .c o m FormDataMultiPart mp = FormDataMultiPartFactory.createFormDataMultiPartForQuery(sessionId, query, operation, lensConfOptional.or(new LensConf()), mt); return target.path("queryapi/queries").request(mt) .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE)); }
From source file:org.apache.aurora.scheduler.SchedulerModule.java
@VisibleForTesting static TierConfig parseTierConfig(Optional<String> config) { Optional<TierConfig> map = config.transform(input -> { try {/* w w w . j ava 2 s . com*/ return new ObjectMapper().readValue(input, TierConfig.class); } catch (IOException e) { LOG.error("Error parsing tier configuration file."); throw Throwables.propagate(e); } }); return map.or(TierConfig.EMPTY); }
From source file:storm.mesos.util.MesosCommon.java
public static String getNimbusHost(Map mesosStormConf) throws UnknownHostException { Optional<String> nimbusHostFromConfig = Optional .fromNullable((String) mesosStormConf.get(Config.NIMBUS_HOST)); Optional<String> nimbusHostFromEnv = Optional.fromNullable(System.getenv("MESOS_NIMBUS_HOST")); return nimbusHostFromConfig.or(nimbusHostFromEnv).or(InetAddress.getLocalHost().getCanonicalHostName()); }
From source file:org.apache.aurora.scheduler.base.CommandUtil.java
/** * Creates a description of a command that will fetch and execute the given URI to an executor * binary./*from w ww. j av a 2 s. c o m*/ * * @param executorUri A URI to the executor * @param executorResources A list of URIs to be fetched into the sandbox with the executor. * @param commandBasePath The relative base path of the executor. * @param extraArguments Extra command line arguments to add to the generated command. * @return A CommandInfo.Builder populated with resources and a command. */ public static CommandInfo.Builder create(String executorUri, List<String> executorResources, String commandBasePath, Optional<String> extraArguments) { Preconditions.checkNotNull(executorResources); MorePreconditions.checkNotBlank(executorUri); MorePreconditions.checkNotBlank(commandBasePath); CommandInfo.Builder builder = CommandInfo.newBuilder(); builder.addAllUris(Iterables.transform(executorResources, STRING_TO_URI_RESOURCE)); builder.addUris(STRING_TO_URI_RESOURCE.apply(executorUri)); String cmdLine = commandBasePath + uriBasename(executorUri) + " " + extraArguments.or(""); return builder.setValue(cmdLine.trim()); }
From source file:org.jclouds.rest.internal.TransformerForRequest.java
@SuppressWarnings("unchecked") private static Key<? extends Function<HttpResponse, ?>> getJAXBParserKeyForMethod(Invokable<?, ?> invoked) { Optional<Type> configuredReturnVal = Optional.absent(); if (invoked.isAnnotationPresent(JAXBResponseParser.class)) { Type configuredClass = invoked.getAnnotation(JAXBResponseParser.class).value(); configuredReturnVal = configuredClass.equals(NullType.class) ? Optional.<Type>absent() : Optional.<Type>of(configuredClass); }//from ww w .ja va 2 s.c o m Type returnVal = configuredReturnVal.or(getReturnTypeFor(invoked.getReturnType())); Type parserType = newParameterizedType(ParseXMLWithJAXB.class, returnVal); return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType); }
From source file:com.qcadoo.mes.orders.dates.OrderDates.java
public static ThreeLevelDate threeLevelDate(final Entity order, final String plannedDateFieldName, final String correctedDateFieldName, final String effectiveDateFieldName, final Optional<DateTime> defaultPlanned) { Optional<DateTime> plannedStart = tryExtractLocalDate(order, plannedDateFieldName); Preconditions.checkArgument(defaultPlanned.isPresent() || plannedStart.isPresent(), "You have to either pass an order with defined planned dates or provide the default values"); Optional<DateTime> correctedStart = tryExtractLocalDate(order, correctedDateFieldName); Optional<DateTime> effectiveStart = tryExtractLocalDate(order, effectiveDateFieldName); return new ThreeLevelDate(plannedStart.or(defaultPlanned).get(), correctedStart, effectiveStart); }
From source file:io.crate.analyze.relations.RelationNormalizer.java
@Nullable private static HavingClause pushHaving(Optional<HavingClause> childHaving, Optional<HavingClause> parentHaving) { assert !(childHaving.isPresent() && parentHaving.isPresent()) : "Cannot merge 'having' if exists in both parent and child relations"; return childHaving.or(parentHaving).orNull(); }