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.BaseImages.java
@GET @Path("/basic") public Collection<BaseImageBean> getByBasic(@QueryParam("provider") String provider, @QueryParam("basic") Optional<Boolean> basic) throws Exception { return baseImageDAO.getByProviderAndBasic(provider, basic.or(true)); }
From source file:gobblin.util.ConfigUtils.java
/** * Convert all the keys that start with a <code>prefix</code> in {@link Properties} to a {@link Config} instance. * * <p>//from w w w. j av a2 s .c o m * This method will throw an exception if (1) the {@link Object#toString()} method of any two keys in the * {@link Properties} objects returns the same {@link String}, or (2) if any two keys are prefixes of one another, * see the Java Docs of {@link ConfigFactory#parseMap(Map)} for more details. * </p> * * @param properties the given {@link Properties} instance * @param prefix of keys to be converted * @return a {@link Config} instance */ public static Config propertiesToConfig(Properties properties, Optional<String> prefix) { Set<String> blacklistedKeys = new HashSet<>(); if (properties.containsKey(GOBBLIN_CONFIG_BLACKLIST_KEYS)) { blacklistedKeys = new HashSet<>(Splitter.on(',').omitEmptyStrings().trimResults() .splitToList(properties.getProperty(GOBBLIN_CONFIG_BLACKLIST_KEYS))); } Set<String> fullPrefixKeys = findFullPrefixKeys(properties, prefix); ImmutableMap.Builder<String, Object> immutableMapBuilder = ImmutableMap.builder(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { String entryKey = entry.getKey().toString(); if (StringUtils.startsWith(entryKey, prefix.or(StringUtils.EMPTY)) && !blacklistedKeys.contains(entryKey)) { if (fullPrefixKeys.contains(entryKey)) { entryKey = sanitizeFullPrefixKey(entryKey); } else if (entryKey.endsWith(STRIP_SUFFIX)) { throw new RuntimeException("Properties are not allowed to end in " + STRIP_SUFFIX); } immutableMapBuilder.put(entryKey, entry.getValue()); } } return ConfigFactory.parseMap(immutableMapBuilder.build()); }
From source file:org.jclouds.abiquo.domain.infrastructure.HypervisorType.java
public boolean hasEditableDatastores() { Optional<String> constraint = Optional.fromNullable(getConstraints().get("datastore_directory_editable")); return Boolean.parseBoolean(constraint.or("true")); }
From source file:com.tealcube.minecraft.bukkit.facecore.profile.PlayerJoinListener.java
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoinEvent(final PlayerJoinEvent event) { Optional<Profile> profileOptional = PlayerResolver.getInstance() .findProfile(event.getPlayer().getUniqueId()); Profile p = profileOptional.or(new Profile(event.getPlayer().getUniqueId(), event.getPlayer().getName())); if (!p.getName().equals(event.getPlayer().getName())) { p.setLastKnownName(p.getName()); p.setName(event.getPlayer().getName()); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override/*from w ww . ja v a 2s . c om*/ public void run() { MessageUtils.sendMessage(event.getPlayer(), "<yellow>You recently did a name change! You must access your chests before you get another name change or you won't be able to unlock them."); } }, 20L * 3); } PlayerResolver.getInstance().addProfile(p); }
From source file:org.locationtech.geogig.porcelain.RemoteListOp.java
/** * Executes the remote-list operation./* w w w. j a v a 2 s .co m*/ * * @return {@code List<Remote>} of all remotes found in the config database, may be empty. */ @Override protected ImmutableList<Remote> _call() { ConfigDatabase config = configDatabase(); List<String> remotes = config.getAllSubsections("remote"); List<Remote> allRemotes = new ArrayList<Remote>(); for (String remoteName : remotes) { String remoteSection = "remote." + remoteName; Optional<String> remoteFetchURL = config.get(remoteSection + ".url"); Optional<String> remoteFetch = config.get(remoteSection + ".fetch"); Optional<String> remoteMapped = config.get(remoteSection + ".mapped"); Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch"); Optional<String> remoteUserName = config.get(remoteSection + ".username"); Optional<String> remotePassword = config.get(remoteSection + ".password"); if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) { Optional<String> remotePushURL = config.get(remoteSection + ".pushurl"); allRemotes.add(new Remote(remoteName, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()), remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull(), remoteUserName.orNull(), remotePassword.orNull())); } } return ImmutableList.copyOf(allRemotes); }
From source file:com.facebook.buck.parser.JavaLibraryBuildRuleFactory.java
@Override protected void amendBuilder(AbstractBuildRuleBuilder abstractBuilder, BuildRuleFactoryParams params) throws NoSuchBuildTargetException { DefaultJavaLibraryRule.Builder builder = ((DefaultJavaLibraryRule.Builder) abstractBuilder); Optional<String> proguardConfig = params.getOptionalStringAttribute("proguard_config"); if (proguardConfig.isPresent()) { String proguardConfigFile = params.resolveFilePathRelativeToBuildFileDirectory(proguardConfig.get()); builder.setProguardConfig(proguardConfigFile); }//from w ww . j a v a2s . co m boolean exportDeps = params.getBooleanAttribute("export_deps"); builder.setExportDeps(exportDeps); extractAnnotationProcessorParameters(builder.getAnnotationProcessingBuilder(), builder, params); Optional<String> sourceLevel = params.getOptionalStringAttribute("source"); builder.setSourceLevel(sourceLevel.or(JavacOptionsUtil.DEFAULT_SOURCE_LEVEL)); Optional<String> targetLevel = params.getOptionalStringAttribute("target"); builder.setTargetLevel(targetLevel.or(JavacOptionsUtil.DEFAULT_TARGET_LEVEL)); }
From source file:springfox.documentation.swagger.schema.ApiModelPropertyPropertyBuilder.java
@Override public void apply(ModelPropertyContext context) { Optional<ApiModelProperty> annotation = Optional.absent(); if (context.getAnnotatedElement().isPresent()) { annotation = annotation.or(findApiModePropertyAnnotation(context.getAnnotatedElement().get())); }/* w w w. j ava2 s . co m*/ if (context.getBeanPropertyDefinition().isPresent()) { annotation = annotation .or(findPropertyAnnotation(context.getBeanPropertyDefinition().get(), ApiModelProperty.class)); } if (annotation.isPresent()) { context.getBuilder().allowableValues(annotation.transform(toAllowableValues()).orNull()) .required(annotation.transform(toIsRequired()).or(false)) .readOnly(annotation.transform(toIsReadOnly()).or(false)) .description(annotation.transform(toDescription()).orNull()) .isHidden(annotation.transform(toHidden()).or(false)) .type(annotation.transform(toType(context.getResolver())).orNull()) .position(annotation.transform(toPosition()).or(0)) .example(annotation.transform(toExample()).orNull()); } }
From source file:google.registry.rde.imports.RdeDomainInput.java
public RdeDomainInput(Optional<Integer> mapShards, String importBucketName, String importFileName) { this.numReaders = mapShards.or(DEFAULT_READERS); this.importBucketName = importBucketName; this.importFileName = importFileName; }
From source file:com.facebook.buck.cli.ProjectCommandOptions.java
public String getIde() { if (ide != null) { return ide; } else {/* w ww .jav a 2s . c o m*/ Optional<String> ide = getBuckConfig().getValue("project", "ide"); return ide.or(DEFAULT_IDE_VALUE); } }
From source file:org.geogit.api.porcelain.RemoteListOp.java
/** * Executes the remote-list operation.//w w w.j av a2 s.c om * * @return {@code List<Remote>} of all remotes found in the config database, may be empty. */ @Override public ImmutableList<Remote> call() { List<String> remotes = config.getAllSubsections("remote"); List<Remote> allRemotes = new ArrayList<Remote>(); for (String remoteName : remotes) { String remoteSection = "remote." + remoteName; Optional<String> remoteFetchURL = config.get(remoteSection + ".url"); Optional<String> remoteFetch = config.get(remoteSection + ".fetch"); Optional<String> remoteMapped = config.get(remoteSection + ".mapped"); Optional<String> remoteMappedBranch = config.get(remoteSection + ".mappedBranch"); if (remoteFetchURL.isPresent() && remoteFetch.isPresent()) { Optional<String> remotePushURL = config.get(remoteSection + ".pushurl"); allRemotes.add(new Remote(remoteName, remoteFetchURL.get(), remotePushURL.or(remoteFetchURL.get()), remoteFetch.get(), remoteMapped.or("false").equals("true"), remoteMappedBranch.orNull())); } } return ImmutableList.copyOf(allRemotes); }