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:springfox.documentation.spring.web.readers.operation.ModelRefs.java

public static Optional<ModelRef> modelRef(Optional<ResolvedType> type, ModelContext modelContext,
        TypeNameExtractor nameExtractor) {
    if (!type.isPresent()) {
        return Optional.absent();
    }/* w w  w.  jav a2 s.c  o m*/
    return Optional.of(modelRef(type.get(), modelContext, nameExtractor));
}

From source file:google.registry.config.YamlUtils.java

/**
 * Recursively merges two YAML documents together.
 *
 * <p>Any fields that are specified in customYaml will override fields of the same path in
 * defaultYaml. Additional fields in customYaml that aren't specified in defaultYaml will be
 * ignored. The schemas of all fields that are present must be identical, e.g. it is an error to
 * override a field that has a Map value in the default YAML with a field of any other type in the
 * custom YAML./*from w  w w. j  a v a  2s  .  c  o  m*/
 *
 * <p>Only maps are handled recursively; lists are simply overridden in place as-is, as are maps
 * whose name is suffixed with "Map" -- this allows entire maps to be overridden, rather than
 * merged.
 */
static String mergeYaml(String defaultYaml, String customYaml) {
    Yaml yaml = new Yaml();
    Map<String, Object> yamlMap = loadAsMap(yaml, defaultYaml).get();
    Optional<Map<String, Object>> customMap = loadAsMap(yaml, customYaml);
    if (customMap.isPresent()) {
        yamlMap = mergeMaps(yamlMap, customMap.get());
        logger.infofmt("Successfully loaded environment configuration YAML file.");
    } else {
        logger.infofmt("Ignoring empty environment configuration YAML file.");
    }
    return yaml.dump(yamlMap);
}

From source file:org.sonar.server.computation.queue.ReportSubmitter.java

private static void ensureOrganizationIsConsistent(Optional<ComponentDto> project,
        OrganizationDto organizationDto) {
    if (project.isPresent()) {
        checkArgument(project.get().getOrganizationUuid().equals(organizationDto.getUuid()),
                "Organization of component with key '%s' does not match specified organization '%s'",
                project.get().key(), organizationDto.getKey());
    }//from  w ww  .  ja v  a  2  s  .  c  o m
}

From source file:org.brooklyncentral.catalog.scrape.CatalogItemScraper.java

private static CatalogItem parseCatalogItem(String repoUrl) {
    //TODO Properly handle required vs. optional failures

    String[] urlTokens = repoUrl.split("/");

    String repoName = urlTokens[urlTokens.length - 1];
    String author = urlTokens[urlTokens.length - 2];

    Optional<String> description = getGithubRawText(repoUrl, "README.md");
    Optional<String> documentation = getGithubRawText(repoUrl, "items.js");

    Optional<String> catalogBomString = getGithubRawText(repoUrl, "catalog.bom");
    @SuppressWarnings("unchecked")
    Map<String, Object> catalogBomYaml = (Map<String, Object>) Yamls.parseAll(catalogBomString.get()).iterator()
            .next();/*from w  w  w.  j  av  a2s. co  m*/

    Optional<String> masterCommitHash = Optional.absent();

    Optional<String> license;
    String licenseUrl = generateRawGithubUrl(repoUrl, "LICENSE.txt");

    if (urlExists(licenseUrl)) {
        license = Optional.of(getGithubRawText(repoUrl, "LICENSE.txt").get());
    } else {
        license = Optional.absent();
    }

    Optional<String> changelog;
    String changelogUrl = generateRawGithubUrl(repoUrl, "CHANGELOG.md");

    if (urlExists(changelogUrl)) {
        changelog = Optional.of(getGithubRawText(repoUrl, "CHANGELOG.md").get());
    } else {
        changelog = Optional.absent();
    }

    //TODO Actually create CatalogItem
    return null;
}

From source file:dagger2.internal.codegen.MethodSignatureFormatter.java

