Permalink
Browse files

Reuse the same Pattern instance when matching multiple key/values

  • Loading branch information...
luccioman committed Feb 14, 2018
1 parent dbf4c1c commit e9527cd0e511abdf746e01bbe52d4826355a32b7
Showing with 4 additions and 3 deletions.
  1. +4 −3 source/net/yacy/server/serverObjects.java
@@ -495,8 +495,9 @@ public boolean getBoolean(final String key) {
// the keyMapper may contain regular expressions as defined in String.matches
// this method is particulary useful when parsing the result of checkbox forms
final List<String> v = new ArrayList<String>();
final Pattern keyPattern = Pattern.compile(keyMapper);
for (final Map.Entry<String, String> entry: entrySet()) {
if (entry.getKey().matches(keyMapper)) {
if (keyPattern.matcher(entry.getKey()).matches()) {
v.add(entry.getValue());
}
}
@@ -512,10 +513,10 @@ public boolean getBoolean(final String key) {
public Map<String, String> getMatchingEntries(final String keyMapper) throws PatternSyntaxException {
// the keyMapper may contain regular expressions as defined in String.matches
// this method is particulary useful when parsing the result of checkbox forms
final Pattern p = Pattern.compile(keyMapper);
final Pattern keyPattern = Pattern.compile(keyMapper);
final Map<String, String> map = new HashMap<>();
for (final Map.Entry<String, String> entry: entrySet()) {
if (entry.getKey().matches(keyMapper)) {
if (keyPattern.matcher(entry.getKey()).matches()) {
map.put(entry.getKey(), entry.getValue());
}
}

0 comments on commit e9527cd

Please sign in to comment.