下面列出了java.util.Objects#nonNull ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
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;
}
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.");
}
}
/**
* 获取配置属性
*/
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;
}
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;
}
@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;
}
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;
}
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);
}
}
}
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;
}
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");
}
@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;
}
}
@Override public void setSelectedIndex(int index) {
TreeNode node = getItemAt(index);
if (Objects.nonNull(node) && node.isLeaf()) {
super.setSelectedIndex(index);
} else {
isNotSelectableIndex = true;
}
}
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;
}
@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);
}
}
/**
* 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;
}
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));
}
}
}
/**
* 获取需要切换的数据源
*/
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);
}
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;
}
}
public AccessTokenData(String accessToken, Map<String, String> data) {
super(data);
Objects.nonNull(accessToken);
this.accessToken = accessToken;
}
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;
}
}