Skip to content

Commit

Permalink
Add list.find[<element>]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 25, 2013
1 parent f593066 commit 387ab9b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dList.java
Expand Up @@ -310,6 +310,23 @@ public String getAttribute(Attribute attribute) {
return new Element(item).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <li@list.find[<element>]>
// @returns Element(Number)
// @description
// returns the numbered location of an element within a list,
// or -1 if the list does not contain that item.
// -->
if (attribute.startsWith("find")) {
if (attribute.hasContext(1)) {
for (int i = 0;i < size();i++) {
if (get(i).equalsIgnoreCase(attribute.getContext(1)))
return new Element(i + 1).getAttribute(attribute.fulfill(1));
}
return new Element(-1).getAttribute(attribute.fulfill(1));
}
}

if (attribute.startsWith("last")) {
return new Element(get(size() - 1)).getAttribute(attribute.fulfill(1));
}
Expand Down

0 comments on commit 387ab9b

Please sign in to comment.