本文整理汇总了Java中org.apache.commons.lang3.ObjectUtils类的典型用法代码示例。如果您正苦于以下问题:Java ObjectUtils类的具体用法?Java ObjectUtils怎么用?Java ObjectUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectUtils类属于org.apache.commons.lang3包,在下文中一共展示了ObjectUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAll
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
@Override
public Page<T> findAll(final Set<T> groups, final String criteria, final Pageable pageable, final Map<String, Comparator<T>> customComparators) {
// Create the set with the right comparator
final List<Sort.Order> orders = IteratorUtils.toList(ObjectUtils.defaultIfNull(pageable.getSort(), new ArrayList<Sort.Order>()).iterator());
orders.add(DEFAULT_ORDER);
final Sort.Order order = orders.get(0);
Comparator<T> comparator = customComparators.get(order.getProperty());
if (order.getDirection() == Direction.DESC) {
comparator = Collections.reverseOrder(comparator);
}
final Set<T> result = new TreeSet<>(comparator);
// Filter the groups, filtering by the criteria
addFilteredByPattern(groups, criteria, result);
// Apply in-memory pagination
return inMemoryPagination.newPage(result, pageable);
}
示例2: writeIssueData
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* Complete the standard data with temporal data (not SLA), sub task, and components
*/
@Override
protected void writeIssueData(final IssueDetails issue, final Writer writer, final Format df, final Format idf) throws IOException {
// Write static data
super.writeIssueData(issue, writer, df, idf);
// Time spent
writer.write(';');
writer.write(String.valueOf(ObjectUtils.defaultIfNull((Object) issue.getTimeSpent(), "")));
// Time estimate
writer.write(';');
writer.write(String.valueOf(ObjectUtils.defaultIfNull((Object) issue.getTimeEstimate(), "")));
// Time initial estimate
writer.write(';');
writer.write(String.valueOf(ObjectUtils.defaultIfNull((Object) issue.getTimeEstimateInit(), "")));
// Optional parent
writer.write(';');
writer.write(String.valueOf(ObjectUtils.defaultIfNull(subTasks.get(issue.getId()), "")));
// Custom non fixed fields
writeCustomData((IssueSla) issue, writer, df);
}
示例3: write
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final RegisteredService service) {
kryo.writeObject(output, service.getServiceId());
kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getName(), ""));
kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getDescription(), ""));
kryo.writeObject(output, service.getId());
kryo.writeObject(output, service.getEvaluationOrder());
kryo.writeObject(output, ObjectUtils.defaultIfNull(service.getLogo(), getEmptyUrl()));
kryo.writeObject(output, service.getLogoutType());
kryo.writeObject(output, ObjectUtils.defaultIfNull(service.getLogoutUrl(), getEmptyUrl()));
kryo.writeObject(output, ImmutableSet.copyOf(service.getRequiredHandlers()));
kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getTheme(), ""));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getPublicKey(),
new RegisteredServicePublicKeyImpl()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getProxyPolicy(),
new RefuseRegisteredServiceProxyPolicy()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getAttributeReleasePolicy(),
new ReturnAllowedAttributeReleasePolicy()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getUsernameAttributeProvider(),
new DefaultRegisteredServiceUsernameProvider()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getAccessStrategy(),
new DefaultRegisteredServiceAccessStrategy()));
}
示例4: save
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
private void save(final SlaEditionVo vo, final Sla entity) {
DescribedBean.copy(vo, entity);
entity.setStop(StringUtils.join(identifierHelper.normalize(vo.getStop()), ','));
entity.setStart(StringUtils.join(identifierHelper.normalize(vo.getStart()), ','));
entity.setThreshold(vo.getThreshold());
vo.setPause(ObjectUtils.defaultIfNull(vo.getPause(), new ArrayList<>()));
vo.setPriorities(ObjectUtils.defaultIfNull(vo.getPriorities(), new ArrayList<>()));
vo.setResolutions(ObjectUtils.defaultIfNull(vo.getResolutions(), new ArrayList<>()));
vo.setTypes(ObjectUtils.defaultIfNull(vo.getTypes(), new ArrayList<>()));
checkSlaBounds(vo);
entity.setPause(StringUtils.join(identifierHelper.normalize(vo.getPause()), ','));
entity.setPriorities(StringUtils.join(vo.getPriorities(), ','));
entity.setResolutions(StringUtils.join(vo.getResolutions(), ','));
entity.setTypes(StringUtils.join(vo.getTypes(), ','));
slaRepository.saveAndFlush(entity);
}
示例5: write
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
@Override
public void write(final Kryo kryo, final Output output, final RegisteredService service) {
kryo.writeObject(output, service.getServiceId());
kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getName(), StringUtils.EMPTY));
kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getDescription(), StringUtils.EMPTY));
kryo.writeObject(output, service.getId());
kryo.writeObject(output, service.getEvaluationOrder());
kryo.writeObject(output, ObjectUtils.defaultIfNull(service.getLogo(), getEmptyUrl()));
kryo.writeObject(output, service.getLogoutType());
kryo.writeObject(output, ObjectUtils.defaultIfNull(service.getLogoutUrl(), getEmptyUrl()));
kryo.writeObject(output, new HashSet<>(service.getRequiredHandlers()));
kryo.writeObject(output, StringUtils.defaultIfEmpty(service.getTheme(), StringUtils.EMPTY));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getPublicKey(),
new RegisteredServicePublicKeyImpl()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getProxyPolicy(),
new RefuseRegisteredServiceProxyPolicy()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getAttributeReleasePolicy(),
new ReturnAllowedAttributeReleasePolicy()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getUsernameAttributeProvider(),
new DefaultRegisteredServiceUsernameProvider()));
writeObjectByReflection(kryo, output, ObjectUtils.defaultIfNull(service.getAccessStrategy(),
new DefaultRegisteredServiceAccessStrategy()));
}
示例6: handleConfigurationModifiedEvent
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* Handle configuration modified event.
*
* @param event the event
*/
@EventListener
public void handleConfigurationModifiedEvent(final CasConfigurationModifiedEvent event) {
if (this.contextRefresher == null) {
LOGGER.warn("Unable to refresh application context, since no refresher is available");
return;
}
if (event.isEligibleForContextRefresh()) {
LOGGER.info("Received event [{}]. Refreshing CAS configuration...", event);
Collection<String> keys = null;
try {
keys = this.contextRefresher.refresh();
LOGGER.debug("Refreshed the following settings: [{}].", keys);
} catch (final Throwable e) {
LOGGER.trace(e.getMessage(), e);
} finally {
rebind();
LOGGER.info("CAS finished rebinding configuration with new settings [{}]",
ObjectUtils.defaultIfNull(keys, Collections.emptyList()));
}
}
}
示例7: writeData
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* Write issue data
*/
private void writeData(final JiraChangeItem change, final String key, final Writer writer, final Format df, final Format idf) throws IOException {
// Write static data
writer.write(change.getId().toString());
writer.write(';');
writer.write(key);
writer.write(';');
writer.write(ObjectUtils.defaultIfNull(change.getAuthor(), change.getReporter()));
writer.write(';');
writer.write(ObjectUtils.defaultIfNull(change.getFromStatus(), "").toString());
writer.write(';');
writer.write(String.valueOf(change.getToStatus()));
writer.write(';');
writer.write(idf.format(ObjectUtils.defaultIfNull(statusText.get(change.getFromStatus()), "")));
writer.write(';');
writer.write(idf.format(statusText.get(change.getToStatus())));
writer.write(';');
writer.write(df.format(change.getCreated()));
writer.write(';');
writer.write(String.valueOf(change.getCreated().getTime()));
}
示例8: createNode
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* 创建节点
*
* @param path
* @param data
* @param mode
* @return
*/
public boolean createNode(String path, String data, CreateMode mode) {
if (!ObjectUtils.allNotNull(zkClient, path)) {
return Boolean.FALSE;
}
try {
Stat stat = exists(path);
if (stat == null) {
mode = mode == null ? CreateMode.PERSISTENT : mode;
String opResult;
if (ObjectUtils.allNotNull(data)) {
opResult = zkClient.create().creatingParentContainersIfNeeded().withMode(mode).forPath(path, data.getBytes(Charsets.UTF_8));
} else {
opResult = zkClient.create().creatingParentContainersIfNeeded().withMode(mode).forPath(path);
}
return Objects.equal(opResult, path);
}
return Boolean.TRUE;
} catch (Exception e) {
log.error("create node fail! path: {}, error: {}", path, e);
}
return Boolean.FALSE;
}
示例9: deleteNode
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* 删除节点 递归删除子节点
*
* @param path
* @param version
* @return
*/
public boolean deleteNode(String path, Integer version) {
if (!ObjectUtils.allNotNull(zkClient, path)) {
return Boolean.FALSE;
}
try {
Stat stat = exists(path);
if (stat != null) {
if (version == null) {
zkClient.delete().deletingChildrenIfNeeded().forPath(path);
} else {
zkClient.delete().deletingChildrenIfNeeded().withVersion(version).forPath(path);
}
}
return Boolean.TRUE;
} catch (Exception e) {
log.error("delete node fail! path: {}, error: {}", path, e);
}
return Boolean.FALSE;
}
示例10: setNodeData
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* 设置节点数据
*
* @param path
* @param data
* @param version
* @return
*/
public boolean setNodeData(String path, byte[] data, Integer version) {
if (!ObjectUtils.allNotNull(zkClient, path)) {
return Boolean.FALSE;
}
try {
Stat stat = exists(path);
if (stat != null) {
if (version == null) {
zkClient.setData().forPath(path, data);
} else {
zkClient.setData().withVersion(version).forPath(path, data);
}
return Boolean.TRUE;
}
} catch (Exception e) {
log.error("set node data fail! path: {}, error: {}", path, e);
}
return Boolean.FALSE;
}
示例11: listenerPathChildrenCache
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* 设置子节点更改监听
*
* @param path
* @throws Exception
*/
public boolean listenerPathChildrenCache(String path, BiConsumer<CuratorFramework, PathChildrenCacheEvent> biConsumer) {
if (!ObjectUtils.allNotNull(zkClient, path, biConsumer)) {
return Boolean.FALSE;
}
try {
Stat stat = exists(path);
if (stat != null) {
PathChildrenCache watcher = new PathChildrenCache(zkClient, path, true);
watcher.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
//该模式下 watcher在重连的时候会自动 rebuild 否则需要重新rebuild
watcher.getListenable().addListener(biConsumer::accept, pool);
if (!pathChildrenCaches.contains(watcher)) {
pathChildrenCaches.add(watcher);
}
// else{
// watcher.rebuild();
// }
return Boolean.TRUE;
}
} catch (Exception e) {
log.error("listen path children cache fail! path:{} , error:{}", path, e);
}
return Boolean.FALSE;
}
示例12: readTargetChildsData
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* 读取指定节点的子菜单的值
*
* @param path
* @return
*/
public Map<String, String> readTargetChildsData(String path) {
if (!ObjectUtils.allNotNull(zkClient, path)) {
return null;
}
Map<String, String> map = null;
try {
Stat stat = exists(path);
if (stat != null) {
List<String> childrens = zkClient.getChildren().forPath(path);
GetDataBuilder dataBuilder = zkClient.getData();
if (childrens != null) {
map = childrens.stream().collect(Collectors.toMap(Function.identity(), (child) -> {
try {
return new String(dataBuilder.forPath(ZKPaths.makePath(path, child)), Charsets.UTF_8);
} catch (Exception e1) {
return null;
}
}));
}
}
} catch (Exception e) {
log.error("get target childs data fail!, path:{} , error:{}", path, e);
}
return map;
}
示例13: createNotifyUrl
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* 创建响应URL
* @param transOrder
* @param backType 1:前台页面;2:后台接口
* @return
*/
public String createNotifyUrl(TransOrder transOrder, String backType) {
String mchId = transOrder.getMchId();
MchInfo mchInfo = super.baseSelectMchInfo(mchId);
String resKey = mchInfo.getResKey();
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("transOrderId", ObjectUtils.defaultIfNull(transOrder.getTransOrderId(), "")); // 转账订单号
paramMap.put("mchId", ObjectUtils.defaultIfNull(transOrder.getMchId(), "")); // 商户ID
paramMap.put("mchOrderNo", ObjectUtils.defaultIfNull(transOrder.getMchTransNo(), "")); // 商户订单号
paramMap.put("channelId", ObjectUtils.defaultIfNull(transOrder.getChannelId(), "")); // 渠道ID
paramMap.put("amount", ObjectUtils.defaultIfNull(transOrder.getAmount(), "")); // 支付金额
paramMap.put("currency", ObjectUtils.defaultIfNull(transOrder.getCurrency(), "")); // 货币类型
paramMap.put("status", ObjectUtils.defaultIfNull(transOrder.getStatus(), "")); // 转账状态
paramMap.put("result", ObjectUtils.defaultIfNull(transOrder.getResult(), "")); // 转账结果
paramMap.put("clientIp", ObjectUtils.defaultIfNull(transOrder.getClientIp(), "")); // 客户端IP
paramMap.put("device", ObjectUtils.defaultIfNull(transOrder.getDevice(), "")); // 设备
paramMap.put("channelOrderNo", ObjectUtils.defaultIfNull(transOrder.getChannelOrderNo(), "")); // 渠道订单号
paramMap.put("param1", ObjectUtils.defaultIfNull(transOrder.getParam1(), "")); // 扩展参数1
paramMap.put("param2", ObjectUtils.defaultIfNull(transOrder.getParam2(), "")); // 扩展参数2
paramMap.put("transSuccTime", ObjectUtils.defaultIfNull(transOrder.getTransSuccTime(), "")); // 转账成功时间
paramMap.put("backType", backType==null ? "" : backType);
// 先对原文签名
String reqSign = PayDigestUtil.getSign(paramMap, resKey);
paramMap.put("sign", reqSign); // 签名
// 签名后再对有中文参数编码
try {
paramMap.put("device", URLEncoder.encode(ObjectUtils.defaultIfNull(transOrder.getDevice(), ""), PayConstant.RESP_UTF8));
paramMap.put("param1", URLEncoder.encode(ObjectUtils.defaultIfNull(transOrder.getParam1(), ""), PayConstant.RESP_UTF8));
paramMap.put("param2", URLEncoder.encode(ObjectUtils.defaultIfNull(transOrder.getParam2(), ""), PayConstant.RESP_UTF8));
}catch (UnsupportedEncodingException e) {
_log.error("URL Encode exception.", e);
return null;
}
String param = XXPayUtil.genUrlParams(paramMap);
StringBuffer sb = new StringBuffer();
sb.append(transOrder.getNotifyUrl()).append("?").append(param);
return sb.toString();
}
示例14: upload
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
/**
* Upload a file of quote in add mode.
*
* @param subscription
* The subscription identifier, will be used to filter the locations
* from the associated provider.
* @param uploadedFile
* Instance entries files to import. Currently support only CSV
* format.
* @param columns
* the CSV header names.
* @param term
* The default {@link ProvInstancePriceTerm} used when no one is
* defined in the CSV line
* @param ramMultiplier
* The multiplier for imported RAM values. Default is 1.
* @param encoding
* CSV encoding. Default is UTF-8.
* @throws IOException
* When the CSV stream cannot be written.
*/
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("{subscription:\\d+}/upload")
public void upload(@PathParam("subscription") final int subscription, @Multipart(value = "csv-file") final InputStream uploadedFile,
@Multipart(value = "columns", required = false) final String[] columns,
@Multipart(value = "term", required = false) final String term,
@Multipart(value = "memoryUnit", required = false) final Integer ramMultiplier,
@Multipart(value = "encoding", required = false) final String encoding) throws IOException {
subscriptionResource.checkVisibleSubscription(subscription).getNode().getId();
// Check column's name validity
final String[] sanitizeColumns = ArrayUtils.isEmpty(columns) ? DEFAULT_COLUMNS : columns;
checkHeaders(ACCEPTED_COLUMNS, sanitizeColumns);
// Build CSV header from array
final String csvHeaders = StringUtils.chop(ArrayUtils.toString(sanitizeColumns)).substring(1).replace(',', ';') + "\n";
// Build entries
final String safeEncoding = ObjectUtils.defaultIfNull(encoding, StandardCharsets.UTF_8.name());
csvForBean
.toBean(InstanceUpload.class, new InputStreamReader(
new SequenceInputStream(new ByteArrayInputStream(csvHeaders.getBytes(safeEncoding)), uploadedFile), safeEncoding))
.stream().filter(Objects::nonNull).forEach(i -> persist(i, subscription, term, ramMultiplier));
}
示例15: handleError
import org.apache.commons.lang3.ObjectUtils; //导入依赖的package包/类
protected void handleError(Throwable e) {
if (engine != null) {
if (engine.getInteractiveMode() != null) {
engine.getInteractiveMode().getExceptionHandler().handleException(e,
new GenericExceptionContext(engine, ObjectUtils.defaultIfNull(SpongeUtils.getSourceName(e), "interactive")));
} else {
engine.handleError("standalone", e);
}
} else {
if (e instanceof StandaloneInitializationException && !testMode) {
System.out.println(e.getMessage());
System.out.println("");
builder.printHelp();
} else {
logger.error("Error", e);
}
}
if (testMode) {
throw SpongeUtils.wrapException(e);
}
}