Example usage for com.google.common.base Optional get

List of usage examples for com.google.common.base Optional get

Introduction

In this page you can find the example usage for com.google.common.base Optional get.

Prototype

public abstract T get();

Source Link

Document

Returns the contained instance, which must be present.

Usage

From source file:org.opendaylight.controller.config.threadpool.util.FlexibleThreadPoolWrapper.java

/**
 * Overriding the queue://from   w  ww .  ja  va 2 s . c o m
 * ThreadPoolExecutor would not create new threads if the queue is not full, thus adding
 * occurs in RejectedExecutionHandler.
 * This impl saturates threadpool first, then queue. When both are full caller will get blocked.
 */
private static ForwardingBlockingQueue getQueue(Optional<Integer> capacity) {
    final BlockingQueue<Runnable> delegate = capacity.isPresent()
            ? new LinkedBlockingQueue<Runnable>(capacity.get())
            : new LinkedBlockingQueue<Runnable>();
    return new ForwardingBlockingQueue(delegate);
}

From source file:org.asciidoctor.asciidoclet.DocletOptions.java

public static boolean validOptions(String[][] options, DocErrorReporter errorReporter,
        StandardAdapter standardDoclet) {
    DocletOptions docletOptions = new DocletOptions(options);

    if (!docletOptions.baseDir().isPresent()) {
        errorReporter.printWarning(//w w  w.  ja va2s  .  c om
                BASEDIR + " must be present for includes or file reference features to work properly.");
    }

    Optional<File> attrsFile = docletOptions.attributesFile();
    if (attrsFile.isPresent() && !attrsFile.get().canRead()) {
        errorReporter.printWarning("Cannot read attributes file " + attrsFile.get());
    }

    return standardDoclet.validOptions(options, errorReporter);
}

From source file:org.jclouds.aliyun.ecs.domain.IpProtocol.java

public static IpProtocol fromValue(String value) {
    Optional<IpProtocol> ipProtocol = Enums.getIfPresent(IpProtocol.class, value.toUpperCase());
    checkArgument(ipProtocol.isPresent(), "Expected one of %s but was %s",
            Joiner.on(',').join(IpProtocol.values()), value);
    return ipProtocol.get();
}

From source file:org.apache.gobblin.service.modules.spec.JobExecutionPlanDagFactory.java

/**
 * The job name is derived from the {@link org.apache.gobblin.runtime.api.JobTemplate} URI. It is the
 * simple name of the path component of the URI.
 * @param jobExecutionPlan/*from w w  w .  ja v a  2  s.  co m*/
 * @return the simple name from the URI path.
 */
private static String getJobName(JobExecutionPlan jobExecutionPlan) {
    Optional<URI> jobTemplateUri = jobExecutionPlan.getJobSpec().getTemplateURI();
    if (jobTemplateUri.isPresent()) {
        return Files.getNameWithoutExtension(new Path(jobTemplateUri.get()).getName());
    } else {
        return null;
    }
}

From source file:google.registry.monitoring.whitebox.EppMetric.java

/**
 * Helper method to populate an {@link com.google.common.collect.ImmutableMap.Builder} with an
 * {@link Optional} value if the value is {@link Optional#isPresent()}.
 *///from   ww  w .  j  a va2  s. c o m
private static <T> void addOptional(String key, Optional<T> value, ImmutableMap.Builder<String, String> map) {
    if (value.isPresent()) {
        map.put(key, value.get().toString());
    }
}

From source file:springfox.documentation.schema.Enums.java

static List<String> getEnumValues(final Class<?> subject) {
    return transformUnique(subject.getEnumConstants(), new Function<Object, String>() {
        @Override//from  w  ww.jav a  2  s  . c  o m
        public String apply(Object input) {
            Optional<String> jsonValue = findJsonValueAnnotatedMethod(input)
                    .transform(evaluateJsonValue(input));
            if (jsonValue.isPresent() && !isNullOrEmpty(jsonValue.get())) {
                return jsonValue.get();
            }
            return input.toString();
        }
    });
}

From source file:org.anhonesteffort.flock.sync.key.KeySyncUtil.java

public static HidingCalDavCollection getOrCreateKeyCollection(Context context, DavAccount account)
        throws PropertyParseException, DavException, GeneralSecurityException, IOException {
    Log.d(TAG, "getOrCreateKeyCollection()");

    Optional<HidingCalDavCollection> keyCollection = getKeyCollection(context, account);
    if (keyCollection.isPresent())
        return keyCollection.get();

    HidingCalDavStore store = DavAccountHelper.getHidingCalDavStore(context, account, null);
    Optional<String> calendarHomeSet = store.getCalendarHomeSet();

    if (!calendarHomeSet.isPresent())
        throw new PropertyParseException("No calendar-home-set property found for user.", store.getHostHREF(),
                CalDavConstants.PROPERTY_NAME_CALENDAR_HOME_SET);

    Log.d(TAG, "creating key collection");
    store.addCollection(calendarHomeSet.get().concat(KeySyncUtil.PATH_KEY_COLLECTION));
    keyCollection = store.getCollection(calendarHomeSet.get().concat(KeySyncUtil.PATH_KEY_COLLECTION));

    if (!keyCollection.isPresent())
        throw new DavException(500, "WebDAV server did not create our key collection!");

    return keyCollection.get();
}

