Java Code Examples for java.util.Objects#nonNull()
The following examples show how to use
java.util.Objects#nonNull() .
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: MainPanel.java From java-swing-tips with MIT License | 7 votes |
private int getOtherToken(String content, int startOffset, int endOffset) { int endOfToken = startOffset + 1; while (endOfToken <= endOffset) { if (isDelimiter(content.substring(endOfToken, endOfToken + 1))) { break; } endOfToken++; } String token = content.substring(startOffset, endOfToken); Style s = getStyle(token); // if (keywords.containsKey(token)) { // setCharacterAttributes(startOffset, endOfToken - startOffset, keywords.get(token), false); if (Objects.nonNull(s)) { setCharacterAttributes(startOffset, endOfToken - startOffset, s, false); } return endOfToken + 1; }
Example 2
Source File: ConfigHandler.java From netstrap with Apache License 2.0 | 7 votes |
/** * 获取配置属性 */ private Map<String, String> getConfigProperties(Class<?> clz, ConfigReader configReader) throws IOException { Configurable configurable = clz.getAnnotation(Configurable.class); InputStream input = null; Map<String, String> properties; try { ResourceReader reader = ResourceReader.getReader(configurable.protocol()); input = reader.load(configurable.path()); properties = configReader.readByInputStream(input); } finally { if (Objects.nonNull(input)) { input.close(); } } return properties; }
Example 3
Source File: ECBAbstractRateProvider.java From jsr354-ri with Apache License 2.0 | 7 votes |
private RateResult findExchangeRate(ConversionQuery conversionQuery) { LocalDate[] dates = getQueryDates(conversionQuery); if (dates == null) { Comparator<LocalDate> comparator = Comparator.naturalOrder(); LocalDate date = this.rates.keySet().stream() .max(comparator) .orElseThrow(() -> new MonetaryException("There is not more recent exchange rate to rate on ECBRateProvider.")); return new RateResult(this.rates.get(date)); } else { for (LocalDate localDate : dates) { Map<String, ExchangeRate> targets = this.rates.get(localDate); if(Objects.nonNull(targets)) { return new RateResult(targets); } } String datesOnErros = Stream.of(dates).map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE)).collect(Collectors.joining(",")); throw new MonetaryException("There is not exchange on day " + datesOnErros + " to rate to rate on ECBRateProvider."); } }
Example 4
Source File: JakduService.java From jakduk-api with MIT License | 7 votes |
public Jakdu setMyJakdu(CommonWriter writer, MyJakduRequest myJakdu) { JakduSchedule jakduSchedule = jakduScheduleRepository.findById(myJakdu.getJakduScheduleId()).orElseThrow(() -> new ServiceException(ServiceError.NOT_FOUND_JAKDUSCHEDULE)); if (Objects.isNull(jakduSchedule)) throw new NoSuchElementException(JakdukUtils.getMessageSource("jakdu.msg.not.found.jakdu.schedule.exception")); JakduOnSchedule existJakdu = jakduRepository.findByUserIdAndWriter(writer.getUserId(), new ObjectId(jakduSchedule.getId())); if (Objects.nonNull(existJakdu)) throw new ServiceException(ServiceError.INTERNAL_SERVER_ERROR, JakdukUtils.getMessageSource("jakdu.msg.already.join.jakdu.exception")); Jakdu jakdu = new Jakdu(); jakdu.setSchedule(jakduSchedule); jakdu.setWriter(writer); jakdu.setHomeScore(myJakdu.getHomeScore()); jakdu.setAwayScore(myJakdu.getAwayScore()); jakduRepository.save(jakdu); return jakdu; }
Example 5
Source File: DeviceCommand.java From devicehive-java-server with Apache License 2.0 | 7 votes |
@Override public void writePortable(PortableWriter portableWriter) throws IOException { portableWriter.writeLong("id", Objects.nonNull(id) ? id : 0); portableWriter.writeUTF("command", command); portableWriter.writeLong("timestamp", Objects.nonNull(timestamp) ? timestamp.getTime() :0); portableWriter.writeLong("lastUpdated", Objects.nonNull(lastUpdated) ? lastUpdated.getTime() :0); portableWriter.writeLong("userId", Objects.nonNull(userId) ? userId : 0); portableWriter.writeUTF("deviceId", deviceId); portableWriter.writeLong("networkId", Objects.nonNull(networkId) ? networkId : 0); portableWriter.writeLong("deviceTypeId", Objects.nonNull(deviceTypeId) ? deviceTypeId : 0); boolean parametersIsNotNull = Objects.nonNull(parameters) && Objects.nonNull(parameters.getJsonString()); portableWriter.writeUTF("parameters", parametersIsNotNull ? parameters.getJsonString() : null); portableWriter.writeInt("lifetime", Objects.nonNull(lifetime) ? lifetime : 0); portableWriter.writeUTF("status", status); boolean resultIsNotNull = Objects.nonNull(result) && Objects.nonNull(result.getJsonString()); portableWriter.writeUTF("result", resultIsNotNull ? result.getJsonString() : null); portableWriter.writeBoolean("isUpdated", Objects.nonNull(isUpdated)? isUpdated : false); }
Example 6
Source File: JPAPermissionTicketStore.java From keycloak with Apache License 2.0 | 6 votes |
@Override public List<PermissionTicket> findByResourceServer(final String resourceServerId) { TypedQuery<String> query = entityManager.createNamedQuery("findPolicyIdByServerId", String.class); query.setParameter("serverId", resourceServerId); List<String> result = query.getResultList(); List<PermissionTicket> list = new LinkedList<>(); PermissionTicketStore ticketStore = provider.getStoreFactory().getPermissionTicketStore(); for (String id : result) { PermissionTicket ticket = ticketStore.findById(id, resourceServerId); if (Objects.nonNull(ticket)) { list.add(ticket); } } return list; }
Example 7
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void hierarchyChanged(HierarchyEvent e) { boolean isDisplayableChanged = (e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0; if (isDisplayableChanged && !e.getComponent().isDisplayable() && Objects.nonNull(worker)) { System.out.println("DISPOSE_ON_CLOSE"); worker.cancel(true); worker = null; } }
Example 8
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void setSelectedIndex(int index) { TreeNode node = getItemAt(index); if (Objects.nonNull(node) && node.isLeaf()) { super.setSelectedIndex(index); } else { isNotSelectableIndex = true; } }
Example 9
Source File: AsciiTreeGenerator.java From AsciidocFX with Apache License 2.0 | 5 votes |
private void printFile(StringBuilder sb, Tree leaf) { sb.append(getIndentString(leaf)); if (Objects.nonNull(leaf.getParent())) { if (Objects.isNull(leaf.getNextSibling())) sb.append("`--"); else sb.append("|--"); } sb.append(leaf.getName()); if (!leaf.isLastChild()) sb.append("\n"); }
Example 10
Source File: VStsClient.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private int getTestPointId(String project, int testPlanId, String suite, String testCase) { try { JSONObject res = httpClient.Get(getUrl(buildUrl(getTestPlanUrl(project, testPlanId) + "/suites/" + getTestSuiteId(project, testPlanId, suite) + "/points?witFields=System.Title"))); JSONObject testpoint = getTestPoint((JSONArray) res.get("value"), testCase); if (Objects.nonNull(testpoint)) { return Integer.parseInt(testpoint.get("id").toString()); } } catch (Exception ex) { LOGGER.log(Level.SEVERE, null, ex); } return -1; }
Example 11
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 12
Source File: AuthScopeStoreImpl.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
@Override public boolean authorize(String authScopeName, Set<String> userGroups) throws AuthNotFoundException { try { AuthScope authScope = authScopeCache.get(authScopeName); return Objects.nonNull(authScope) && authScope.getUserGroups().stream().anyMatch(userGroups::contains); } catch (ExecutionException e) { throw new AuthNotFoundException("A scope was not found for the scope name: " + authScopeName, e); } }
Example 13
Source File: CacheZuulRouteStorage.java From heimdall with Apache License 2.0 | 5 votes |
/** * Gets a ordered List of {@link ZuulRoute}. * * @return A ordered List of {@link ZuulRoute} */ public List<ZuulRoute> init() { log.info("Initialize routes from profiles: " + profile); List<ZuulRoute> routes = new LinkedList<>(); List<Long> apiIds = apiJDBCRepository.findAllIds(); boolean production = Constants.PRODUCTION.equals(profile); String destination; if (production) { destination = "producao"; } else { destination = "sandbox"; } List<String> apiPathConcatWithOperationPaths = null; if (apiIds != null && !apiIds.isEmpty()) { apiPathConcatWithOperationPaths = operationJDBCRepository.findOperationsFromAllApis(apiIds); } if (Objects.nonNull(apiPathConcatWithOperationPaths) && !apiPathConcatWithOperationPaths.isEmpty()) { for (String completePath : apiPathConcatWithOperationPaths) { ZuulRoute route = new ZuulRoute(completePath, destination); route.setStripPrefix(false); route.setSensitiveHeaders(Collections.newSetFromMap(new ConcurrentHashMap<>())); route.setRetryable(retryable); routes.add(route); } } routes.sort(new RouteSort()); return routes; }
Example 14
Source File: Attributes.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
public void update(Attribute a) { if (Objects.nonNull(a)) { Optional<Attribute> attRes = find(a.getName()); if (attRes.isPresent()) { attRes.get().setValue(a.getValue()); } else { this.add(a); } } }
Example 15
Source File: TerminalService.java From cloudterm with MIT License | 5 votes |
public void onTerminalResize(String columns, String rows) { if (Objects.nonNull(columns) && Objects.nonNull(rows)) { this.columns = Integer.valueOf(columns); this.rows = Integer.valueOf(rows); if (Objects.nonNull(process)) { process.setWinSize(new WinSize(this.columns, this.rows)); } } }
Example 16
Source File: DataSourceAspect.java From RuoYi-Vue with MIT License | 5 votes |
/** * 获取需要切换的数据源 */ public DataSource getDataSource(ProceedingJoinPoint point) { MethodSignature signature = (MethodSignature) point.getSignature(); DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class); if (Objects.nonNull(dataSource)) { return dataSource; } return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class); }
Example 17
Source File: UserService.java From jakduk-api with MIT License | 5 votes |
public User createJakdukUser(String email, String username, String password, String footballClub, String about, String userPictureId) { UserPicture userPicture = null; User user = new User(); user.setEmail(email); user.setUsername(username); user.setPassword(passwordEncoder.encode(password)); user.setProviderId(Constants.ACCOUNT_TYPE.JAKDUK); user.setRoles(Collections.singletonList(JakdukAuthority.ROLE_USER_01.getCode())); this.setUserAdditionalInfo(user, footballClub, about); if (StringUtils.isNotBlank(userPictureId)) { userPicture = userPictureRepository.findOneById(userPictureId.trim()) .orElseThrow(() -> new ServiceException(ServiceError.NOT_FOUND_USER_IMAGE)); user.setUserPicture(userPicture); } userRepository.save(user); if (Objects.nonNull(userPicture)) { userPicture.setStatus(Constants.GALLERY_STATUS_TYPE.ENABLE); userPictureRepository.save(userPicture); } log.info("JakduK user created. {}", user); return user; }
Example 18
Source File: GlossaryTermUtils.java From atlas with Apache License 2.0 | 4 votes |
private void processTermAnchor(AtlasGlossaryTerm storeObject, AtlasGlossaryTerm updatedTerm, RelationshipOperation op) throws AtlasBaseException { if (Objects.isNull(updatedTerm.getAnchor()) && op != RelationshipOperation.DELETE) { throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ANCHOR); } AtlasGlossaryHeader existingAnchor = storeObject.getAnchor(); AtlasGlossaryHeader updatedTermAnchor = updatedTerm.getAnchor(); switch (op) { case CREATE: if (Objects.isNull(updatedTermAnchor.getGlossaryGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_NEW_ANCHOR_GUID); } else { if (DEBUG_ENABLED) { LOG.debug("Creating new term anchor, category = {}, glossary = {}", storeObject.getGuid(), updatedTerm.getAnchor().getGlossaryGuid()); } createRelationship(defineTermAnchorRelation(updatedTermAnchor.getGlossaryGuid(), storeObject.getGuid())); } break; case UPDATE: if (!Objects.equals(updatedTermAnchor, existingAnchor)) { if (Objects.isNull(updatedTermAnchor.getGlossaryGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_NEW_ANCHOR_GUID); } if (DEBUG_ENABLED) { LOG.debug("Updating term anchor, currAnchor = {}, newAnchor = {} and term = {}", existingAnchor.getGlossaryGuid(), updatedTermAnchor.getGlossaryGuid(), storeObject.getName()); } relationshipStore.deleteById(existingAnchor.getRelationGuid(), true); // Derive the qualifiedName when anchor changes String anchorGlossaryGuid = updatedTermAnchor.getGlossaryGuid(); AtlasGlossary glossary = dataAccess.load(getGlossarySkeleton(anchorGlossaryGuid)); storeObject.setQualifiedName(storeObject.getName() + "@" + glossary.getQualifiedName()); if (LOG.isDebugEnabled()) { LOG.debug("Derived qualifiedName = {}", storeObject.getQualifiedName()); } createRelationship(defineTermAnchorRelation(updatedTermAnchor.getGlossaryGuid(), storeObject.getGuid())); } break; case DELETE: if (Objects.nonNull(existingAnchor)) { if (DEBUG_ENABLED) { LOG.debug("Deleting term anchor"); } relationshipStore.deleteById(existingAnchor.getRelationGuid(), true); } break; } }
Example 19
Source File: AccessTokenData.java From yfiton with Apache License 2.0 | 4 votes |
public AccessTokenData(String accessToken, Map<String, String> data) { super(data); Objects.nonNull(accessToken); this.accessToken = accessToken; }
Example 20
Source File: PdxInstanceWrapper.java From spring-boot-data-geode with Apache License 2.0 | 3 votes |
private String toString(PdxInstance pdx, String indent) { if (Objects.nonNull(pdx)) { StringBuilder buffer = new StringBuilder(OBJECT_BEGIN).append(NEW_LINE); String fieldIndent = indent + INDENT_STRING; buffer.append(fieldIndent).append(formatFieldValue(CLASS_NAME_PROPERTY, pdx.getClassName())); for (String fieldName : nullSafeList(pdx.getFieldNames())) { Object fieldValue = pdx.getField(fieldName); String valueString = toStringObject(fieldValue, fieldIndent); buffer.append(COMMA_NEW_LINE); buffer.append(fieldIndent).append(formatFieldValue(fieldName, valueString)); } buffer.append(NEW_LINE).append(indent).append(OBJECT_END); return buffer.toString(); } else { return null; } }