Example usage for com.google.common.base Strings emptyToNull

List of usage examples for com.google.common.base Strings emptyToNull

Introduction

In this page you can find the example usage for com.google.common.base Strings emptyToNull.

Prototype

@Nullable
public static String emptyToNull(@Nullable String string) 

Source Link

Document

Returns the given string if it is nonempty; null otherwise.

Usage

From source file:nl.mpi.translation.tools.LocalFileAwareUrlStreamResolver.java

/**
 * Constructs the file aware resolver with a new instance of
 * {@link UrlStreamResolverImpl} as base resolver. If either baseUrl or
 * basePath is empty or null, the behaviour of this resolver will fall back
 * to the base resolver.//from ww w  .j a va2s. c om
 *
 * @param baseResolver resolver to use if no corresponding file can be found
 * @param baseUrl base URL
 * @param basePath the base path on the local file system that corresponds
 * with the base URL
 */
public LocalFileAwareUrlStreamResolver(UrlStreamResolver baseResolver, String baseUrl, String basePath) {
    this.baseResolver = baseResolver;
    this.baseUrl = Strings.emptyToNull(baseUrl);
    if (Strings.isNullOrEmpty(basePath)) {
        this.basePath = null;
    } else {
        this.basePath = new File(basePath);
    }
}

From source file:com.eucalyptus.objectstorage.policy.XAmzContentSha256Key.java

private String getXAmzContentSha256() throws AuthException {
    try {/*from  w  w  w.jav  a2s  .c o  m*/
        final MappingHttpRequest request = Contexts.lookup().getHttpRequest();
        return Strings.emptyToNull(request.getHeader(S3V4Authentication.AWS_CONTENT_SHA_HEADER));
    } catch (final Exception e) {
        Exceptions.findAndRethrow(e, AuthException.class);
        throw new AuthException("Error getting value for s3 x-amz-content-sha256 condition", e);
    }
}

From source file:org.n52.shetland.ogc.ows.OwsDomain.java

public OwsDomain(String name, OwsPossibleValues possibleValues, OwsValue defaultValue,
        OwsDomainMetadata meaning, OwsDomainMetadata dataType, OwsValuesUnit valuesUnit,
        Collection<OwsMetadata> metadata) {
    super(possibleValues, defaultValue, meaning, dataType, valuesUnit, metadata);
    this.name = Objects.requireNonNull(Strings.emptyToNull(name), "name");
}

From source file:org.ambraproject.rhino.view.article.author.AuthorView.java

private AuthorView(Builder builder) {
    this.givenNames = Strings.emptyToNull(builder.givenNames);
    this.surnames = Strings.emptyToNull(builder.surnames);
    this.suffix = Strings.emptyToNull(builder.suffix);
    this.onBehalfOf = Strings.emptyToNull(builder.onBehalfOf);
    this.orcid = builder.orcid;
    this.equalContrib = builder.equalContrib;
    this.deceased = builder.deceased;
    this.relatedFootnote = builder.relatedFootnote;
    this.corresponding = builder.corresponding;
    this.currentAddresses = (builder.currentAddresses == null) ? ImmutableList.of()
            : ImmutableList.copyOf(builder.currentAddresses);
    this.affiliations = (builder.affiliations == null) ? ImmutableList.of()
            : ImmutableList.copyOf(builder.affiliations);
    this.customFootnotes = (builder.customFootnotes == null) ? ImmutableList.of()
            : ImmutableList.copyOf(builder.customFootnotes);
    this.roles = (builder.roles == null) ? ImmutableList.of() : ImmutableList.copyOf(builder.roles);

    this.fullName = buildFullName(givenNames, surnames, suffix);
}

From source file:org.mayocat.addons.util.AddonUtils.java

public static Object emptyToNull(Object value) {
    if (value == null) {
        return null;
    }/*from ww w .  j  a  va2 s  .com*/
    if (String.class.isAssignableFrom(value.getClass())) {
        return Strings.emptyToNull((String) value);
    }
    return value;
}

From source file:com.reprezen.swagedit.assist.Proposal.java

/**
 * Returns a {@link CompletionProposal}.
 * /*from w w w.  jav  a  2s . c  o  m*/
 * The {@link CompletionProposal} will be returned only if the prefix is null, or if the replacement string starts
 * with or contains the prefix. Otherwise this method returns null.
 * 
 * @param prefix
 * @param offset
 * @return proposal
 */