From source file:com.complexible.common.collect.Iterables2.java

public static <T> Iterable<T> present(final Iterable<Optional<T>> theIterable) {
    return new Iterable<T>() {
        public Iterator<T> iterator() {
            return new AbstractIterator<T>() {
                private Iterator<Optional<T>> theIter = theIterable.iterator();

                @Override/*from  w  w w.j a  v a2 s .  c o  m*/
                protected T computeNext() {
                    while (theIter.hasNext()) {
                        Optional<T> aOptional = theIter.next();
                        if (aOptional.isPresent()) {
                            return aOptional.get();
                        }
                    }
                    return endOfData();
                }
            };
        }
    };
}

From source file:org.opendaylight.mdsal.dom.spi.RpcRoutingStrategy.java

public static RpcRoutingStrategy from(final RpcDefinition rpc) {
    ContainerSchemaNode input = rpc.getInput();
    if (input != null) {
        for (DataSchemaNode schemaNode : input.getChildNodes()) {
            Optional<QName> context = getRoutingContext(schemaNode);
            if (context.isPresent()) {
                return new RoutedRpcStrategy(rpc.getQName(), context.get(), schemaNode.getQName());
            }/*  w w  w.j  av  a2s  . c o  m*/
        }
    }
    return new GlobalRpcStrategy(rpc.getQName());
}

From source file:com.facebook.buck.jvm.java.JavacOptionsFactory.java

public static JavacOptions create(JavacOptions defaultOptions, BuildRuleParams params,
        BuildRuleResolver resolver, SourcePathResolver pathResolver, JvmLibraryArg jvmLibraryArg) {
    if ((jvmLibraryArg.source.isPresent() || jvmLibraryArg.target.isPresent())
            && jvmLibraryArg.javaVersion.isPresent()) {
        throw new HumanReadableException("Please set either source and target or java_version.");
    }//from  w  w  w  .  ja v a2s  . co m

    JavacOptions.Builder builder = JavacOptions.builder(defaultOptions);

    if (jvmLibraryArg.javaVersion.isPresent()) {
        builder.setSourceLevel(jvmLibraryArg.javaVersion.get());
        builder.setTargetLevel(jvmLibraryArg.javaVersion.get());
    }

    if (jvmLibraryArg.source.isPresent()) {
        builder.setSourceLevel(jvmLibraryArg.source.get());
    }

    if (jvmLibraryArg.target.isPresent()) {
        builder.setTargetLevel(jvmLibraryArg.target.get());
    }

    if (jvmLibraryArg.extraArguments.isPresent()) {
        builder.addAllExtraArguments(jvmLibraryArg.extraArguments.get());
    }

    if (jvmLibraryArg.compiler.isPresent()) {
        Either<BuiltInJavac, SourcePath> either = jvmLibraryArg.compiler.get();

        if (either.isRight()) {
            SourcePath sourcePath = either.getRight();

            Optional<BuildRule> possibleRule = pathResolver.getRule(sourcePath);
            if (possibleRule.isPresent()) {
                BuildRule rule = possibleRule.get();
                if (rule instanceof PrebuiltJar) {
                    builder.setJavacJarPath(new BuildTargetSourcePath(rule.getBuildTarget()));
                } else {
                    throw new HumanReadableException("Only prebuilt_jar targets can be used as a javac");
                }
            } else {
                builder.setJavacPath(pathResolver.getAbsolutePath(sourcePath));
            }
        }
    } else {
        if (jvmLibraryArg.javac.isPresent() || jvmLibraryArg.javacJar.isPresent()) {
            if (jvmLibraryArg.javac.isPresent() && jvmLibraryArg.javacJar.isPresent()) {
                throw new HumanReadableException("Cannot set both javac and javacjar");
            }
            builder.setJavacPath(jvmLibraryArg.javac);
            builder.setJavacJarPath(jvmLibraryArg.javacJar);
        }
    }

    AnnotationProcessingParams annotationParams = jvmLibraryArg
            .buildAnnotationProcessingParams(params.getBuildTarget(), params.getProjectFilesystem(), resolver);
    builder.setAnnotationProcessingParams(annotationParams);

    return builder.build();
}