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:org.eclipse.buildship.ui.wizard.project.ProjectImportWizardController.java

public ProjectImportWizardController(IWizard projectImportWizard) {
    // assemble configuration object that serves as the data model of the wizard
    Validator<File> projectDirValidator = Validators
            .requiredDirectoryValidator(ProjectWizardMessages.Label_ProjectRootDirectory);
    Validator<GradleDistributionWrapper> gradleDistributionValidator = GradleDistributionValidator
            .gradleDistributionValidator();
    Validator<Boolean> applyWorkingSetsValidator = Validators.nullValidator();
    Validator<List<String>> workingSetsValidator = Validators.nullValidator();

    this.configuration = new ProjectImportConfiguration(projectDirValidator, gradleDistributionValidator,
            applyWorkingSetsValidator, workingSetsValidator);

    // initialize values from the persisted dialog settings
    IDialogSettings dialogSettings = projectImportWizard.getDialogSettings();
    Optional<File> projectDir = FileUtils.getAbsoluteFile(dialogSettings.get(SETTINGS_KEY_PROJECT_DIR));
    Optional<String> gradleDistributionType = Optional
            .fromNullable(Strings.emptyToNull(dialogSettings.get(SETTINGS_KEY_GRADLE_DISTRIBUTION_TYPE)));
    Optional<String> gradleDistributionConfiguration = Optional.fromNullable(
            Strings.emptyToNull(dialogSettings.get(SETTINGS_KEY_GRADLE_DISTRIBUTION_CONFIGURATION)));
    boolean applyWorkingSets = dialogSettings.get(SETTINGS_KEY_APPLY_WORKING_SETS) != null
            && dialogSettings.getBoolean(SETTINGS_KEY_APPLY_WORKING_SETS);
    List<String> workingSets = ImmutableList
            .copyOf(CollectionsUtils.nullToEmpty(dialogSettings.getArray(SETTINGS_KEY_WORKING_SETS)));

    this.configuration.setProjectDir(projectDir.orNull());
    this.configuration.setGradleDistribution(
            createGradleDistribution(gradleDistributionType, gradleDistributionConfiguration));
    this.configuration.setApplyWorkingSets(applyWorkingSets);
    this.configuration.setWorkingSets(workingSets);

    // store the values every time they change
    saveFilePropertyWhenChanged(dialogSettings, SETTINGS_KEY_PROJECT_DIR, this.configuration.getProjectDir());
    saveGradleWrapperPropertyWhenChanged(dialogSettings, this.configuration.getGradleDistribution());
    saveBooleanPropertyWhenChanged(dialogSettings, SETTINGS_KEY_APPLY_WORKING_SETS,
            this.configuration.getApplyWorkingSets());
    saveStringArrayPropertyWhenChanged(dialogSettings, SETTINGS_KEY_WORKING_SETS,
            this.configuration.getWorkingSets());
}

From source file:com.googlesource.gerrit.plugins.github.oauth.GitHubOAuthConfig.java

private List<Scope> parseScopesString(String scopesString) {
    ArrayList<Scope> scopes = new ArrayList<OAuthProtocol.Scope>();
    if (Strings.emptyToNull(scopesString) != null) {
        String[] scopesStrings = scopesString.split(",");
        for (String scope : scopesStrings) {
            scopes.add(Enum.valueOf(Scope.class, scope));
        }/*from  w  w w. jav a  2  s  . c o m*/
    }

    return scopes;
}

From source file:org.activityinfo.server.command.handler.crud.ActivityPolicy.java

private void applyProperties(Activity activity, PropertyMap changes) {
    if (changes.containsKey("name")) {
        activity.setName((String) changes.get("name"));
    }//w w w . j av  a 2 s .  c  o  m

    if (changes.containsKey("locationTypeId")) {
        LocationType location = em.find(LocationType.class, changes.get("locationTypeId"));
        if (location != null) {
            activity.setLocationType(location);
        }
    }

    if (changes.containsKey("locationType")) {
        activity.setLocationType(
                em.getReference(LocationType.class, ((LocationTypeDTO) changes.get("locationType")).getId()));
    }

    if (changes.containsKey("category")) {
        String category = Strings.nullToEmpty((String) changes.get("category")).trim();
        activity.setCategory(Strings.emptyToNull(category));
    }

    if (changes.containsKey("mapIcon")) {
        activity.setMapIcon((String) changes.get("mapIcon"));
    }

    if (changes.containsKey("reportingFrequency")) {
        activity.setReportingFrequency((Integer) changes.get("reportingFrequency"));
    }

    if (changes.containsKey("published")) {
        activity.setPublished((Integer) changes.get("published"));
    }

    if (changes.containsKey("classicView")) {
        activity.setClassicView((Boolean) changes.get("classicView"));
    }

    if (changes.containsKey("sortOrder")) {
        activity.setSortOrder((Integer) changes.get("sortOrder"));
    }

    activity.getDatabase().setLastSchemaUpdate(new Date());
}

