Skip to content

Commit

Permalink
Add tag list.filter
Browse files Browse the repository at this point in the history
Incredible list-handling power!
  • Loading branch information
mcmonkey4eva committed Oct 23, 2014
1 parent 5d98f5b commit be6a41b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -968,6 +968,30 @@ else if (res > 0)
return new dList(list).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.filter[<tag>]>
// @returns dList
// @description
// returns a copy of the list with all its contents parsed through the given tag and only including ones that returned 'true'.
// For example, a list of '1|2|3|4|5' .filter[is[or_more].than[3]] returns a list of '3|4|5'.
// -->
if (attribute.startsWith("filter")
&& attribute.hasContext(1)) {
dList newlist = new dList();
try {
for (String str: this) {
if (ObjectFetcher.pickObjectFor(str).getAttribute(new Attribute(attribute.getContext(1),
attribute.getScriptEntry())).equalsIgnoreCase("true")) {
newlist.add(str);
}
}
}
catch (Exception ex) {
dB.echoError(ex);
}
return newlist.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.parse[<tag>]>
// @returns dList
Expand Down

0 comments on commit be6a41b

Please sign in to comment.