本文整理了Java中com.google.common.base.Strings.emptyToNull()
方法的一些代码示例,展示了Strings.emptyToNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Strings.emptyToNull()
方法的具体详情如下:
包路径:com.google.common.base.Strings
类名称:Strings
方法名:emptyToNull
[英]Returns the given string if it is nonempty; null otherwise.
[中]如果给定字符串为非空,则返回该字符串;否则为空。
代码示例来源:origin: Graylog2/graylog2-server
@Override
public String getNodeId() {
return emptyToNull((String)fields.get(MessageInput.FIELD_NODE_ID));
}
}
代码示例来源:origin: prestodb/presto
private static String trimEmptyToNull(String value)
{
return emptyToNull(nullToEmpty(value).trim());
}
代码示例来源:origin: SonarSource/sonarqube
public Component(String uuid, @Nullable String key, @Nullable String name) {
this.uuid = requireNonNull(emptyToNull(uuid), "uuid can't be null nor empty");
this.key = emptyToNull(key);
this.name = emptyToNull(name);
}
代码示例来源:origin: Graylog2/graylog2-server
public static String cut(String s, String splitChar, int index) {
if (s == null || splitChar == null || index < 0) {
return null;
}
final String[] parts = s.split(Pattern.quote(splitChar));
if (parts.length <= index) {
return null;
}
return emptyToNull(parts[index]);
}
代码示例来源:origin: prestodb/presto
public PrestoNode(String nodeIdentifier, URI httpUri, NodeVersion nodeVersion, boolean coordinator)
{
nodeIdentifier = emptyToNull(nullToEmpty(nodeIdentifier).trim());
this.nodeIdentifier = requireNonNull(nodeIdentifier, "nodeIdentifier is null or empty");
this.httpUri = requireNonNull(httpUri, "httpUri is null");
this.nodeVersion = requireNonNull(nodeVersion, "nodeVersion is null");
this.coordinator = coordinator;
}
代码示例来源:origin: prestodb/presto
public static Optional<String> defaultCredentialCachePath()
{
String value = nullToEmpty(System.getenv("KRB5CCNAME"));
if (value.startsWith(FILE_PREFIX)) {
value = value.substring(FILE_PREFIX.length());
}
return Optional.ofNullable(emptyToNull(value));
}
}
代码示例来源:origin: apache/incubator-druid
/**
* Returns the given string if it is nonempty; {@code null} otherwise.
* This method should only be used at places where null to empty conversion is
* irrelevant to null handling of the data.
*
* @param string the string to test and possibly return
*
* @return {@code string} itself if it is nonempty; {@code null} if it is
* empty or null
*/
@Nullable
public static String emptyToNullNonDruidDataString(@Nullable String string)
{
//CHECKSTYLE.OFF: Regexp
return Strings.emptyToNull(string);
//CHECKSTYLE.ON: Regexp
}
代码示例来源:origin: Graylog2/graylog2-server
private static DateTimeZone buildTimeZone(Object timeZoneId) {
if (timeZoneId instanceof String) {
try {
final String timeZoneString = (String) timeZoneId;
final String zoneId = firstNonNull(emptyToNull(timeZoneString.trim()), "Etc/UTC");
return DateTimeZone.forID(zoneId);
} catch (IllegalArgumentException e) {
return DEFAULT_TIME_ZONE;
}
} else {
return DEFAULT_TIME_ZONE;
}
}
代码示例来源:origin: apache/incubator-druid
@Nullable
public static String emptyToNullIfNeeded(@Nullable String value)
{
//CHECKSTYLE.OFF: Regexp
return replaceWithDefault() ? Strings.emptyToNull(value) : value;
//CHECKSTYLE.ON: Regexp
}
代码示例来源:origin: Graylog2/graylog2-server
@JsonCreator
public static MatchingType valueOfOrDefault(String name) {
return (emptyToNull(name) == null ? DEFAULT : valueOf(name));
}
}
代码示例来源:origin: prestodb/presto
public static String preprocessQuery(Optional<String> catalog, Optional<String> schema, String query)
throws QueryPreprocessorException
{
Duration timeout = DEFAULT_PREPROCESSOR_TIMEOUT;
String timeoutEnvironment = nullToEmpty(System.getenv(ENV_PREPROCESSOR_TIMEOUT)).trim();
if (!timeoutEnvironment.isEmpty()) {
timeout = Duration.valueOf(timeoutEnvironment);
}
String preprocessorCommand = System.getenv(ENV_PREPROCESSOR);
if (emptyToNull(preprocessorCommand) == null) {
return query;
}
return preprocessQuery(catalog, schema, query, ImmutableList.of("/bin/sh", "-c", preprocessorCommand), timeout);
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public String create(UserDto user) {
UserDto userDto = requireNonNull(user, "User cannot be null");
return hash(requireNonNull(emptyToNull(userDto.getEmail()), "Email cannot be null"));
}
代码示例来源:origin: google/guava
public void testEmptyToNull() {
assertNull(Strings.emptyToNull(null));
assertNull(Strings.emptyToNull(""));
assertEquals("a", Strings.emptyToNull("a"));
}
代码示例来源:origin: SonarSource/sonarqube
@CheckForNull
private String getAssignee(Request request) {
String assignee = emptyToNull(request.param(PARAM_ASSIGNEE));
if (ASSIGN_TO_ME_VALUE.equals(assignee) || BooleanUtils.isTrue(request.paramAsBoolean(DEPRECATED_PARAM_ME))) {
return userSession.getLogin();
}
return assignee;
}
代码示例来源:origin: prestodb/presto
public static Column fromMetastoreApiFieldSchema(FieldSchema fieldSchema)
{
return new Column(fieldSchema.getName(), HiveType.valueOf(fieldSchema.getType()), Optional.ofNullable(emptyToNull(fieldSchema.getComment())));
}
代码示例来源:origin: SonarSource/sonarqube
private Users.User.Builder formatUser(UserDto user) {
Users.User.Builder builder = Users.User.newBuilder()
.setLogin(user.getLogin())
.setName(nullToEmpty(user.getName()))
.setActive(user.isActive());
ofNullable(emptyToNull(user.getEmail())).ifPresent(email -> builder.setAvatar(avatarFactory.create(user)));
return builder;
}
代码示例来源:origin: SonarSource/sonarqube
private SearchUsersResponse.User toUser(UserDto user, boolean isSelected) {
SearchUsersResponse.User.Builder builder = SearchUsersResponse.User.newBuilder()
.setLogin(user.getLogin())
.setName(user.getName())
.setSelected(isSelected);
ofNullable(emptyToNull(user.getEmail())).ifPresent(e -> builder.setAvatar(avatarResolver.create(user)));
return builder
.build();
}
代码示例来源:origin: SonarSource/sonarqube
private AddMemberWsResponse buildResponse(UserDto user, int groups) {
AddMemberWsResponse.Builder response = AddMemberWsResponse.newBuilder();
User.Builder wsUser = User.newBuilder()
.setLogin(user.getLogin())
.setName(user.getName())
.setGroupCount(groups);
ofNullable(emptyToNull(user.getEmail())).ifPresent(text -> wsUser.setAvatar(avatarResolver.create(user)));
response.setUser(wsUser);
return response.build();
}
代码示例来源:origin: SonarSource/sonarqube
private static ActiveRule convert(ScannerReport.ActiveRule input, Rule rule) {
RuleKey key = RuleKey.of(input.getRuleRepository(), input.getRuleKey());
Map<String, String> params = new HashMap<>(input.getParamsByKeyMap());
long updatedAt = input.getUpdatedAt();
return new ActiveRule(key, input.getSeverity().name(), params, updatedAt == 0 ? input.getCreatedAt() : updatedAt, rule.getPluginKey(), emptyToNull(input.getQProfileKey()));
}
}
代码示例来源:origin: SonarSource/sonarqube
private static CreateWsResponse buildResponse(UserDto userDto) {
CreateWsResponse.User.Builder userBuilder = CreateWsResponse.User.newBuilder()
.setLogin(userDto.getLogin())
.setName(userDto.getName())
.setActive(userDto.isActive())
.setLocal(userDto.isLocal())
.addAllScmAccounts(userDto.getScmAccountsAsList());
ofNullable(emptyToNull(userDto.getEmail())).ifPresent(userBuilder::setEmail);
return CreateWsResponse.newBuilder().setUser(userBuilder).build();
}
内容来源于网络,如有侵权,请联系作者删除!