public Optional<SupervisorSpec> getSupervisorSpec(String id) { Pair<Supervisor, SupervisorSpec> supervisor = supervisors.get(id); return supervisor == null ? Optional.absent() : Optional.fromNullable(supervisor.rhs); }
private TaskStatus(final Builder builder) { this.job = checkNotNull(builder.job, "job"); this.goal = checkNotNull(builder.goal, "goal"); this.state = checkNotNull(builder.state, "state"); // Optional this.containerId = builder.containerId; this.throttled = Optional.fromNullable(builder.throttled).or(ThrottleState.NO); this.ports = Optional.fromNullable(builder.ports).or(EMPTY_PORTS); this.env = Optional.fromNullable(builder.env).or(Maps.<String, String>newHashMap()); this.containerError = Optional.fromNullable(builder.containerError).or(""); }
@Override protected Optional<String> doExtract(final HttpRequest request) { Optional<ImmutableMap<String, String>> cookies = extractor.extract(request); if (cookies.isPresent()) { return fromNullable(cookies.get().get(this.key)); } return Optional.absent(); } }
/** * Execute queries. * * @param queries the queries * @param proxy the proxy * @throws SQLException the sql exception */ public void executeQueries(List<String> queries, Optional<String> proxy) throws SQLException { Preconditions.checkArgument(!this.statementMap.isEmpty(), "No hive connection. Unable to execute queries"); if (!proxy.isPresent()) { Preconditions.checkArgument(this.statementMap.size() == 1, "Multiple Hive connections. Please specify a user"); proxy = Optional.fromNullable(this.statementMap.keySet().iterator().next()); } Statement statement = this.statementMap.get(proxy.get()); for (String query : queries) { statement.execute(query); } }
public void testFromNullable() { Optional<String> optionalName = Optional.fromNullable("bob"); assertEquals("bob", optionalName.get()); }
@Override public SharedResourceFactoryResponse<RestClient> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, SharedRestClientKey> config) throws NotConfiguredException { try { SharedRestClientKey key = config.getKey(); if (!(key instanceof UriRestClientKey)) { return new ResourceCoordinate<>(this, new UriRestClientKey(key.serviceName, resolveUriPrefix(config.getConfig(), key)), config.getScope()); } String uriPrefix = ((UriRestClientKey) key).getUri(); HttpClientFactory http = new HttpClientFactory(FilterChains.empty(), new NioEventLoopGroup(0 /* use default settings */, ExecutorsUtils.newDaemonThreadFactory(Optional.<Logger>absent(), Optional.of("R2 Nio Event Loop-%d"))), true, Executors.newSingleThreadScheduledExecutor( ExecutorsUtils.newDaemonThreadFactory(Optional.<Logger>absent(), Optional.of("R2 Netty Scheduler"))), true); Client r2Client = new TransportClientAdapter(http.getClient(Collections.<String, String>emptyMap())); return new ResourceInstance<>(new RestClient(r2Client,uriPrefix)); } catch (URISyntaxException use) { throw new RuntimeException("Could not create a rest client for key " + Optional.fromNullable(config.getKey().toConfigurationKey()).or("null")); } }
this.hostname = Optional.fromNullable(hostname).orNull(); this.created = Optional.fromNullable(created).orNull(); this.command = Optional.fromNullable(command).or(EMPTY_COMMAND); this.env = Optional.fromNullable(env).or(EMPTY_ENV); this.resources = Optional.fromNullable(resources).orNull(); this.ports = Optional.fromNullable(ports).or(EMPTY_PORTS); this.registration = Optional.fromNullable(registration).or(EMPTY_REGISTRATION); this.gracePeriod = Optional.fromNullable(gracePeriod).orNull(); this.volumes = Optional.fromNullable(volumes).or(EMPTY_VOLUMES); this.expires = expires; this.registrationDomain = Optional.fromNullable(registrationDomain) .or(EMPTY_REGISTRATION_DOMAIN); this.creatingUser = Optional.fromNullable(creatingUser).orNull(); this.token = Optional.fromNullable(token).or(EMPTY_TOKEN); this.healthCheck = Optional.fromNullable(healthCheck).orNull(); this.securityOpt = Optional.fromNullable(securityOpt).or(EMPTY_SECURITY_OPT); this.networkMode = Optional.fromNullable(networkMode).orNull(); this.metadata = Optional.fromNullable(metadata).or(EMPTY_METADATA); this.addCapabilities = firstNonNull(addCapabilities, EMPTY_CAPS); this.dropCapabilities = firstNonNull(dropCapabilities, EMPTY_CAPS); this.labels = Optional.fromNullable(labels).or(EMPTY_LABELS); this.secondsToWaitBeforeKill = secondsToWaitBeforeKill; this.ramdisks = firstNonNull(ramdisks, EMPTY_RAMDISKS); this.rolloutOptions = rolloutOptions; this.runtime = Optional.fromNullable(runtime).orNull();
@Override protected Optional<String> doExtract(final HttpRequest request) { Optional<ImmutableMap<String, String>> forms = extractor.extract(request); if (forms.isPresent()) { return fromNullable(forms.get().get(key)); } return Optional.absent(); } }
public static String getProperty(HivePartitionDataset dataset, String property, long defaultValue) { Optional<String> propertyValueOptional = Optional.fromNullable(dataset.getParams().get(property)); if (!propertyValueOptional.isPresent()) { return Long.toString(defaultValue); } try { long propertyVal = Long.parseLong(propertyValueOptional.get()); if (propertyVal < 0) { return Long.toString(defaultValue); } else { return Long.toString(propertyVal); } } catch (NumberFormatException e) { return Long.toString(defaultValue); } } }
FluentIterable(Iterable<E> iterable) { checkNotNull(iterable); this.iterableDelegate = Optional.fromNullable(this != iterable ? iterable : null); }
private static String env(final String name, final String defaultValue) { return Optional.fromNullable(getenv(name)).or(defaultValue); }
public static Optional<EntityMap> fromEntity(Optional<Entity> entity) { if(entity.isPresent()){ EntityMap map = fromEntity(entity.get()); return Optional.fromNullable(map); }else{ return Optional.absent(); } }
for (String dimension : dimensions) { Optional<RangeSet<String>> optFilterRangeSet = dimensionRangeCache .computeIfAbsent(dimension, d -> Optional.fromNullable(dimFilter.getDimensionRangeSet(d))); if (optFilterRangeSet.isPresent()) { filterDomain.put(dimension, optFilterRangeSet.get());
public Left(S s) { super(Optional.fromNullable(s), Optional.<T>absent()); }
public String getHost() { return fromNullable(uri.getHost()).or("localhost"); }
InnerTimer(MetricContext context, String name, ContextAwareTimer contextAwareTimer) { this.name = name; Optional<MetricContext> parentContext = context.getParent(); if (parentContext.isPresent()) { this.parentTimer = Optional.fromNullable(parentContext.get().contextAwareTimer(name)); } else { this.parentTimer = Optional.absent(); } this.timer = new WeakReference<>(contextAwareTimer); }
@Override @Value.Lazy public Optional<String[]> depluralize() { @Nullable String[] dictionary = null; Optional<DeclaringPackage> parent = namedParentPackage(); if (parent.isPresent()) { Optional<String[]> depluralize = parent.get().depluralize(); if (depluralize.isPresent()) { dictionary = concat(dictionary, depluralize.get()); } } Optional<String[]> depluralize = super.depluralize(); if (depluralize.isPresent()) { dictionary = concat(dictionary, depluralize.get()); } return Optional.fromNullable(dictionary); }
public Right(T t) { super(Optional.<S>absent(), Optional.fromNullable(t)); }
protected String getLastFragment(String url) { URI uri = URI.create(url); String path = Optional.fromNullable(uri.getPath()).or("/"); return path.substring(path.lastIndexOf('/') + 1); } }
InnerMeter(MetricContext context, String name, ContextAwareMeter contextAwareMeter) { this.name = name; Optional<MetricContext> parentContext = context.getParent(); if (parentContext.isPresent()) { this.parentMeter = Optional.fromNullable(parentContext.get().contextAwareMeter(name)); } else { this.parentMeter = Optional.absent(); } this.contextAwareMeter = new WeakReference<>(contextAwareMeter); }