List of usage examples for com.google.common.base Optional or
@Beta public abstract T or(Supplier<? extends T> supplier);
From source file:com.arpnetworking.clusteraggregator.AggDataUnifier.java
private static Optional<Unit> getSmaller(final Optional<Unit> a, final Optional<Unit> b) { if (a.isPresent() && b.isPresent()) { return a.get().isSmallerThan(b.get()) ? a : b; } else {/* ww w . ja v a2 s . c o m*/ return a.or(b); } }
From source file:com.amazonaws.services.dynamodbv2.streams.connectors.CommandLineInterface.java
@VisibleForTesting static AwsClientBuilder.EndpointConfiguration createEndpointConfiguration(Region region, Optional<String> endpoint, String endpointPrefix) { return new AwsClientBuilder.EndpointConfiguration( endpoint.or("https://" + region.getServiceEndpoint(endpointPrefix)), region.getName()); }
From source file:zipkin.autoconfigure.storage.elasticsearch.http.ZipkinElasticsearchHttpStorageAutoConfiguration.java
public static Optional<String> regionFromAwsUrls(List<String> hosts) { Optional<String> awsRegion = Optional.absent(); for (String url : hosts) { Matcher matcher = AWS_URL.matcher(url); if (matcher.find()) { String matched = matcher.group(1); checkArgument(awsRegion.or(matched).equals(matched), "too many regions: saw '%s' and '%s'", awsRegion, matched); awsRegion = Optional.of(matcher.group(1)); } else {/*w w w . j a va 2 s . c o m*/ checkArgument(!awsRegion.isPresent(), "mismatched regions; saw '%s' but no awsRegion found in '%s'", awsRegion.orNull(), url); } } return awsRegion; }
From source file:org.openqa.selenium.safari.SafariDriverExtension.java
/** * @param customDataDir Location of the data directory for a custom Safari * installation. If omitted, t/*from w w w . ja va2 s. c om*/ * @return The directory that the SafariDriver extension should be installed * to for the current platform. * @throws IllegalStateException If the extension cannot be installed on the * current platform. * @throws IOException If an I/O error occurs. */ private static File getInstallDirectory(Optional<File> customDataDir) throws IOException { File dataDir = customDataDir.or(getSafariDataDirectory()); checkState(dataDir.isDirectory(), "The expected Safari data directory does not exist: %s", dataDir.getAbsolutePath()); File extensionsDir = new File(dataDir, "Extensions"); if (!extensionsDir.isDirectory()) { extensionsDir.mkdir(); } return extensionsDir; }
From source file:eu.eubrazilcc.lvl.service.cache.StatisticsCache.java
public static Map<String, List<SimpleStat>> sandflyStats() { Optional<Map<String, List<SimpleStat>>> stats = absent(); try {//from w w w .ja v a2 s. co m stats = CACHE.get(SANDFLY_COLLECTION); } catch (ExecutionException e) { LOGGER.error("Failed to get collection statistics from cache", e); } return stats.or(new Hashtable<String, List<SimpleStat>>()); }
From source file:eu.eubrazilcc.lvl.service.cache.StatisticsCache.java
public static Map<String, List<SimpleStat>> leishmaniaStats() { Optional<Map<String, List<SimpleStat>>> stats = absent(); try {//ww w . j av a 2 s. c o m stats = CACHE.get(LEISHMANIA_COLLECTION); } catch (ExecutionException e) { LOGGER.error("Failed to get collection statistics from cache", e); } return stats.or(new Hashtable<String, List<SimpleStat>>()); }
From source file:org.locationtech.geogig.storage.postgresql.PGCache.java
public static PGCache build(ConfigDatabase configdb) { Optional<Long> maxSize = configdb.getGlobal(Environment.KEY_ODB_BYTE_CACHE_MAX_SIZE, Long.class); Optional<Integer> concurrencyLevel = configdb.getGlobal(Environment.KEY_ODB_BYTE_CACHE_CONCURRENCY_LEVEL, Integer.class); Optional<Integer> expireSeconds = configdb.getGlobal(Environment.KEY_ODB_BYTE_CACHE_EXPIRE_SECONDS, Integer.class); Optional<Integer> initialCapacity = configdb.getGlobal(Environment.KEY_ODB_BYTE_CACHE_INITIAL_CAPACITY, Integer.class); Integer initialCapacityCount = initialCapacity.or(1_000_000); Integer concurrencyLevel2 = concurrencyLevel.or(16); Long maxWeightBytes = maxSize.or(defaultCacheSize()); return build(initialCapacityCount, concurrencyLevel2, maxWeightBytes, expireSeconds); }
From source file:zipkin.autoconfigure.storage.elasticsearch.aws.ZipkinElasticsearchAwsStorageAutoConfiguration.java
static Optional<String> regionFromAwsUrls(List<String> hosts) { Optional<String> awsRegion = Optional.absent(); for (String url : hosts) { Matcher matcher = AWS_URL.matcher(url); if (matcher.find()) { String matched = matcher.group(1); checkArgument(awsRegion.or(matched).equals(matched), "too many regions: saw '%s' and '%s'", awsRegion, matched); awsRegion = Optional.of(matcher.group(1)); } else {/* w w w. j av a 2s . c o m*/ checkArgument(!awsRegion.isPresent(), "mismatched regions; saw '%s' but no awsRegion found in '%s'", awsRegion.orNull(), url); } } return awsRegion; }
From source file:com.publicuhc.pluginframework.util.YamlUtil.java
/** * Loads the given file from the harddrive with it's defaults set to the JAR version (and saved to the HDD) * * @param path the path to the file to load * @param loader the classloader to load from * @param dataDir the directory to save/load from * * @return optional fileconfiguration. Absent if jar AND hdd version don't exist * @throws IOException//from w ww. j a va 2 s. co m * @throws InvalidConfigurationException if HDD or JAR file failed to parse */ public static Optional<FileConfiguration> loadConfigWithDefaults(String path, ClassLoader loader, File dataDir) throws IOException, InvalidConfigurationException { Optional<YamlConfiguration> jarOptional = YamlUtil.loadYamlFromJAR(path, loader); Optional<YamlConfiguration> hardDriveOptional = YamlUtil.loadYamlFromDir(path, dataDir); if (!hardDriveOptional.isPresent() && !jarOptional.isPresent()) { return Optional.absent(); } YamlConfiguration hardDrive = hardDriveOptional.or(new YamlConfiguration()); if (jarOptional.isPresent()) { YamlConfiguration jar = jarOptional.get(); hardDrive.setDefaults(jar); hardDrive.options().copyDefaults(true); } YamlUtil.saveConfiguration(hardDrive, dataDir, path); return Optional.of((FileConfiguration) hardDrive); }
From source file:org.apache.gobblin.util.PropertiesUtils.java
/** * Extract all the keys that start with a <code>prefix</code> in {@link Properties} to a new {@link Properties} * instance.//from ww w . java2 s.c o m * * @param properties the given {@link Properties} instance * @param prefix of keys to be extracted * @return a {@link Properties} instance */ public static Properties extractPropertiesWithPrefix(Properties properties, Optional<String> prefix) { Preconditions.checkNotNull(properties); Preconditions.checkNotNull(prefix); Properties extractedProperties = new Properties(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { if (StringUtils.startsWith(entry.getKey().toString(), prefix.or(StringUtils.EMPTY))) { extractedProperties.put(entry.getKey().toString(), entry.getValue()); } } return extractedProperties; }