本文整理了Java中org.apache.commons.lang.StringUtils.defaultString()
方法的一些代码示例,展示了StringUtils.defaultString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.defaultString()
方法的具体详情如下:
包路径:org.apache.commons.lang.StringUtils
类名称:StringUtils
方法名:defaultString
StringUtils.defaultString介绍
[英]Returns either the passed in String, or if the String is null
, an empty String ("").
StringUtils.defaultString(null) = ""
StringUtils.defaultString("") = ""
StringUtils.defaultString("bat") = "bat"
[中]返回传入的字符串,如果字符串为null
,则返回空字符串(“”)。
StringUtils.defaultString(null) = ""
StringUtils.defaultString("") = ""
StringUtils.defaultString("bat") = "bat"
代码示例
代码示例来源:origin: SonarSource/sonarqube
public ProjectDefinition setName(String s) {
properties.put(CoreProperties.PROJECT_NAME_PROPERTY, StringUtils.defaultString(s));
return this;
}
代码示例来源:origin: apache/hive
/**
* Logs into the log file. Handles an extra detail which will not be printed if null.
* BeeLine uses the operation log file to show the logs to the user, so depending on the
* BeeLine settings it could be shown to the user.
* @param info The log message
* @param detail Extra detail to log which will be not printed if null
*/
public void logInfo(String info, String detail) {
LOG.info(info + StringUtils.defaultString(detail));
}
代码示例来源:origin: SonarSource/sonarqube
public String validKey(String key) {
requireNonNull(key, "key can't be null");
String trimmedKey = key.trim();
return StringUtils.defaultString(deprecatedKeys.get(trimmedKey), trimmedKey);
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public File newFile(@Nullable String prefix, @Nullable String suffix) {
try {
return junit.newFile(StringUtils.defaultString(prefix) + "-" + StringUtils.defaultString(suffix));
} catch (IOException e) {
throw new IllegalStateException("Fail to create temp file", e);
}
}
}
代码示例来源:origin: SonarSource/sonarqube
public MinimumViableSystem checkRequiredJavaOptions(Map requiredJavaOptions) {
for (Map.Entry entry : requiredJavaOptions.entrySet()) {
String value = System.getProperty(entry.getKey());
if (!StringUtils.equals(value, entry.getValue())) {
throw new MessageException(format(
"JVM option '%s' must be set to '%s'. Got '%s'", entry.getKey(), entry.getValue(), StringUtils.defaultString(value)));
}
}
return this;
}
}
代码示例来源:origin: SonarSource/sonarqube
/**
* @deprecated to be dropped in 4.4. Default values are declared in ws metadata
*/
@CheckForNull
@Deprecated
public String param(String key, @CheckForNull String defaultValue) {
return StringUtils.defaultString(param(key), defaultValue);
}
代码示例来源:origin: commons-lang/commons-lang
/**
* Gets a short message summarising the exception.
*
* The message returned is of the form
* {ClassNameWithoutPackage}: {ThrowableMessage}
*
* @param th the throwable to get a message for, null returns empty string
* @return the message, non-null
* @since Commons Lang 2.2
*/
public static String getMessage(Throwable th) {
if (th == null) {
return "";
}
String clsName = ClassUtils.getShortClassName(th, null);
String msg = th.getMessage();
return clsName + ": " + StringUtils.defaultString(msg);
}
代码示例来源:origin: jenkinsci/jenkins
@DataBoundConstructor
public BuildTrigger(String childProjects, String threshold) {
this(childProjects, Result.fromString(StringUtils.defaultString(threshold, Result.SUCCESS.toString())));
}
代码示例来源:origin: jenkinsci/jenkins
@CheckForNull
public FilePath getRootPath() {
final SlaveComputer computer = getComputer();
if (computer == null) {
// if computer is null then channel is null and thus we were going to return null anyway
return null;
} else {
return createPath(StringUtils.defaultString(computer.getAbsoluteRemoteFs(), remoteFS));
}
}
代码示例来源:origin: SonarSource/sonarqube
LineHashKey(Trackable trackable) {
this.ruleKey = trackable.getRuleKey();
this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
@Override
public List paramAsStrings(String key) {
WebService.Param definition = action.param(key);
String value = defaultString(readParam(key, definition), definition.defaultValue());
if (value == null) {
return null;
}
List values = COMMA_SPLITTER.splitToList(value);
return validateValues(values, definition);
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
private String readParam(String key, @Nullable WebService.Param definition) {
checkArgument(definition != null, "BUG - parameter '%s' is undefined for action '%s'", key, action.key());
String deprecatedKey = definition.deprecatedKey();
return deprecatedKey != null ? defaultString(readParam(deprecatedKey), readParam(key)) : readParam(key);
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public Map loadAll() {
try (DbSession dbSession = dbClient.openSession(false)) {
return dbClient.propertiesDao().selectGlobalProperties(dbSession)
.stream()
.collect(MoreCollectors.uniqueIndex(PropertyDto::getKey, p -> defaultString(p.getValue())));
}
}
代码示例来源:origin: SonarSource/sonarqube
protected LineAndLineHashKey(Trackable trackable) {
this.ruleKey = trackable.getRuleKey();
this.line = trackable.getLine();
this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
}
代码示例来源:origin: SonarSource/sonarqube
LineHashAndMessageKey(Trackable trackable) {
this.ruleKey = trackable.getRuleKey();
this.message = trackable.getMessage();
this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public String load(String key) {
PropertyDto dto = dbClient.propertiesDao().selectGlobalProperty(key);
if (dto != null) {
return defaultString(dto.getValue());
}
return null;
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public final boolean hasComponentPermission(String permission, ComponentDto component) {
if (isRoot()) {
return true;
}
String projectUuid = defaultString(component.getMainBranchProjectUuid(), component.projectUuid());
return hasProjectUuidPermission(permission, projectUuid);
}
代码示例来源:origin: SonarSource/sonarqube
protected LineAndLineHashAndMessage(Trackable trackable) {
this.ruleKey = trackable.getRuleKey();
this.line = trackable.getLine();
this.message = trackable.getMessage();
this.lineHash = StringUtils.defaultString(trackable.getLineHash(), "");
}
代码示例来源:origin: SonarSource/sonarqube
private void loadUserSession(HttpServletRequest request, HttpServletResponse response, boolean urlSupportsSystemPasscode) {
UserSession session = requestAuthenticator.authenticate(request, response);
if (!session.isLoggedIn() && !urlSupportsSystemPasscode && config.getBoolean(CORE_FORCE_AUTHENTICATION_PROPERTY).orElse(false)) {
// authentication is required
throw AuthenticationException.newBuilder()
.setSource(Source.local(AuthenticationEvent.Method.BASIC))
.setMessage("User must be authenticated")
.build();
}
threadLocalSession.set(session);
request.setAttribute(ACCESS_LOG_LOGIN, defaultString(session.getLogin(), "-"));
}
代码示例来源:origin: SonarSource/sonarqube
private static void appendHeader(Notification notif, StringBuilder sb) {
appendLine(sb, StringUtils.defaultString(notif.getFieldValue("componentName"), notif.getFieldValue("componentKey")));
String branchName = notif.getFieldValue(FIELD_BRANCH);
if (branchName != null) {
appendField(sb, "Branch", null, branchName);
}
String pullRequest = notif.getFieldValue(FIELD_PULL_REQUEST);
if (pullRequest != null) {
appendField(sb, "Pull request", null, pullRequest);
}
appendField(sb, "Rule", null, notif.getFieldValue("ruleName"));
appendField(sb, "Message", null, notif.getFieldValue("message"));
}