public StyledCompletionProposal asStyledCompletionProposal(String prefix, int offset) {
    final StyledString styledString = new StyledString(displayString);
    if (type != null) {
        styledString.append(": ", typeStyler).append(type, typeStyler);
    }

    StyledCompletionProposal proposal = null;
    if (Strings.emptyToNull(prefix) == null) {
        proposal = new StyledCompletionProposal(replacementString, styledString, null, description, offset);
    } else if (replacementString.contains(prefix) || replacementString.startsWith(prefix)) {
        proposal = new StyledCompletionProposal(replacementString, styledString, prefix, description, offset);
    }

    return proposal;
}

From source file:io.druid.server.namespace.JDBCExtractionNamespaceFunctionFactory.java

@Override
public Function<String, String> build(JDBCExtractionNamespace extractionNamespace,
        final Map<String, String> cache) {
    return new Function<String, String>() {
        @Nullable/*from  w  w  w . j a  va  2 s  . co m*/
        @Override
        public String apply(String input) {
            if (Strings.isNullOrEmpty(input)) {
                return null;
            }
            return Strings.emptyToNull(cache.get(input));
        }
    };
}

From source file:com.google.gerrit.server.project.ConfigInfoImpl.java

public ConfigInfoImpl(boolean serverEnableSignedPush, ProjectControl control, TransferConfig config,
        DynamicMap<ProjectConfigEntry> pluginConfigEntries, PluginConfigFactory cfgFactory,
        AllProjectsName allProjects, DynamicMap<RestView<ProjectResource>> views) {
    ProjectState projectState = control.getProjectState();
    Project p = control.getProject();//w  ww . j  ava 2 s.c o m
    this.description = Strings.emptyToNull(p.getDescription());

    InheritedBooleanInfo useContributorAgreements = new InheritedBooleanInfo();
    InheritedBooleanInfo useSignedOffBy = new InheritedBooleanInfo();
    InheritedBooleanInfo useContentMerge = new InheritedBooleanInfo();
    InheritedBooleanInfo requireChangeId = new InheritedBooleanInfo();
    InheritedBooleanInfo createNewChangeForAllNotInTarget = new InheritedBooleanInfo();
    InheritedBooleanInfo enableSignedPush = new InheritedBooleanInfo();
    InheritedBooleanInfo requireSignedPush = new InheritedBooleanInfo();
    InheritedBooleanInfo rejectImplicitMerges = new InheritedBooleanInfo();
    InheritedBooleanInfo enableReviewerByEmail = new InheritedBooleanInfo();

    useContributorAgreements.value = projectState.isUseContributorAgreements();
    useSignedOffBy.value = projectState.isUseSignedOffBy();
    useContentMerge.value = projectState.isUseContentMerge();
    requireChangeId.value = projectState.isRequireChangeID();
    createNewChangeForAllNotInTarget.value = projectState.isCreateNewChangeForAllNotInTarget();

    useContributorAgreements.configuredValue = p.getUseContributorAgreements();
    useSignedOffBy.configuredValue = p.getUseSignedOffBy();
    useContentMerge.configuredValue = p.getUseContentMerge();
    requireChangeId.configuredValue = p.getRequireChangeID();
    createNewChangeForAllNotInTarget.configuredValue = p.getCreateNewChangeForAllNotInTarget();
    enableSignedPush.configuredValue = p.getEnableSignedPush();
    requireSignedPush.configuredValue = p.getRequireSignedPush();
    rejectImplicitMerges.configuredValue = p.getRejectImplicitMerges();
    enableReviewerByEmail.configuredValue = p.getEnableReviewerByEmail();

    ProjectState parentState = Iterables.getFirst(projectState.parents(), null);
    if (parentState != null) {
        useContributorAgreements.inheritedValue = parentState.isUseContributorAgreements();
        useSignedOffBy.inheritedValue = parentState.isUseSignedOffBy();
        useContentMerge.inheritedValue = parentState.isUseContentMerge();
        requireChangeId.inheritedValue = parentState.isRequireChangeID();
        createNewChangeForAllNotInTarget.inheritedValue = parentState.isCreateNewChangeForAllNotInTarget();
        enableSignedPush.inheritedValue = projectState.isEnableSignedPush();
        requireSignedPush.inheritedValue = projectState.isRequireSignedPush();
        rejectImplicitMerges.inheritedValue = projectState.isRejectImplicitMerges();
        enableReviewerByEmail.inheritedValue = projectState.isEnableReviewerByEmail();
    }

    this.useContributorAgreements = useContributorAgreements;
    this.useSignedOffBy = useSignedOffBy;
    this.useContentMerge = useContentMerge;
    this.requireChangeId = requireChangeId;
    this.rejectImplicitMerges = rejectImplicitMerges;
    this.createNewChangeForAllNotInTarget = createNewChangeForAllNotInTarget;
    this.enableReviewerByEmail = enableReviewerByEmail;
    if (serverEnableSignedPush) {
        this.enableSignedPush = enableSignedPush;
        this.requireSignedPush = requireSignedPush;
    }

    MaxObjectSizeLimitInfo maxObjectSizeLimit = new MaxObjectSizeLimitInfo();
    maxObjectSizeLimit.value = config.getEffectiveMaxObjectSizeLimit(projectState) == config
            .getMaxObjectSizeLimit() ? config.getFormattedMaxObjectSizeLimit() : p.getMaxObjectSizeLimit();
    maxObjectSizeLimit.configuredValue = p.getMaxObjectSizeLimit();
    maxObjectSizeLimit.inheritedValue = config.getFormattedMaxObjectSizeLimit();
    this.maxObjectSizeLimit = maxObjectSizeLimit;

    this.submitType = p.getSubmitType();
    this.state = p.getState() != com.google.gerrit.extensions.client.ProjectState.ACTIVE ? p.getState() : null;

    this.commentlinks = new LinkedHashMap<>();
    for (CommentLinkInfo cl : projectState.getCommentLinks()) {
        this.commentlinks.put(cl.name, cl);
    }

    pluginConfig = getPluginConfig(control.getProjectState(), pluginConfigEntries, cfgFactory, allProjects);

    actions = new TreeMap<>();
    for (UiAction.Description d : UiActions.from(views, new ProjectResource(control),
            Providers.of(control.getUser()))) {
        actions.put(d.getId(), new ActionInfo(d));
    }
    this.theme = projectState.getTheme();

    this.extensionPanelNames = projectState.getConfig().getExtensionPanelSections();
}

