use of org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumeration in project BroadleafCommerce by BroadleafCommerce.
the class DataDrivenEnumVariableExpression method getEnumValues.
/**
* Looks up a list of {@link DataDrivenEnumerationValue} by the {@link DataDrivenEnumeration#getKey()} specified by <b>key</b>
* @param key lookup for the {@link DataDrivenEnumeration}
* @param sort optional, either 'ASCENDING' or 'DESCENDING' depending on how you want the result list sorted
* @return the list of {@link DataDrivenEnumerationValue} for the given <b>key</b>
*/
public List<DataDrivenEnumerationValue> getEnumValues(String key, final String sort) {
if (StringUtils.isEmpty(key)) {
throw new IllegalArgumentException("No 'key' parameter was passed to find enumeration values");
}
DataDrivenEnumeration ddEnum = enumService.findEnumByKey(key);
if (ddEnum == null) {
throw new IllegalArgumentException("Could not find a data driven enumeration keyed by " + key);
}
List<DataDrivenEnumerationValue> enumValues = new ArrayList<>(ddEnum.getEnumValues());
if (StringUtils.isNotEmpty(sort)) {
Collections.sort(enumValues, new Comparator<DataDrivenEnumerationValue>() {
@Override
public int compare(DataDrivenEnumerationValue arg0, DataDrivenEnumerationValue arg1) {
if (sort.equals("ASCENDING")) {
return arg0.getDisplay().compareTo(arg1.getDisplay());
} else {
return arg1.getDisplay().compareTo(arg0.getDisplay());
}
}
});
}
return enumValues;
}
Aggregations