Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > containsKey (contains) implementation for Map (Set) to work with regex when key (contents) are String's

Reply
Thread Tools

containsKey (contains) implementation for Map (Set) to work with regex when key (contents) are String's

 
 
chachra
Guest
Posts: n/a
 
      01-09-2007
Is there a containsKey (contains) implementation for Map (Set) to work
with regex when key (contents) are String's ?

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      01-09-2007
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.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP and hashmap's containsKey lord.zoltar@gmail.com Java 5 05-06-2009 01:54 AM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
ContainsKey with Custom Dictionary Keys =?Utf-8?B?RnJhbms=?= ASP .Net 0 07-05-2006 10:21 PM
map.insert(key,val) vs. map[key]=val ? Patrick Guio C++ 6 10-20-2004 01:54 PM
problem with containsKey for Set Jacek Java 1 03-07-2004 10:57 PM



Advertisments