Skip to content

Commit

Permalink
tmf: Accept Integer key values as string in Regex Multimap parameters
Browse files Browse the repository at this point in the history
In extractRegexFilter check if provided key values are string
instead of integer.

For example in REGEX_MAP_FILTERS user could specify a key value pair
as {"1": ["string",...]} instead of {1: ["string",...]}.

[Changed] Accept Integer keys as string in Regex Multimap parameters

Signed-off-by: Hriday Panchasara <hriday.panchasara@ericsson.com>
Change-Id: I9d409860a4027344705fd2bbd58c0b73878a3fb6
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/197273
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
hriday-panchasara authored and MatthewKhouzam committed May 18, 2023
1 parent 5b3bbea commit 0ff790d
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.core.Activator;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -220,6 +220,7 @@ private DataProviderParameterUtils() {
* @return Multimap of regexes or null if there is no regex key in the map
* of parameters
*/
@SuppressWarnings("null")
public static @Nullable Multimap<Integer, String> extractRegexFilter(Map<String, Object> parameters) {
Object regexesObject = parameters.get(REGEX_MAP_FILTERS_KEY);
if (!(regexesObject instanceof Map<?, ?>)) {
Expand All @@ -228,10 +229,18 @@ private DataProviderParameterUtils() {

Multimap<Integer, String> regexes = HashMultimap.create();
@SuppressWarnings("unchecked")
Map<Integer, Collection<String>> regexesMap = (Map<Integer, Collection<String>>) regexesObject;
for (Entry<Integer, Collection<String>> entry : regexesMap.entrySet()) {
regexes.putAll(entry.getKey(), entry.getValue());
}
Map<Object, Collection<String>> regexesMap = (Map<Object, Collection<String>>) regexesObject;
regexesMap.forEach((key, value) -> {
if (key instanceof String) {
try {
regexes.putAll(Integer.valueOf((String) key), value);
} catch (NumberFormatException e) {
Activator.logError(e.getMessage(), e);
}
} else if (key instanceof Number) {
regexes.putAll(((Number) key).intValue(), value);
}
});

return regexes;
}
Expand Down

0 comments on commit 0ff790d

Please sign in to comment.