We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to limit arrays ? Something like this would be useful: <myobj.items:{it|<it.something>}; limit=10 >
<myobj.items:{it|<it.something>}; limit=10 >
The text was updated successfully, but these errors were encountered:
Ok I have found a workaround for this:
group.defineDictionary("max", new MaxListItemsLimiter());
Usage (first item is always max. items count, second is List): <max.(["50",myObject.items]):{msg|<msg.something>}>
<max.(["50",myObject.items]):{msg|<msg.something>}>
final class MaxListItemsLimiter extends AbstractMap<String, Object> { @Override public Object get(Object key) { List items = (List) key; if (!items.isEmpty()) { //First item is max. count Integer limit = NumberUtils.toInt(items.get(0).toString(), -1); //use Integer.parseInt if (limit != -1) { return items.subList(1, Math.min(items.size(), limit + 1)); } else { throw new AssertionError("First parameter in max must be number"); } } else { return super.get(key); } } @Override public Set<Map.Entry<String, Object>> entrySet() { return Collections.emptySet(); } @Override public boolean containsKey(Object key) { if (key instanceof List) { return true; } else { throw new AssertionError("You can use max only on Lists."); } } }
Sorry, something went wrong.
Not a bad idea to have. thanks for the suggestion.
What is the use case? Pagination comes to mind, but that also requires a way to skip n items.
n
No branches or pull requests
Is there any way to limit arrays ? Something like this would be useful:
<myobj.items:{it|<it.something>}; limit=10 >
The text was updated successfully, but these errors were encountered: