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

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

Introduction

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

Prototype

public abstract <V> Optional<V> transform(Function<? super T, V> function);

Source Link

Document

If the instance is present, it is transformed with the given Function ; otherwise, Optional#absent is returned.

Usage

From source file:org.jclouds.openstack.marconi.v1.domain.MessageStream.java

@Override
public Optional<Object> nextMarker() {
    Optional<Link> nextMarkerLink = Iterables.tryFind(getLinks(), IS_NEXT_LINK);
    return nextMarkerLink.transform(TO_LIST_OPTIONS);
}

From source file:com.facebook.buck.java.PrebuiltJarBuildRuleFactory.java

@Override
protected void amendBuilder(PrebuiltJarRule.Builder builder, BuildRuleFactoryParams params) {
    // binary_jar
    String binaryJar = params.getRequiredStringAttribute("binary_jar");
    String binaryJarFile = params.resolveFilePathRelativeToBuildFileDirectory(binaryJar);
    builder.setBinaryJar(binaryJarFile);

    // source_jar
    Optional<String> sourceJar = params.getOptionalStringAttribute("source_jar");
    builder.setSourceJar(sourceJar.transform(params.getResolveFilePathRelativeToBuildFileDirectoryTransform()));

    // javadoc_url
    Optional<String> javadocUrl = params.getOptionalStringAttribute("javadoc_url");
    builder.setJavadocUrl(javadocUrl);//w w  w . j  av a 2  s.c o m
}

From source file:com.facebook.buck.android.AndroidLibraryBuildRuleFactory.java

@Override
protected void amendBuilder(DefaultJavaLibraryRule.Builder abstractBuilder, BuildRuleFactoryParams params)
        throws NoSuchBuildTargetException {
    super.amendBuilder(abstractBuilder, params);
    AndroidLibraryRule.Builder builder = (AndroidLibraryRule.Builder) abstractBuilder;

    // manifest/*from  ww  w.j a va 2  s  .co m*/
    Optional<String> manifestFile = params.getOptionalStringAttribute("manifest");
    builder.setManifestFile(
            manifestFile.transform(params.getResolveFilePathRelativeToBuildFileDirectoryTransform()));
}

From source file:com.mirantis.opendaylight.route.RouteBuilderServiceImpl.java

private ListenableFuture<Short> allocateVlan(ReadWriteTransaction tx, Uri srcNode, Uri dstNode) {
    if (Objects.equals(srcNode, dstNode)) {
        return immediateFuture(null);
    }/*from  w  w w. ja  v a2s.  c o m*/
    InstanceIdentifier<VlanCounter> counterId = InstanceIdentifier.create(VlanCounter.class);
    return transform(tx.read(CONFIGURATION, counterId), (Optional<VlanCounter> counter) -> {
        short curVal = counter.transform(cnt -> cnt.getNextVlan().getValue()).or(1L).shortValue();
        Counter32 nextVal = new Counter32(curVal < 4094 ? curVal + 1L : 1L);
        tx.put(CONFIGURATION, counterId, new VlanCounterBuilder().setNextVlan(nextVal).build());
        return curVal;
    }, executor);
}

From source file:springfox.documentation.swagger.readers.operation.SwaggerOperationTagsReader.java

private Set<String> operationTags(OperationContext context) {
    Optional<ApiOperation> annotation = context.findAnnotation(ApiOperation.class);
    return annotation.transform(tagsFromOperation()).or(Sets.<String>newHashSet());
}

From source file:com.facebook.buck.parser.ProjectConfigRuleFactory.java

@Override
protected void amendBuilder(ProjectConfigRule.Builder builder, BuildRuleFactoryParams params)
        throws NoSuchBuildTargetException {
    Function<String, BuildTarget> contextualBuildParser = createBuildTargetParseFunction(params);

    // src_target
    Optional<String> srcTargetId = params.getOptionalStringAttribute("src_target");
    builder.setSrcTarget(srcTargetId.transform(contextualBuildParser));

    // src_roots/*ww w . j  a v  a  2 s .  c  o m*/
    // Note that the values in this array are passed as-is, rather than resolved to local project
    // paths.
    List<String> srcRoots = params.getNullableListAttribute("src_roots");
    builder.setSrcRoots(srcRoots);

    // test_target
    Optional<String> testTargetId = params.getOptionalStringAttribute("test_target");
    builder.setTestTarget(testTargetId.transform(contextualBuildParser));

    // test_roots
    // Note that this value is passed as-is, rather than resolved to a project local path.
    List<String> testRoots = params.getNullableListAttribute("test_roots");
    builder.setTestRoots(testRoots);

    // is_intellij_plugin
    builder.setIsIntelliJPlugin(params.getBooleanAttribute("is_intellij_plugin"));
}

From source file:springfox.documentation.swagger.readers.operation.SwaggerOperationTagsReader.java

private Set<String> controllerTags(OperationContext context) {
    Optional<Api> controllerAnnotation = context.findControllerAnnotation(Api.class);
    return controllerAnnotation.transform(tagsFromController()).or(Sets.<String>newHashSet());
}

From source file:springfox.documentation.swagger.web.SwaggerApiListingReader.java

@Override
public void apply(ApiListingContext apiListingContext) {
    Class<?> controllerClass = apiListingContext.getResourceGroup().getControllerClass();
    Optional<Api> apiAnnotation = fromNullable(findAnnotation(controllerClass, Api.class));
    String description = emptyToNull(apiAnnotation.transform(descriptionExtractor()).orNull());

    Set<String> tagSet = apiAnnotation.transform(tags()).or(Sets.<String>newTreeSet());
    if (tagSet.isEmpty()) {
        tagSet.add(apiListingContext.getResourceGroup().getGroupName());
    }/* ww  w .j  av  a 2s .  c o  m*/
    apiListingContext.apiListingBuilder().description(description).tagNames(tagSet);
}

From source file:org.locationtech.geogig.rocksdb.RocksdbBlobStore.java

@Override
public Optional<InputStream> getBlobAsStream(String namespace, String path) {
    Optional<byte[]> blob = getBlob(path);
    return blob.transform((b) -> new ByteArrayInputStream(b));
}

From source file:com.google.testing.junit.runner.junit4.JUnit4Config.java

/**
 * Returns the XML output path, or null if not specified.
 *//*from  w  w  w.  j  av  a  2s .  c  o  m*/
public Optional<Path> getXmlOutputPath() {
    if (!xmlOutputPath.isPresent()) {
        Optional<String> envXmlOutputPath = Optional.fromNullable(System.getenv(XML_OUTPUT_FILE_ENV_VAR));
        return envXmlOutputPath.transform(new Function<String, Path>() {
            @Override
            public Path apply(String path) {
                return FileSystems.getDefault().getPath(path);
            }
        });
    }

    return xmlOutputPath;
}