本文整理了Java中org.apache.commons.collections4.CollectionUtils.emptyIfNull()
方法的一些代码示例,展示了CollectionUtils.emptyIfNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CollectionUtils.emptyIfNull()
方法的具体详情如下:
包路径:org.apache.commons.collections4.CollectionUtils
类名称:CollectionUtils
方法名:emptyIfNull
[英]Returns an immutable empty collection if the argument is null
, or the argument itself otherwise.
[中]如果参数为null
,则返回不可变的空集合,否则返回参数本身。
代码示例来源:origin: org.apache.commons/commons-collections4
/**
* Removes all values associated with the specified key.
* <p>
* A subsequent <code>get(Object)</code> would return an empty collection.
*
* @param key the key to remove values from
* @return the <code>Collection</code> of values removed, will return an
* empty, unmodifiable collection for no mapping found
*/
@Override
public Collection<V> remove(final Object key) {
return CollectionUtils.emptyIfNull(getMap().remove(key));
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Integer calculateNumShippableFulfillmentGroups(Order order) {
Integer numShippableFulfillmentGroups = 0;
List<FulfillmentGroup> fulfillmentGroups = order.getFulfillmentGroups();
for (FulfillmentGroup fulfillmentGroup : CollectionUtils.emptyIfNull(fulfillmentGroups)) {
if (isShippable(fulfillmentGroup.getType())) {
numShippableFulfillmentGroups++;
}
}
return numShippableFulfillmentGroups;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public boolean cartHasCreditCardPayment() {
Order cart = CartState.getCart();
List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
boolean isCreditCartPayment = PaymentType.CREDIT_CARD.equals(payment.getType());
if (payment.isActive() && isCreditCartPayment) {
return true;
}
}
return false;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public boolean cartHasThirdPartyPayment() {
Order cart = CartState.getCart();
List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
if (payment.isActive() && PaymentType.THIRD_PARTY_ACCOUNT.equals(payment.getType())) {
return true;
}
}
return false;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected Address getAddressFromCCOrderPayment(Order cart) {
List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
boolean isCreditCardPaymentType = PaymentType.CREDIT_CARD.equals(payment.getType());
boolean paymentHasBillingAddress = (payment.getBillingAddress() != null);
if (payment.isActive() && isCreditCardPaymentType && paymentHasBillingAddress) {
return payment.getBillingAddress();
}
}
return null;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public boolean cartHasPopulatedShippingAddress() {
Order cart = CartState.getCart();
for (FulfillmentGroup fulfillmentGroup : CollectionUtils.emptyIfNull(cart.getFulfillmentGroups())) {
if (fulfillmentGroupService.isShippable(fulfillmentGroup.getType())) {
if (fulfillmentGroup.getAddress() != null && fulfillmentGroup.getFulfillmentOption() != null) {
return true;
}
}
}
return false;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public boolean cartHasPopulatedBillingAddress() {
Order cart = CartState.getCart();
List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
boolean isCreditCardPayment = PaymentType.CREDIT_CARD.equals(payment.getType());
boolean paymentHasBillingAddress = (payment.getBillingAddress() != null);
if (payment.isActive() && isCreditCardPayment && paymentHasBillingAddress) {
return true;
}
}
return false;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public boolean cartHasTemporaryCreditCard() {
Order cart = CartState.getCart();
List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
boolean isCreditCartPayment = PaymentType.CREDIT_CARD.equals(payment.getType());
boolean isTemporaryPaymentGateway = PaymentGatewayType.TEMPORARY.equals(payment.getGatewayType());
if (payment.isActive() && isCreditCartPayment && isTemporaryPaymentGateway) {
return true;
}
}
return false;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected OrderPayment getUnconfirmedCCFromCart() {
OrderPayment unconfirmedCC = null;
Order cart = CartState.getCart();
List<OrderPayment> orderPayments = orderPaymentService.readPaymentsForOrder(cart);
for (OrderPayment payment : CollectionUtils.emptyIfNull(orderPayments)) {
boolean isCreditCartPayment = PaymentType.CREDIT_CARD.equals(payment.getType());
boolean isTemporaryPaymentGateway = PaymentGatewayType.TEMPORARY.equals(payment.getGatewayType());
if (payment.isActive() && isCreditCartPayment && !isTemporaryPaymentGateway) {
unconfirmedCC = payment;
}
}
return unconfirmedCC;
}
代码示例来源:origin: Evolveum/midpoint
public void setOrdering(Collection<? extends ObjectOrdering> orderings) {
this.ordering.clear();
for (ObjectOrdering ordering : CollectionUtils.emptyIfNull(orderings)) {
this.ordering.add((ObjectOrderingImpl) ordering);
}
}
代码示例来源:origin: Evolveum/midpoint
public void setGrouping(Collection<ObjectGrouping> groupings) {
this.grouping.clear();
for (ObjectGrouping grouping : CollectionUtils.emptyIfNull(groupings)) {
this.grouping.add((ObjectGroupingImpl) grouping);
}
}
代码示例来源:origin: DSpace/DSpace
public DiscoverySearchFilter getSearchFilter(String name) {
for (DiscoverySearchFilter filter : CollectionUtils.emptyIfNull(searchFilters)) {
if (StringUtils.equals(name, filter.getIndexFieldName())) {
return filter;
}
}
return null;
}
代码示例来源:origin: org.ligoj.bootstrap/bootstrap-web
@Override
protected Set<String> findConnectionHeaders(final HttpServletRequest clientRequest) {
final Set<String> ignoreRequestHeader = new HashSet<>();
ignoreRequestHeader.addAll(CollectionUtils.emptyIfNull(super.findConnectionHeaders(clientRequest)));
// Drop cookie headers forward from FRONT to BACK by default, only filtered ones will be added
ignoreRequestHeader.add(HEADER_COOKIE);
return ignoreRequestHeader;
}
}
代码示例来源:origin: org.ligoj.plugin/plugin-id
/**
* Convert the given user UIDs to a the corresponding DN. The users must exists.
*
* @param uids
* The UIDs to convert.
* @return The corresponding DN.
*/
private List<String> toDn(final List<String> uids) {
return CollectionUtils.emptyIfNull(uids).stream().map(getUser()::findByIdExpected).map(UserOrg::getDn)
.collect(Collectors.toList());
}
}
代码示例来源:origin: Evolveum/midpoint
void trimItemsDefinitionsTrees(Collection<? extends ItemPath> alwaysKeep) {
// to play safe, we won't touch PCV-specific complexTypeDefinition
for (Item<?, ?> item : CollectionUtils.emptyIfNull(items)) {
if (item instanceof PrismContainer) {
Collection<ItemPath> alwaysKeepInSub = ItemPathCollectionsUtil.remainder(CollectionUtils.emptyIfNull(alwaysKeep),
item.getElementName(), false);
((PrismContainer<?>) item).trimDefinitionTree(alwaysKeepInSub);
}
}
}
代码示例来源:origin: Evolveum/midpoint
@NotNull
private List<? extends ItemPath> getPathsToResolve(Collection<SelectorOptions<GetOperationOptions>> options) {
final UniformItemPath EMPTY_PATH = prismContext.emptyPath();
List<UniformItemPath> rv = new ArrayList<>();
for (SelectorOptions<GetOperationOptions> option : CollectionUtils.emptyIfNull(options)) {
if (GetOperationOptions.isResolveNames(option.getOptions())) {
rv.add(option.getItemPath(EMPTY_PATH));
}
}
return rv;
}
}
代码示例来源:origin: Evolveum/midpoint
public static void displayObjectTypeCollection(String message, Collection<? extends ObjectType> collection) {
System.out.println(OBJECT_TITLE_OUT_PREFIX + message);
LOGGER.debug(OBJECT_TITLE_LOG_PREFIX + message);
for (ObjectType o : CollectionUtils.emptyIfNull(collection)) {
System.out.println(ObjectTypeUtil.dump(o));
LOGGER.debug(ObjectTypeUtil.dump(o));
System.out.println(OBJECT_LIST_SEPARATOR);
LOGGER.debug(OBJECT_LIST_SEPARATOR);
}
}
代码示例来源:origin: Evolveum/midpoint
private <T> void assertUnsortedListsEquals(String message, Collection<String> expected, Collection<T> real, Function<T, String> nameExtractor) {
Bag<String> expectedAsBag = new TreeBag<>(CollectionUtils.emptyIfNull(expected));
Bag<String> realAsBag = new TreeBag<>(real.stream().map(nameExtractor).collect(Collectors.toList()));
assertEquals(message, expectedAsBag, realAsBag);
}
代码示例来源:origin: Evolveum/midpoint
private void assertTargetPolicyRules(EvaluatedAssignmentImpl<? extends FocusType> evaluatedAssignment,
Collection<String> expectedThisTargetItems, Collection<String> expectedOtherTargetsItems) {
expectedOtherTargetsItems = CollectionUtils.emptyIfNull(expectedOtherTargetsItems);
expectedThisTargetItems = CollectionUtils.emptyIfNull(expectedThisTargetItems);
assertUnsortedListsEquals("Wrong other targets policy rules", expectedOtherTargetsItems,
evaluatedAssignment.getOtherTargetsPolicyRules(), r -> r.getName());
assertUnsortedListsEquals("Wrong this target policy rules", expectedThisTargetItems,
evaluatedAssignment.getThisTargetPolicyRules(), r -> r.getName());
}
代码示例来源:origin: Evolveum/midpoint
private <AH extends AssignmentHolderType> boolean pathMatches(ObjectDelta<?> delta, PrismObject<AH> objectOld, ItemPath path,
boolean exactPathMatch) throws SchemaException {
if (delta.isAdd()) {
return delta.getObjectToAdd().containsItem(path, false);
} else if (delta.isDelete()) {
return objectOld != null && objectOld.containsItem(path, false);
} else {
return ItemDeltaCollectionsUtil.pathMatches(emptyIfNull(delta.getModifications()), path, 0, exactPathMatch);
}
}
内容来源于网络,如有侵权,请联系作者删除!