From source file:io.druid.query.groupby.RowBasedValueMatcherFactory.java

@Override
public ValueMatcher makeValueMatcher(final String dimension, final String value) {
    if (dimension.equals(Column.TIME_COLUMN_NAME)) {
        if (value == null) {
            return new BooleanValueMatcher(false);
        }//  www .  jav  a  2s. co m

        final Long longValue = GuavaUtils.tryParseLong(value);
        if (longValue == null) {
            return new BooleanValueMatcher(false);
        }

        return new ValueMatcher() {
            // store the primitive, so we don't unbox for every comparison
            final long unboxedLong = longValue;

            @Override
            public boolean matches() {
                return row.getTimestampFromEpoch() == unboxedLong;
            }
        };
    } else {
        final String valueOrNull = Strings.emptyToNull(value);
        return new ValueMatcher() {
            @Override
            public boolean matches() {
                return doesMatch(row.getRaw(dimension), valueOrNull);
            }
        };
    }
}

From source file:io.druid.segment.virtual.ExpressionSelectors.java

public static DimensionSelector makeDimensionSelector(final ColumnSelectorFactory columnSelectorFactory,
        final Expr expression, final ExtractionFn extractionFn) {
    final ExpressionObjectSelector baseSelector = ExpressionObjectSelector.from(columnSelectorFactory,
            expression);//from w  w w  . j ava 2 s.  c  o m

    if (extractionFn == null) {
        class DefaultExpressionDimensionSelector extends BaseSingleValueDimensionSelector {
            @Override
            protected String getValue() {
                return Strings.emptyToNull(baseSelector.getObject().asString());
            }

            @Override
            public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
                inspector.visit("baseSelector", baseSelector);
            }
        }
        return new DefaultExpressionDimensionSelector();
    } else {
        class ExtractionExpressionDimensionSelector extends BaseSingleValueDimensionSelector {
            @Override
            protected String getValue() {
                return extractionFn.apply(Strings.emptyToNull(baseSelector.getObject().asString()));
            }

            @Override
            public void inspectRuntimeShape(RuntimeShapeInspector inspector) {
                inspector.visit("baseSelector", baseSelector);
                inspector.visit("extractionFn", extractionFn);
            }
        }
        return new ExtractionExpressionDimensionSelector();
    }
}