From source file:de.bund.bfr.knime.pmm.js.common.Indep.java

/**
 * Sets the original name of this {@link Indep}.
 * //from   w w  w  . j  a  va  2s.  com
 * Empty strings are converted to null.
 * 
 * @param origname
 *            the original name to be set
 */
public void setOrigname(String origname) {
    this.origname = Strings.emptyToNull(origname);
}

From source file:de.bund.bfr.knime.pmm.js.common.Misc.java

/**
 * Sets the name of this {@link Misc}./*from  w  ww . j a va  2 s  . c o  m*/
 * 
 * Empty strings are converted to null.
 * 
 * @param name the name to be set
 */
public void setName(final String name) {
    this.name = Strings.emptyToNull(name);
}

From source file:net.minecraftforge.gradle.user.patcherUser.forge.ForgeExtension.java

private void checkAndSetVersion(String str) {
    str = str.trim();//from  w  ww  .jav a  2 s .c o m

    // build number
    if (isAllNums(str)) {
        boolean worked = getFromBuildNumber(str);
        if (worked)
            return;
    }

    // promotions
    if (this.forgeJson != null && this.forgeJson.promos != null && this.forgeJson.promos.containsKey(str)) {
        boolean worked = getFromBuildNumber(this.forgeJson.promos.get(str));
        LOGGER.lifecycle("Selected version " + this.forgeVersion);
        if (worked)
            return;
    }

    // matches just an API version
    Matcher matcher = API.matcher(str);
    if (matcher.matches()) {
        String branch = Strings.emptyToNull(matcher.group(3));
        String forgeVersion = matcher.group(1);

        try {
            ForgeBuild build = this.forgeJson.number.get(Integer.valueOf(matcher.group(2)));

            if (build == null) {
                throw new GradleConfigurationException("No such version exists!");
            }

            boolean branchMatches = false;
            if (branch == null)
                branchMatches = Strings.isNullOrEmpty(build.branch);
            else
                branchMatches = branch.substring(1).equals(build.branch);

            String outBranch = build.branch;
            if (outBranch == null)
                outBranch = "";
            else
                outBranch = "-" + build.branch;

            if (!build.version.equals(forgeVersion) || !branchMatches) {
                throw new GradleConfigurationException(
                        str + " is an invalid version! did you mean '" + build.version + outBranch + "' ?");
            }

            version = build.mcversion.replace("_", "-");
            this.forgeVersion = build.version;
            if (!Strings.isNullOrEmpty(build.branch) && !"null".equals(build.branch))
                this.forgeVersion += outBranch;

        } catch (GradleConfigurationException e) {
            throw e;
        } catch (Exception e)// everythng but the gradle exception
        {
            System.out.println("Error occurred parsing version!");

            version = "1.8";// just gonna guess.. since we dont know..
            this.forgeVersion = forgeVersion;
            if (!Strings.isNullOrEmpty(branch) && !"null".equals(branch))
                this.forgeVersion += branch;
        }

        return;
    }

    // matches standard form.
    matcher = STANDARD.matcher(str);
    if (matcher.matches()) {
        String branch = matcher.group(4);
        String mcversion = matcher.group(1);

        String forgeVersion = matcher.group(2);
        String buildNumber = matcher.group(3);

        try {
            if ("0".equals(buildNumber)) {
                LOGGER.lifecycle("Assuming custom forge version!");
                version = mcversion;
                this.forgeVersion = forgeVersion + branch;
                return;
            }

            ForgeBuild build = this.forgeJson.number.get(Integer.parseInt(buildNumber));

            if (build == null) {
                throw new GradleConfigurationException("No such version exists!");
            }

            boolean branchMatches = false;
            if (Strings.isNullOrEmpty(branch))
                branchMatches = Strings.isNullOrEmpty(build.branch);
            else
                branchMatches = branch.substring(1).equals(build.branch);

            boolean mcMatches = build.mcversion.equals(mcversion);

            String outBranch = build.branch;
            if (outBranch == null)
                outBranch = "";
            else
                outBranch = "-" + build.branch;

            if (!build.version.equals(forgeVersion) || !branchMatches || !mcMatches) {
                throw new GradleConfigurationException(str + " is an invalid version! did you mean '"
                        + build.mcversion + "-" + build.version + outBranch + "' ?");
            }

            version = build.mcversion.replace("_", "-");
            this.forgeVersion = build.version;
            if (!Strings.isNullOrEmpty(build.branch) && !"null".equals(build.branch))
                this.forgeVersion += outBranch;
        } catch (GradleConfigurationException e) {
            throw e;
        } catch (Exception e)// everythng but the gradle exception
        {
            System.out.println("Error occurred parsing version!");

            version = mcversion;
            this.forgeVersion = forgeVersion;
            if (!Strings.isNullOrEmpty(branch) && !"null".equals(branch))
                this.forgeVersion += branch;
        }

        return;
    }

    throw new GradleConfigurationException(
            "Invalid version notation, or version doesnt exist! The following are valid notations. Buildnumber, version, version-branch, mcversion-version-branch, and pomotion");
}

