热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.commons.lang.StringUtils.defaultString()方法的使用及代码示例

本文整理了Java中org.apache.commons.lang.StringUtils.defaultString()方法的一些代码示例,展示了Stri

本文整理了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"));
}

推荐阅读
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • sklearn数据集库中的常用数据集类型介绍
    本文介绍了sklearn数据集库中常用的数据集类型,包括玩具数据集和样本生成器。其中详细介绍了波士顿房价数据集,包含了波士顿506处房屋的13种不同特征以及房屋价格,适用于回归任务。 ... [详细]
  • 本文讨论了编写可保护的代码的重要性,包括提高代码的可读性、可调试性和直观性。同时介绍了优化代码的方法,如代码格式化、解释函数和提炼函数等。还提到了一些常见的坏代码味道,如不规范的命名、重复代码、过长的函数和参数列表等。最后,介绍了如何处理数据泥团和进行函数重构,以提高代码质量和可维护性。 ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 本文详细介绍了GetModuleFileName函数的用法,该函数可以用于获取当前模块所在的路径,方便进行文件操作和读取配置信息。文章通过示例代码和详细的解释,帮助读者理解和使用该函数。同时,还提供了相关的API函数声明和说明。 ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 标题: ... [详细]
  • 本文介绍了一些Java开发项目管理工具及其配置教程,包括团队协同工具worktil,版本管理工具GitLab,自动化构建工具Jenkins,项目管理工具Maven和Maven私服Nexus,以及Mybatis的安装和代码自动生成工具。提供了相关链接供读者参考。 ... [详细]
  • REVERT权限切换的操作步骤和注意事项
    本文介绍了在SQL Server中进行REVERT权限切换的操作步骤和注意事项。首先登录到SQL Server,其中包括一个具有很小权限的普通用户和一个系统管理员角色中的成员。然后通过添加Windows登录到SQL Server,并将其添加到AdventureWorks数据库中的用户列表中。最后通过REVERT命令切换权限。在操作过程中需要注意的是,确保登录名和数据库名的正确性,并遵循安全措施,以防止权限泄露和数据损坏。 ... [详细]
author-avatar
so-sweet天地
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有