Implementing path.contains(obj)

This commit is contained in:
hns 2004-02-27 13:24:03 +00:00
parent e6da507d85
commit 5c8d774f47
2 changed files with 24 additions and 1 deletions

View file

@ -132,4 +132,14 @@ public class RequestPath {
return buffer.toString(); return buffer.toString();
} }
/**
* Checks if the given object is contained in the request path
*
* @param obj the element to check
* @return the index of the element, or -1 if it isn't contained
*/
public int contains(Object obj) {
return objects.indexOf(obj);
}
} }

View file

@ -43,7 +43,8 @@ public class PathWrapper extends ScriptableObject {
setParentScope(core.getScope()); setParentScope(core.getScope());
setPrototype(null); setPrototype(null);
defineProperty("length", PathWrapper.class, attributes); defineProperty("length", PathWrapper.class, attributes);
defineFunctionProperties(new String[] {"href"}, PathWrapper.class, attributes); defineFunctionProperties(new String[] {"href", "contains"},
PathWrapper.class, attributes);
} }
/** /**
@ -126,6 +127,18 @@ public class PathWrapper extends ScriptableObject {
return path.href(null); return path.href(null);
} }
/**
* Checks if the given object is contained in the request path
*
* @param obj the element to check
* @return the index of the element, or -1 if it isn't contained
*/
public int contains(Object obj) {
if (obj instanceof Wrapper)
obj = ((Wrapper) obj).unwrap();
return path.contains(obj);
}
public String getClassName() { public String getClassName() {
return "[PathWrapper]"; return "[PathWrapper]";
} }