private static void appendParameter(StringBuilder builder, VariableElement parameter, TypeMirror type) {
    Optional<AnnotationMirror> qualifier = InjectionAnnotations.getQualifier(parameter);
    if (qualifier.isPresent()) {
        builder.append(ErrorMessages.format(qualifier.get())).append(' ');
    }//from w ww .j  a  v  a  2  s  .com
    builder.append(nameOfType(type));
}

From source file:org.apache.gobblin.hive.HiveConfFactory.java

/**
 *
 * @param hcatURI User specified hcatURI.
 * @param broker A shared resource broker
 * @return a {@link HiveConf} with specified hcatURI if any.
 * @throws IOException/*from w  w w  . j  ava  2  s.c  o  m*/
 */
public static <S extends ScopeType<S>> HiveConf get(Optional<String> hcatURI, SharedResourcesBroker<S> broker)
        throws IOException {
    try {
        SharedHiveConfKey confKey = hcatURI.isPresent() && StringUtils.isNotBlank(hcatURI.get())
                ? new SharedHiveConfKey(hcatURI.get())
                : SharedHiveConfKey.INSTANCE;
        return broker.getSharedResource(new HiveConfFactory<>(), confKey);
    } catch (NotConfiguredException nce) {
        throw new IOException(nce);
    }
}

From source file:org.apache.gobblin.metrics.event.EventSubmitter.java

/**
 * Calls submit on submitter if present.
 *//*from w  ww. j a va2s . c  om*/
public static void submit(Optional<EventSubmitter> submitter, String name, String... metadataEls) {
    if (submitter.isPresent()) {
        submitter.get().submit(name, metadataEls);
    }
}

From source file:org.eclipse.recommenders.examples.models.MappingWorkFlowExample.java

public static void useOfMapping(final IMappingProvider mapping) {
    DependencyInfo ed = null;/*from  w ww .j  a  v a 2 s  . c o m*/

    mapping.addStrategy(new MavenPomPropertiesStrategy());

    IProjectCoordinateResolver mappingStrategy = mapping;

    Optional<ProjectCoordinate> optionalProjectCoordinate = mappingStrategy.searchForProjectCoordinate(ed);

    ProjectCoordinate projectCoordinate = null;
    if (optionalProjectCoordinate.isPresent()) {
        projectCoordinate = optionalProjectCoordinate.get();
    }
}

From source file:org.opendaylight.genius.interfacemanager.globals.InterfaceServiceUtil.java

public static short getVlanId(String interfaceName, DataBroker broker) {
    InstanceIdentifier<Interface> id = InstanceIdentifier.builder(Interfaces.class)
            .child(Interface.class, new InterfaceKey(interfaceName)).build();
    Optional<Interface> ifInstance = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, id, broker);
    if (ifInstance.isPresent()) {
        IfL2vlan vlanIface = ifInstance.get().getAugmentation(IfL2vlan.class);
        return vlanIface.getVlanId() == null ? 0 : vlanIface.getVlanId().getValue().shortValue();
    }/*from w w  w.j  a v a  2 s .  c o  m*/
    return -1;
}

From source file:eu.numberfour.n4js.ui.utils.HandlerServiceUtils.java

private static <T> Optional<T> getVariable(final String variableName, final Class<T> expectedClass) {

    if (isNullOrEmpty(variableName) || null == expectedClass) {
        return absent();
    }/*  w  w w  .jav  a  2s .  c  o  m*/

    final Optional<IEvaluationContext> state = getCurrentWorkbenchState();
    if (!state.isPresent()) {
        return absent();
    }

    final Object variable = state.get().getVariable(variableName);
    if (null == variable || UNDEFINED_VARIABLE == variable) {
        return absent();
    }

    if (expectedClass.isAssignableFrom(variable.getClass())) {
        return fromNullable(expectedClass.cast(variable));
    }

    return absent();
}