From source file:com.haulmont.cuba.web.gui.data.PropertyWrapper.java

protected Object valueOf(Object newValue) throws Converter.ConversionException {
    if (newValue == null) {
        return null;
    }/*from  www . j  a va2 s  .  co  m*/

    final Range range = propertyPath.getRange();
    if (range == null) {
        return newValue;
    } else {
        final Object obj;
        if (range.isDatatype()) {
            Datatype<Object> datatype = range.asDatatype();
            if (newValue instanceof String) {
                try {
                    newValue = Strings.emptyToNull((String) newValue);
                    UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
                    obj = datatype.parse((String) newValue, sessionSource.getLocale());
                } catch (ParseException e) {
                    throw new Converter.ConversionException(e);
                }
            } else {
                if (newValue.getClass().equals(datatype.getJavaClass())) {
                    return newValue;
                } else {
                    Datatype newValueDatatype = Datatypes.getNN(newValue.getClass());
                    //noinspection unchecked
                    String str = newValueDatatype.format(newValue);
                    try {
                        obj = datatype.parse(str);
                    } catch (ParseException e) {
                        throw new Converter.ConversionException(e);
                    }
                }
            }
        } else {
            obj = newValue;
        }
        return obj;
    }
}

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

private boolean doesMatch(final Object raw, final String value) {
    if (raw == null) {
        return value == null;
    } else if (raw instanceof List) {
        final List theList = (List) raw;
        if (theList.isEmpty()) {
            // null should match empty rows in multi-value columns
            return value == null;
        } else {//w  w w  .j a  v  a 2  s .co m
            for (Object o : theList) {
                if (doesMatch(o, value)) {
                    return true;
                }
            }

            return false;
        }
    } else {
        return Objects.equals(Strings.emptyToNull(raw.toString()), value);
    }
}

From source file:org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5InterpolatingProver.java

@Override
protected long getMsatModel() throws SolverException {
    // Interpolation in MathSAT is buggy at least for UFs+Ints and sometimes returns a wrong "SAT".
    // In this case, model generation fails and users should try again without interpolation.
    // Example failures: "Invalid model", "non-integer model value"
    // As this is a bug in MathSAT and not in our code, we throw a SolverException.
    // We do it only in InterpolatingProver because without interpolation this is not expected.
    try {/*from   w w  w  .  ja  v a  2  s .  co  m*/
        return msat_get_model(curEnv);
    } catch (IllegalArgumentException e) {
        String msg = Strings.emptyToNull(e.getMessage());
        throw new SolverException("msat_get_model failed" + (msg != null ? " with \"" + msg + "\"" : "")
                + ", probably the actual problem is interpolation", e);
    }
}

From source file:org.jclouds.hpcloud.objectstorage.domain.CDNContainer.java

@ConstructorProperties({ "name", "cdnEnabled", "ttl", "cdnUri", "cdnSslUri", "referrerAcl", "useragentAcl",
        "logRetention" })
protected CDNContainer(@Nullable String name, boolean cdnEnabled, long ttl, @Nullable URI CDNUri,
        @Nullable URI CDNSslUri, @Nullable String referrerAcl, @Nullable String useragentAcl,
        boolean logRetention) {
    this.name = Strings.emptyToNull(name);
    this.cdnEnabled = cdnEnabled;
    this.ttl = ttl;
    this.CDNUri = CDNUri;
    this.CDNSslUri = CDNSslUri;
    this.referrerAcl = Strings.emptyToNull(referrerAcl);
    this.useragentAcl = Strings.emptyToNull(useragentAcl);
    this.logRetention = logRetention;
}