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

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

Introduction

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

Prototype

@Nullable
public abstract T orNull();

Source Link

Document

Returns the contained instance if it is present; null otherwise.

Usage

From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.PatternConstraintEffectiveImpl.java

public PatternConstraintEffectiveImpl(final String regex, final String rawRegex,
        final Optional<String> description, final Optional<String> reference) {
    this(regex, rawRegex, description.orNull(), reference.orNull(), null, null, null);
}

From source file:org.glowroot.collector.DetailMapWriter.java

private void writeValue(@Nullable Object value) throws IOException {
    if (value == null) {
        jg.writeNull();/*  w  ww .ja v a  2 s  . c  om*/
    } else if (value instanceof String) {
        jg.writeString((String) value);
    } else if (value instanceof Boolean) {
        jg.writeBoolean((Boolean) value);
    } else if (value instanceof Number) {
        jg.writeNumber(((Number) value).doubleValue());
    } else if (value instanceof Optional) {
        Optional<?> val = (Optional<?>) value;
        writeValue(val.orNull());
    } else if (value instanceof Map) {
        writeMap((Map<?, ?>) value);
    } else if (value instanceof List) {
        jg.writeStartArray();
        for (Object v : (List<?>) value) {
            writeValue(v);
        }
        jg.writeEndArray();
    } else if (isUnshadedGuavaOptionalClass(value)) {
        // this is just for plugin tests that run against shaded glowroot-core
        Class<?> optionalClass = value.getClass().getSuperclass();
        // just tested that super class is not null in condition
        checkNotNull(optionalClass);
        try {
            Method orNullMethod = optionalClass.getMethod("orNull");
            writeValue(orNullMethod.invoke(value));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    } else {
        logger.warn("detail map has unexpected value type: {}", value.getClass().getName());
        jg.writeString(value.toString());
    }
}

From source file:org.jclouds.openstack.keystone.v2_0.functions.AuthenticateApiAccessKeyCredentials.java

@Override
protected Access authenticateWithTenantName(Optional<String> tenantName,
        ApiAccessKeyCredentials apiAccessKeyCredentials) {
    return api.authenticateWithTenantNameAndCredentials(tenantName.orNull(), apiAccessKeyCredentials);
}

From source file:com.vmware.photon.controller.apife.clients.PortGroupFeClient.java

public ResourceList<PortGroup> find(Optional<String> name, Optional<UsageTag> usageTag,
        Optional<Integer> pageSize) {
    logger.info("find port groups of name {} and usageTag {}", name.orNull(), usageTag.orNull());
    return portGroupBackend.filter(name, usageTag, pageSize);
}

From source file:org.hypoport.springGuavaCacheAdapter.SpringGuavaCacheAdapter.java

@Override
public ValueWrapper get(Object key) {
    Optional<Object> value = cache.getIfPresent(key);
    return (value != null ? new SimpleValueWrapper(value.orNull()) : null);
}

From source file:org.geogit.api.plumbing.diff.GenericAttributeDiffImpl.java

private CharSequence attributeValueAsString(Optional<?> value) {
    return TextValueSerializer.asString(Optional.fromNullable((Object) value.orNull()));
}

From source file:org.estatio.dom.communicationchannel.EmailAddresses.java

@Programmatic
public EmailAddress findByEmailAddress(final CommunicationChannelOwner owner, final String emailAddress) {

    final List<CommunicationChannelOwnerLink> links = communicationChannelOwnerLinks
            .findByOwnerAndCommunicationChannelType(owner, CommunicationChannelType.EMAIL_ADDRESS);
    final Iterable<EmailAddress> emailAddresses = Iterables.transform(links,
            CommunicationChannelOwnerLink.Functions.communicationChannel(EmailAddress.class));
    final Optional<EmailAddress> emailAddressIfFound = Iterables.tryFind(emailAddresses,
            EmailAddress.Predicates.equalTo(emailAddress));
    return emailAddressIfFound.orNull();
}

From source file:org.eclipse.buildship.ui.preferences.GradleDistributionValidatingListener.java

@Override
public void distributionUpdated(GradleDistributionWrapper distribution) {
    Optional<String> error = this.gradleDistributionValidator.validate(distribution);
    this.preferencePage.setValid(!error.isPresent());
    this.preferencePage.setErrorMessage(error.orNull());
}

From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.RangeConstraintEffectiveImpl.java

public RangeConstraintEffectiveImpl(final Number min, final Number max, final Optional<String> description,
        final Optional<String> reference) {
    this(min, max, description.orNull(), reference.orNull(), "range-out-of-specified-bounds",
            "The argument is out of bounds <" + min + ", " + max + ">");
}

From source file:org.eclipse.buildship.ui.preferences.GradleUserHomeValidatingListener.java

@Override
public void modifyText(ModifyEvent e) {
    File gradleUserHome = this.gradleUserHomeGroup.getGradleUserHome();
    Optional<String> error = this.gradleUserHomeValidator.validate(gradleUserHome);
    this.preferencePage.setValid(!error.isPresent());
    this.preferencePage.setErrorMessage(error.orNull());
}