use of org.apache.commons.collections.Transformer in project opencast by opencast.
the class DublinCoreCatalog method get.
@Override
@SuppressWarnings("unchecked")
public List<String> get(EName property, final String language) {
RequireUtil.notNull(property, "property");
RequireUtil.notNull(language, "language");
if (LANGUAGE_ANY.equals(language)) {
return (List<String>) CollectionUtils.collect(getValuesAsList(property), new Transformer() {
@Override
public Object transform(Object o) {
return ((CatalogEntry) o).getValue();
}
});
} else {
final List<String> values = new ArrayList<String>();
final boolean langUndef = LANGUAGE_UNDEFINED.equals(language);
CollectionUtils.forAllDo(getValuesAsList(property), new Closure() {
@Override
public void execute(Object o) {
CatalogEntry c = (CatalogEntry) o;
String lang = c.getAttribute(XML_LANG_ATTR);
if ((langUndef && lang == null) || (language.equals(lang)))
values.add(c.getValue());
}
});
return values;
}
}
use of org.apache.commons.collections.Transformer in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method getConsolidatedOptionProperty.
/**
* Returns a {@link Property} filled out with a delimited list of the <b>values</b> that are passed in. This should be
* invoked on a fetch and the returned property should be added to the fetched {@link Entity} dto.
*
* @param values
* @return
* @see {@link #createConsolidatedOptionField(Class)};
*/
public Property getConsolidatedOptionProperty(Collection<ProductOptionValue> values) {
Property optionValueProperty = new Property();
optionValueProperty.setName(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);
// order the values by the display order of their correspond product option
// Collections.sort(values, new Comparator<ProductOptionValue>() {
//
// @Override
// public int compare(ProductOptionValue value1, ProductOptionValue value2) {
// return new CompareToBuilder().append(value1.getProductOption().getDisplayOrder(),
// value2.getProductOption().getDisplayOrder()).toComparison();
// }
// });
ArrayList<String> stringValues = new ArrayList<>();
CollectionUtils.collect(values, new Transformer() {
@Override
public Object transform(Object input) {
return ((ProductOptionValue) input).getAttributeValue();
}
}, stringValues);
optionValueProperty.setValue(StringUtils.join(stringValues, CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER));
return optionValueProperty;
}
use of org.apache.commons.collections.Transformer in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceImpl method getUniqueOffersFromOrder.
@Override
@SuppressWarnings("unchecked")
public Set<Offer> getUniqueOffersFromOrder(Order order) {
HashSet<Offer> result = new HashSet<Offer>();
Transformer adjustmentToOfferTransformer = new Transformer() {
@Override
public Object transform(Object input) {
return ((Adjustment) input).getOffer();
}
};
result.addAll(CollectionUtils.collect(order.getOrderAdjustments(), adjustmentToOfferTransformer));
if (order.getOrderItems() != null) {
for (OrderItem item : order.getOrderItems()) {
result.addAll(CollectionUtils.collect(item.getOrderItemAdjustments(), adjustmentToOfferTransformer));
// record usage for price details on the item as well
if (item.getOrderItemPriceDetails() != null) {
for (OrderItemPriceDetail detail : item.getOrderItemPriceDetails()) {
result.addAll(CollectionUtils.collect(detail.getOrderItemPriceDetailAdjustments(), adjustmentToOfferTransformer));
}
}
}
}
if (order.getFulfillmentGroups() != null) {
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
result.addAll(CollectionUtils.collect(fg.getFulfillmentGroupAdjustments(), adjustmentToOfferTransformer));
}
}
return result;
}
Aggregations