chachra wrote On 01/09/07 16:45,:
> Is there a containsKey (contains) implementation for Map (Set) to work
> with regex when key (contents) are String's ?
If I understand you correctly, you are looking for
a method to report whether a Set (which might be the
keySet() of a Map) contains a String that is matched by
a given regular expression. I don't think such a thing
exists in the standard collection classes.
You could write one easily enough:
static boolean containsPattern(Set<String> set, Pattern pat)
{
for (String s : set) {
Matcher m = pat.matcher(s);
if (m.matches())
return true;
}
return false;
}
If the sets are large efficiency might be a concern,
and you might want to consider implementing a specialized
data structure. I'd suggest starting by asking whether you
really need a full-fledged regular expression, or merely a
few wild-cards and things.
--