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:fathom.conf.Settings.java

public String getApplicationVersion() {
    return Optional.fromNullable(Strings.emptyToNull(getString(Setting.application_version, null)))
            .or("<VERSION>");
}

From source file:org.dcache.alarms.server.LogEntryServerWrapper.java

public void setProperties(String properties) {
    this.properties = Strings.emptyToNull(properties);
}

From source file:org.jclouds.aws.ec2.compute.config.AWSEC2ComputeServiceDependenciesModule.java

@Provides
@Singleton//from   www  .ja v  a2 s . c om
@ImageQuery
protected Map<String, String> imageQuery(ValueOfConfigurationKeyOrNull config) {
    String amiQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_AMI_QUERY));
    String owners = config.apply(PROPERTY_EC2_AMI_OWNERS);
    if ("".equals(owners)) {
        amiQuery = null;
    } else if (owners != null) {
        StringBuilder query = new StringBuilder();
        if ("*".equals(owners))
            query.append("state=available;image-type=machine");
        else
            query.append("owner-id=").append(owners).append(";state=available;image-type=machine");
        Logger.getAnonymousLogger()
                .warning(String.format("Property %s is deprecated, please use new syntax: %s=%s",
                        PROPERTY_EC2_AMI_OWNERS, PROPERTY_EC2_AMI_QUERY, query.toString()));
        amiQuery = query.toString();
    }
    Builder<String, String> builder = ImmutableMap.<String, String>builder();
    if (amiQuery != null)
        builder.put(PROPERTY_EC2_AMI_QUERY, amiQuery);
    String ccQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_CC_AMI_QUERY));
    if (ccQuery != null)
        builder.put(PROPERTY_EC2_CC_AMI_QUERY, ccQuery);
    return builder.build();
}

From source file:com.reprezen.swagedit.schema.SwaggerSchema.java

/**
 * Returns the type that is reachable by the given pointer inside the JSON schema. <br/>
 * /*  ww w.j a v a  2 s  .  c om*/
 * Examples of pointers: <br/>
 * - /properties/swagger <br/>
 * - /definitions/paths
 * 
 * @param pointer
 * @return type
 */
public TypeDefinition getType(String reference) {
    if (Strings.emptyToNull(reference) == null) {
        return swaggerType.getType();
    }

    JsonPointer pointer = pointer(reference);
    JsonSchema schema = getSchema(baseURI(reference));

    return schema.get(pointer);
}

From source file:fathom.rest.swagger.SwaggerBuilder.java

public SwaggerBuilder(Settings settings, Router router, ContentTypeEngines engines, Messages messages) {
    this.settings = settings;
    this.router = router;
    this.engines = engines;
    this.messages = messages;
    List<String> languages = settings.getStrings("application.languages");
    this.defaultLanguage = languages.isEmpty() ? "en" : languages.get(0);
    this.relativeSwaggerBasePath = Optional
            .fromNullable(Strings.emptyToNull(settings.getString("swagger.basePath", null))).or("/");
}

From source file:de.bund.bfr.knime.pmm.pmfwriter.PMFWriterNodeModel.java

protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec)
        throws Exception {
    KnimeSchema schema = null;/*  ww  w  . j  a  va 2 s.co  m*/
    ModelType modelType = null;
    List<KnimeTuple> tuples;

    DataTableSpec spec = inData[0].getSpec();
    // Table has the structure Model1 + Model2 + Data
    if (SchemaFactory.conformsM12DataSchema(spec)) {
        schema = SchemaFactory.createM12DataSchema();
        tuples = PmmUtilities.getTuples(inData[0], schema);
        if (hasData(tuples)) {
            boolean identical = identicalEstModels(tuples);
            if (settings.isSecondary) {
                if (identical) {
                    modelType = ModelType.ONE_STEP_SECONDARY_MODEL;
                } else {
                    modelType = ModelType.TWO_STEP_SECONDARY_MODEL;
                }
            } else {
                if (identical) {
                    modelType = ModelType.ONE_STEP_TERTIARY_MODEL;
                } else {
                    modelType = ModelType.TWO_STEP_TERTIARY_MODEL;
                }
            }
        } else {
            modelType = ModelType.MANUAL_TERTIARY_MODEL;
        }
    }

    // Table has Model1 + Data
    else if (SchemaFactory.conformsM1DataSchema(spec)) {
        schema = SchemaFactory.createM1DataSchema();
        tuples = PmmUtilities.getTuples(inData[0], schema);

        // Check every tuple. If any tuple has data (number of data points >
        // 0) then assigns PRIMARY_MODEL_WDATA. Otherwise it assigns
        // PRIMARY_MODEL_WODATA
        modelType = ModelType.PRIMARY_MODEL_WODATA;
        for (KnimeTuple tuple : tuples) {
            PmmXmlDoc mdData = tuple.getPmmXml(TimeSeriesSchema.ATT_TIMESERIES);
            if (mdData.size() > 0) {
                modelType = ModelType.PRIMARY_MODEL_WDATA;
                break;
            }
        }
    }

    // Table only has data
    else if (SchemaFactory.conformsDataSchema(spec)) {
        schema = SchemaFactory.createDataSchema();
        tuples = PmmUtilities.getTuples(inData[0], schema);
        modelType = ModelType.EXPERIMENTAL_DATA;
    }

    // Table only has secondary model cells
    else if (SchemaFactory.conformsM2Schema(spec)) {
        schema = SchemaFactory.createM2Schema();
        tuples = PmmUtilities.getTuples(inData[0], schema);
        modelType = ModelType.MANUAL_SECONDARY_MODEL;
    } else {
        throw new Exception();
    }

    // Retrieve info from dialog
    Metadata metadata = SBMLFactory.createMetadata();

    if (settings.creatorGivenName.isEmpty()) {
        setWarningMessage("Given name missing");
    } else {
        metadata.setGivenName(settings.creatorGivenName);
    }

    if (settings.creatorFamilyName.isEmpty()) {
        setWarningMessage("Creator family name missing");
    } else {
        metadata.setFamilyName(settings.creatorFamilyName);
    }

    if (settings.creatorContact.isEmpty()) {
        setWarningMessage("Creator contact missing");
    } else {
        metadata.setContact(settings.creatorContact);
    }

    metadata.setCreatedDate(new Date(settings.createdDate).toString());
    metadata.setModifiedDate(new Date(settings.modifiedDate).toString());

    metadata.setType(modelType);
    metadata.setRights(Strings.emptyToNull(settings.license));
    metadata.setReferenceLink(Strings.emptyToNull(settings.referenceDescriptionLink));

    String modelNotes = Strings.emptyToNull(settings.notes);

    String dir = settings.outPath;
    String mdName = settings.modelName;

    // Check for existing file -> shows warning if despite overwrite being
    // false the user still executes the nod
    String filepath = String.format("%s/%s.pmfx", dir, mdName);
    File f = new File(filepath);
    if (f.exists() && !f.isDirectory() && !settings.overwrite) {
        setWarningMessage(filepath + " was not overwritten");
        return new BufferedDataTable[] {};
    }

    WriterUtils.write(tuples, isPmfx, dir, mdName, metadata, settings.splitModels, modelNotes, exec, modelType);

    return new BufferedDataTable[] {};
}

From source file:fathom.conf.Settings.java

public String getApplicationPackage() {
    return Strings.emptyToNull(getString(Setting.application_package, ""));
}

From source file:org.dcache.alarms.jdom.XmlBackedAlarmDefinitionsMap.java

public void setDefinitionsPath(String xmlDefinitionsPath) {
    Preconditions.checkNotNull(Strings.emptyToNull(xmlDefinitionsPath));
    this.xmlDefinitionsPath = xmlDefinitionsPath;
}

From source file:org.fenixedu.academic.domain.person.HumanName.java

public static String cleanupName(String name) {
    if (name == null) {
        return null;
    }/*from w  w w.  j  a  va  2  s.  c  o m*/
    return Strings.emptyToNull(CharMatcher.WHITESPACE.trimAndCollapseFrom(name, ' '));
}

From source file:org.gbif.portal.action.species.SearchAction.java

/**
 * Initializes the getTitle* functions: getDatasetTitle and getHigherTaxaTitle.
 * Because we need the non static resource bundle lookup method getText() these methods
 * unfortuantely cant be static ones and are created here instead for every action.
 *//* www.  j  a v a2  s.  c  om*/
private void initGetTitleFunctions() {
    // the function makes use of the shared and ftl exposed base searhc action title map cache
    getDatasetTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            if (Strings.emptyToNull(name) == null) {
                return null;
            }
            final UUID dsKey = UUID.fromString(name);
            if (!titles.containsKey(dsKey)) {
                titles.put(dsKey, datasetService.get(dsKey).getTitle());
            }
            return titles.get(dsKey);
        }
    };

    getHigherTaxaTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            if (Strings.emptyToNull(name) == null) {
                return null;
            }
            return usageService.get(Integer.valueOf(name), null).getCanonicalOrScientificName();
        }
    };

    getExtinctTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            return getBooleanTitle("search.facet.IS_EXTINCT", name);
        }
    };

    getHabitatTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            return getBooleanTitle("search.facet.MARINE", name);
        }
    };

    getRankTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            return getEnumTitle("rank", name);
        }
    };

    getTaxStatusTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            return getEnumTitle("taxstatus", name);
        }
    };

    getNomStatusTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            try {
                NomenclaturalStatus status = (NomenclaturalStatus) VocabularyUtils.lookupEnum(name,
                        NomenclaturalStatus.class);
                return status.getAbbreviatedLabel() != null ? status.getAbbreviatedLabel()
                        : status.name().replace("_", " ").toLowerCase();
            } catch (IllegalArgumentException e) {
                // ignore
            }
            return name;
        }
    };

    getThreatStatusTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            return getEnumTitle("threatstatus", name);
        }
    };

    getNameTypeTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            return getEnumTitle("nametype", name);
        }
    };

    getIssueTitle = new Function<String, String>() {

        @Override
        public String apply(String name) {
            return getEnumTitle("usageissue", name);
        }
    };
}