Java Code Examples for java.util.Objects#isNull()
The following examples show how to use
java.util.Objects#isNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MotanHmilyTransactionInterceptor.java From hmily with Apache License 2.0 | 6 votes |
@Override public Object interceptor(final ProceedingJoinPoint pjp) throws Throwable { HmilyTransactionContext hmilyTransactionContext = RpcMediator.getInstance().acquire(key -> { final Request request = RpcContext.getContext().getRequest(); if (Objects.nonNull(request)) { final Map<String, String> attachments = request.getAttachments(); if (attachments != null && !attachments.isEmpty()) { return attachments.get(key); } } return ""; }); if (Objects.isNull(hmilyTransactionContext)) { hmilyTransactionContext = HmilyTransactionContextLocal.getInstance().get(); } return hmilyTransactionAspectService.invoke(hmilyTransactionContext, pjp); }
Example 2
Source File: UserService.java From sanshanblog with Apache License 2.0 | 6 votes |
/** * 忘记密码 * @param email * @param token * @param responseMsgVO */ public void forgetPassword(String email, String token, ResponseMsgVO responseMsgVO) { //获得具体的user对象 UserDO userDO = userRepository.findByEmail(email); log.info("用户:{}忘记密码",userDO.getUsername()); String key = CODE_PREFIX + CodeTypeEnum.CHANGE_PWD.getValue() + userDO.getEmail(); String value = redisTemplate.opsForValue().get(key); if (!Objects.isNull(value) && value.equals(token)) { //通过随机生成字符串 暂时替换为密码 String randomPwd = randomString(20); BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); String tmpPwd=encoder.encode(randomPwd); userRepository.changePassword(userDO.getUsername(), tmpPwd); //忘记密码功能 final String loginToken = serviceAuthFeign.generateUserToken(serviceAuthConfig.getClientId(), serviceAuthConfig.getClientSecret(), userDO.getUsername(), randomPwd).getData(); JwtAuthenticationResponse response = new JwtAuthenticationResponse(loginToken); responseMsgVO.buildOKWithData(response); return; } responseMsgVO.buildWithMsgAndStatus(PosCodeEnum.PARAM_ERROR, "验证码错误"); return; }
Example 3
Source File: ApacheDubboPluginDataHandler.java From soul with Apache License 2.0 | 6 votes |
@Override public void handlerPlugin(final PluginData pluginData) { if (null != pluginData && pluginData.getEnabled()) { DubboRegisterConfig dubboRegisterConfig = GsonUtils.getInstance().fromJson(pluginData.getConfig(), DubboRegisterConfig.class); DubboRegisterConfig exist = Singleton.INST.get(DubboRegisterConfig.class); if (Objects.isNull(dubboRegisterConfig)) { return; } if (Objects.isNull(exist) || !dubboRegisterConfig.equals(exist)) { //如果是空,进行初始化操作, ApplicationConfigCache.getInstance().init(dubboRegisterConfig); ApplicationConfigCache.getInstance().invalidateAll(); } Singleton.INST.single(DubboRegisterConfig.class, dubboRegisterConfig); } }
Example 4
Source File: AppAuthServiceImpl.java From soul with Apache License 2.0 | 6 votes |
@Override public SoulAdminResult updateDetailPath(final AuthPathWarpDTO authPathWarpDTO) { AppAuthDO appAuthDO = appAuthMapper.selectById(authPathWarpDTO.getId()); if (Objects.isNull(appAuthDO)) { return SoulAdminResult.error(AdminConstants.ID_NOT_EXIST); } List<AuthPathDTO> authPathDTOList = authPathWarpDTO.getAuthPathDTOList(); if (CollectionUtils.isNotEmpty(authPathDTOList)) { authPathMapper.deleteByAuthId(authPathWarpDTO.getId()); List<AuthPathDO> collect = authPathDTOList.stream() .map(authPathDTO -> buildAuthPathDO(authPathDTO.getPath(), appAuthDO.getId(), authPathDTO.getAppName())) .collect(Collectors.toList()); authPathMapper.batchSave(collect); } eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.APP_AUTH, DataEventTypeEnum.UPDATE, Lists.newArrayList(buildByEntity(appAuthDO)))); return SoulAdminResult.success(); }
Example 5
Source File: LoggingServiceImpl.java From flow-platform-x with Apache License 2.0 | 6 votes |
@Override public Page<String> read(ExecutedCmd cmd, Pageable pageable) { BufferedReader reader = getReader(cmd.getId()); if (Objects.isNull(reader)) { return LogNotFound; } try (Stream<String> lines = reader.lines()) { int i = pageable.getPageNumber() * pageable.getPageSize(); List<String> logs = lines.skip(i) .limit(pageable.getPageSize()) .collect(Collectors.toList()); return new PageImpl<>(logs, pageable, cmd.getLogSize()); } finally { try { reader.reset(); } catch (IOException e) { // reset will be failed if all lines been read logReaderCache.invalidate(cmd.getId()); } } }
Example 6
Source File: ClouderaManagerClusterCreationSetupService.java From cloudbreak with Apache License 2.0 | 5 votes |
private ClusterComponent determineCmRepoConfig(Optional<Component> stackClouderaManagerRepoConfig, String osType, Cluster cluster, String cdhStackVersion) { Json json; if (Objects.isNull(stackClouderaManagerRepoConfig) || stackClouderaManagerRepoConfig.isEmpty()) { ClouderaManagerRepo clouderaManagerRepo = defaultClouderaManagerRepoService.getDefault( osType, StackType.CDH.name(), cdhStackVersion); if (clouderaManagerRepo == null) { throw new BadRequestException(String.format("Couldn't determine Cloudera Manager repo for the stack: %s", cluster.getStack().getName())); } json = new Json(clouderaManagerRepo); } else { json = stackClouderaManagerRepoConfig.get().getAttributes(); } return new ClusterComponent(ComponentType.CM_REPO_DETAILS, json, cluster); }
Example 7
Source File: JsonUtil.java From easy_javadoc with Apache License 2.0 | 5 votes |
public static <T> String toJson(T obj) { if (Objects.isNull(obj)) { return ""; } try { return objectMapper.writeValueAsString(obj); } catch (JsonProcessingException e) { LOGGER.warn("json序列化异常", e); return ""; } }
Example 8
Source File: AgentConfig.java From flow-platform-x with Apache License 2.0 | 5 votes |
private String getRabbitUri() { String uri = rabbitProperties.getUri().toString(); String domain = env.getProperty(App.RabbitHost); if (Objects.isNull(domain)) { return uri; } return uri.replace(rabbitProperties.getUri().getHost(), domain); }
Example 9
Source File: Person.java From JavaBase with MIT License | 5 votes |
private boolean freeze(Bed bed) { if (Objects.nonNull(this.bed) || Objects.isNull(bed)) { // System.out.println("隔离区没有空床位"); return false; } City.trans(PersonState.CONFIRMED, PersonState.FREEZE); this.bed = bed; state = PersonState.FREEZE; x = bed.getX(); y = bed.getY(); bed.setEmpty(false); return true; }
Example 10
Source File: SalaryType.java From tutorials with MIT License | 5 votes |
@Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { if (Objects.isNull(value)) st.setNull(index, Types.BIGINT); else { Salary salary = (Salary) value; st.setLong(index, SalaryCurrencyConvertor.convert(salary.getAmount(), salary.getCurrency(), localCurrency)); st.setString(index + 1, salary.getCurrency()); } }
Example 11
Source File: ValidateCodeProcessorHolder.java From spring-security-oauth2-demo with GNU General Public License v3.0 | 5 votes |
/** * 通过验证码类型查找 * * @param type 验证码类型 * @return 验证码处理器 */ ValidateCodeProcessor findValidateCodeProcessor(String type) { String name = type.toLowerCase() + ValidateCodeProcessor.class.getSimpleName(); ValidateCodeProcessor processor = validateCodeProcessors.get(name); if (Objects.isNull(processor)){ throw new ValidateCodeException("验证码处理器" + name + "不存在"); } return processor; }
Example 12
Source File: Numbers.java From Java-Coding-Problems with MIT License | 5 votes |
public static boolean integersContainsNulls(List<Integer> integers) { if (Objects.isNull(integers)) { return false; } return integers.stream() .anyMatch(Objects::isNull); }
Example 13
Source File: MapTools.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public static String getString(Map<?, ?> map, Object key, String defaultValue) { String value = null; if (null != map) { Object o = map.get(key); if (!Objects.isNull(o)) { value = o.toString(); } else { value = defaultValue; } } return value; }
Example 14
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private void clickArrowButton(String actionKey) { JButton scrollForwardButton = null; JButton scrollBackwardButton = null; for (Component c: getComponents()) { if (c instanceof JButton) { if (Objects.isNull(scrollForwardButton)) { scrollForwardButton = (JButton) c; } else if (Objects.isNull(scrollBackwardButton)) { scrollBackwardButton = (JButton) c; } } } JButton button = "scrollTabsForwardAction".equals(actionKey) ? scrollForwardButton : scrollBackwardButton; Optional.ofNullable(button) .filter(JButton::isEnabled) .ifPresent(JButton::doClick); // // ArrayIndexOutOfBoundsException // Optional.ofNullable(getActionMap()) // .map(am -> am.get(actionKey)) // .filter(Action::isEnabled) // .ifPresent(a -> a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null, 0, 0))); // // ActionMap map = getActionMap(); // // if (Objects.nonNull(map)) { // // Action action = map.get(actionKey); // // if (Objects.nonNull(action) && action.isEnabled()) { // // action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null, 0, 0)); // // } // // } }
Example 15
Source File: AbstractTxTransactionExecutor.java From Raincat with GNU Lesser General Public License v3.0 | 5 votes |
/** * 事务预提交. * * @param txGroupId 事务组id */ @Override public void preCommit(final String txGroupId) { txManagerService.updateTxTransactionItemStatus(txGroupId, txGroupId, TransactionStatusEnum.COMMIT.getCode(), null); final List<TxTransactionItem> txTransactionItems = txManagerService.listByTxGroupId(txGroupId); final Map<Boolean, List<TxTransactionItem>> listMap = filterData(txTransactionItems); if (Objects.isNull(listMap)) { LogUtil.info(LOGGER, "事务组id:{},提交失败!数据不完整", () -> txGroupId); return; } /* * 获取当前连接的channel 为什么? * 因为如果tm是集群环境,可能业务的channel对象连接到不同的tm * 那么当前的tm可没有其他业务模块的长连接信息,那么就应该做: * 1.检查当前tm的channel状态,并只提交当前渠道的命令 * 2.通知 连接到其他tm的channel,执行命令 */ final List<TxTransactionItem> currentItem = listMap.get(Boolean.TRUE); final List<TxTransactionItem> elseItems = listMap.get(Boolean.FALSE); //检查各位channel 是否都激活,渠道状态不是回滚的 final Boolean ok = checkChannel(currentItem); if (!ok) { doRollBack(txGroupId, currentItem, elseItems); } else { doCommit(txGroupId, currentItem, elseItems); } }
Example 16
Source File: AuthenticationService.java From Spring-5.0-By-Example with MIT License | 5 votes |
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String nickname = authentication.getName(); String password = (String) authentication.getCredentials(); CredentialData credentialData = this.credentialUserDetailsService.loadUserByUsername(nickname); if (Objects.isNull(credentialData) || !credentialData.getEmail().equalsIgnoreCase(nickname)) { throw new BadCredentialsException("email not found or invalid."); } if (!password.equals(credentialData.getPassword())) { throw new BadCredentialsException("wrong password."); } return new UsernamePasswordAuthenticationToken(credentialData, password, credentialData.getAuthorities()); }
Example 17
Source File: OccupationServiceImpl.java From Almost-Famous with MIT License | 4 votes |
@Override public boolean upgrade(Long rid, int schoolId, int exp) { School school = schoolDao.getSchool(rid); if (Objects.isNull(school)) { return false; } Map<Integer, SchoolBean> schools = school.getSchools(); // 职业列表 Map<Integer, OccupationConf> occupationConfMap = ConfigManager.occupationConfMap; if (!occupationConfMap.keySet().contains(schoolId)) { return false; } // 当前职业 SchoolBean schoolBean = schools.get(schoolId); // 当前职业的所有升级机制 List<OccupationConf> occupationList = occupationConfMap.values().stream() .filter(occupation -> occupation.getId() / 1000 == schoolId / 1000) .sorted(Comparator.comparing(OccupationConf::getId)) .collect(Collectors.toList()); // 目前 经验值 int nowExp = schoolBean.getExp(); OccupationConf occupationConf = occupationList.stream() .filter(occupation1 -> occupation1.getId() == schoolBean.getSchoolId()).findFirst().get(); if (Objects.isNull(occupationConf)) { return false; } // 预升级 经验值 int upgradeExp = nowExp + exp; // Level提升 更新职业ID if (upgradeExp > occupationConf.getLvUpExp() && schoolBean.getLevel() < 10) { OccupationConf upgradeOccupation = afterUpgrade(schoolBean, upgradeExp, occupationConf); if (Objects.nonNull(upgradeOccupation)) { schoolBean.setSchoolId(upgradeOccupation.getId()); schoolBean.setLevel(upgradeOccupation.getLevel()); schoolBean.setExp(upgradeExp - occupationConf.getLvUpExp()); school.getSchools().remove(schoolId); school.getSchools().putIfAbsent(upgradeOccupation.getId(), schoolBean); schoolDao.upSchool(school); } } else { schoolBean.setExp(upgradeExp); schoolDao.upSchool(school); return false; } return true; }
Example 18
Source File: LinkedList.java From JavaBase with MIT License | 4 votes |
boolean isEmpty() { return Objects.isNull(head); }
Example 19
Source File: TaskResource.java From micro-integrator with Apache License 2.0 | 4 votes |
private JSONObject convertTaskToJsonObject(TaskDescription task) { if (Objects.isNull(task)) { return null; } JSONObject taskObject = new JSONObject(); taskObject.put(Constants.NAME, task.getName()); String triggerType = "cron"; if (Objects.isNull(task.getCronExpression())) { triggerType = "simple"; } taskObject.put("triggerType", triggerType); taskObject.put("triggerCount", String.valueOf(task.getCount())); taskObject.put("triggerInterval", String.valueOf(task.getInterval())); taskObject.put("triggerCron", task.getCronExpression()); return taskObject; }
Example 20
Source File: SslConfigValidator.java From tessera with Apache License 2.0 | 4 votes |
@Override public boolean isValid(SslConfig sslConfig, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (Objects.isNull(sslConfig)) { return true; } if (sslConfig.getTls() == SslAuthenticationMode.STRICT) { if (!sslConfig.isGenerateKeyStoreIfNotExisted()) { if (!isServerKeyStoreConfigValid(sslConfig, context) || !isClientKeyStoreConfigValid(sslConfig, context)) { return false; } } if (!isTrustModeConfigValid(sslConfig, context)) { return false; } if (!isServerConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isServerConfigValidForCAMode(sslConfig, context)) { return false; } if (!isClientConfigValidForWhiteListMode(sslConfig, context)) { return false; } if (!isClientConfigValidForCAMode(sslConfig, context)) { return false; } } return true; }