本文整理了Java中java.util.Objects.isNull()
方法的一些代码示例,展示了Objects.isNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Objects.isNull()
方法的具体详情如下:
包路径:java.util.Objects
类名称:Objects
方法名:isNull
[英]Returns true if the provided reference is null otherwise returns false.
[中]如果提供的引用为null,则返回true,否则返回false。
代码示例来源:origin: apache/storm
/**
* nullToZero.
* @param value value
* @return nullToZero
*/
private static Double nullToZero(Double value) {
return !Objects.isNull(value) ? value : 0;
}
代码示例来源:origin: apache/storm
/**
* nullToZero.
* @param value value
* @return nullToZero
*/
private static Long nullToZero(Long value) {
return !Objects.isNull(value) ? value : 0;
}
代码示例来源:origin: ctripcorp/apollo
public boolean isClusterNameUnique(String appId, String clusterName) {
Objects.requireNonNull(appId, "AppId must not be null");
Objects.requireNonNull(clusterName, "ClusterName must not be null");
return Objects.isNull(clusterRepository.findByAppIdAndName(appId, clusterName));
}
代码示例来源:origin: ctripcorp/apollo
public boolean isNamespaceUnique(String appId, String cluster, String namespace) {
Objects.requireNonNull(appId, "AppId must not be null");
Objects.requireNonNull(cluster, "Cluster must not be null");
Objects.requireNonNull(namespace, "Namespace must not be null");
return Objects.isNull(
namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId, cluster, namespace));
}
代码示例来源:origin: ctripcorp/apollo
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
Objects.requireNonNull(appId, "AppId must not be null");
Objects.requireNonNull(namespaceName, "Namespace must not be null");
return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName));
}
代码示例来源:origin: ctripcorp/apollo
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
Objects.requireNonNull(appId, "AppId must not be null");
Objects.requireNonNull(namespaceName, "Namespace must not be null");
return Objects.isNull(appNamespaceRepository.findByAppIdAndName(appId, namespaceName));
}
代码示例来源:origin: ctripcorp/apollo
public boolean isAppIdUnique(String appId) {
Objects.requireNonNull(appId, "AppId must not be null");
return Objects.isNull(appRepository.findByAppId(appId));
}
代码示例来源:origin: hibernate/hibernate-orm
@SuppressWarnings("unchecked")
public static <T> ValueGenerator<T> get(final Class<T> type) {
final ValueGenerator<?> valueGeneratorSupplier = generators.get(
type );
if ( Objects.isNull( valueGeneratorSupplier ) ) {
throw new HibernateException(
"Unsupported property type [" + type.getName() + "] for @CreationTimestamp or @UpdateTimestamp generator annotation" );
}
return (ValueGenerator<T>) valueGeneratorSupplier;
}
}
代码示例来源:origin: ctripcorp/apollo
@Override
public Release loadConfig(String clientAppId, String clientIp, String configAppId, String configClusterName,
String configNamespace, String dataCenter, ApolloNotificationMessages clientMessages) {
// load from specified cluster fist
if (!Objects.equals(ConfigConsts.CLUSTER_NAME_DEFAULT, configClusterName)) {
Release clusterRelease = findRelease(clientAppId, clientIp, configAppId, configClusterName, configNamespace,
clientMessages);
if (!Objects.isNull(clusterRelease)) {
return clusterRelease;
}
}
// try to load via data center
if (!Strings.isNullOrEmpty(dataCenter) && !Objects.equals(dataCenter, configClusterName)) {
Release dataCenterRelease = findRelease(clientAppId, clientIp, configAppId, dataCenter, configNamespace,
clientMessages);
if (!Objects.isNull(dataCenterRelease)) {
return dataCenterRelease;
}
}
// fallback to default release
return findRelease(clientAppId, clientIp, configAppId, ConfigConsts.CLUSTER_NAME_DEFAULT, configNamespace,
clientMessages);
}
代码示例来源:origin: yu199195/hmily
@Override
public Boolean updateRetry(final String id, final Integer retry, final String appName) {
if (StringUtils.isBlank(id) || StringUtils.isBlank(appName) || Objects.isNull(retry)) {
return false;
}
final String tableName = RepositoryPathUtils.buildDbTableName(appName);
String sqlBuilder =
String.format("update %s set retried_count = %d,last_time= '%s' where trans_id =%s",
tableName, retry, DateUtils.getCurrentDateTime(), id);
jdbcTemplate.execute(sqlBuilder);
return Boolean.TRUE;
}
代码示例来源:origin: codingapi/tx-lcn
@Override
public void removeAttachments(String groupId, String unitId) {
GroupCache groupCache = transactionInfoMap.get(groupId);
if (Objects.isNull(groupCache)) {
return;
}
groupCache.getUnits().remove(unitId);
if (groupCache.getUnits().size() == 0) {
transactionInfoMap.remove(groupId);
}
}
代码示例来源:origin: skylot/jadx
private void test() {
TestCls thisVar = this;
if (Objects.isNull(thisVar)) {
System.out.println("null");
}
thisVar.method();
thisVar.field = 123;
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Collector collector = collectorService.find(modelId.id());
if (isNull(collector)) {
LOG.debug("Couldn't find collector {}", entityDescriptor);
return Optional.empty();
}
return Optional.of(exportNativeEntity(collector, entityDescriptorIds));
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Configuration configuration = configurationService.find(modelId.id());
if (isNull(configuration)) {
LOG.debug("Couldn't find collector configuration {}", entityDescriptor);
return Optional.empty();
}
return Optional.of(exportNativeEntity(configuration, entityDescriptorIds));
}
代码示例来源:origin: codingapi/tx-lcn
@Override
public void deleteByFields(List<Field> fields) throws TxLoggerException {
if (Objects.isNull(dbHelper)) {
throw new TxLoggerException("系统日志被禁用");
}
StringBuilder sql = new StringBuilder("delete from t_logger where 1=1 and ");
List<String> values = whereSqlAppender(sql, fields);
dbHelper.update(sql.toString(), values.toArray(new Object[0]));
}
代码示例来源:origin: ctripcorp/apollo
/**
* @param clientAppId the application which uses public config
* @param namespace the namespace
* @param dataCenter the datacenter
*/
private Release findPublicConfig(String clientAppId, String clientIp, String clusterName,
String namespace, String dataCenter, ApolloNotificationMessages clientMessages) {
AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespace);
//check whether the namespace's appId equals to current one
if (Objects.isNull(appNamespace) || Objects.equals(clientAppId, appNamespace.getAppId())) {
return null;
}
String publicConfigAppId = appNamespace.getAppId();
return configService.loadConfig(clientAppId, clientIp, publicConfigAppId, clusterName, namespace, dataCenter,
clientMessages);
}
代码示例来源:origin: ctripcorp/apollo
@Transactional
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@PostMapping(value = "/consumers")
public ConsumerToken createConsumer(@RequestBody Consumer consumer,
@RequestParam(value = "expires", required = false)
@DateTimeFormat(pattern = "yyyyMMddHHmmss") Date
expires) {
if (StringUtils.isContainEmpty(consumer.getAppId(), consumer.getName(),
consumer.getOwnerName(), consumer.getOrgId())) {
throw new BadRequestException("Params(appId、name、ownerName、orgId) can not be empty.");
}
Consumer createdConsumer = consumerService.createConsumer(consumer);
if (Objects.isNull(expires)) {
expires = DEFAULT_EXPIRES;
}
return consumerService.generateAndSaveConsumerToken(createdConsumer, expires);
}
代码示例来源:origin: ctripcorp/apollo
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@PostMapping("/server/config")
public ServerConfig createOrUpdate(@Valid @RequestBody ServerConfig serverConfig) {
String modifiedBy = userInfoHolder.getUser().getUserId();
ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());
if (Objects.isNull(storedConfig)) {//create
serverConfig.setDataChangeCreatedBy(modifiedBy);
serverConfig.setDataChangeLastModifiedBy(modifiedBy);
serverConfig.setId(0L);//为空,设置ID 为0,jpa执行新增操作
return serverConfigRepository.save(serverConfig);
} else {//update
BeanUtils.copyEntityProperties(serverConfig, storedConfig);
storedConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(storedConfig);
}
}
代码示例来源:origin: baomidou/mybatis-plus
/**
* 插入 OR 更新
*/
public boolean insertOrUpdate() {
return StringUtils.checkValNull(pkVal()) || Objects.isNull(selectById(pkVal())) ? insert() : updateById();
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
final Configuration configuration = configurationService.find(modelId.id());
if (isNull(configuration)) {
LOG.debug("Could not find configuration {}", entityDescriptor);
} else {
final EntityDescriptor collectorEntityDescriptor = EntityDescriptor.create(
configuration.collectorId(), ModelTypes.SIDECAR_COLLECTOR_V1);
mutableGraph.putEdge(entityDescriptor, collectorEntityDescriptor);
}
return ImmutableGraph.copyOf(mutableGraph);
}
内容来源于网络,如有侵权,请联系作者删除!