Avec une routine est le plus simple.
Dans une routine
1 2 3 4 5 6 7 8 9
|
public java.util.List<Integer> parseListInteger(String input, String separator) {
final String[] stringValues = input.split(separator);
java.util.List<Integer> list = new java.util.ArrayList<>();
for(String s : stringValues) {
list.add(Integer.valueOf(s));
}
return list;
} |
TaRoutine.parseListInteger(context.variable,",").contains(42)
Si tu veux un peut de performance et garder ta liste en cache
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| private java.util.Map<String, java.util.Map<String, java.util.List<Integer>>> cache;
public java.util.List<Integer> parseListInteger(final String input, final String separator, final boolean useCache) {
java.util.List<Integer> list = null;
java.util.Map<String, java.util.List<Integer>> cacheBySeparator = null;
if (useCache) {
if (cache == null) {
cache = new java.util.HashMap<>();
}
cacheBySeparator = cache.get(separator);
if (cacheBySeparator == null) {
cacheBySeparator = new java.util.HashMap<>();
cache.put(separator, cacheBySeparator);
}
list = cacheBySeparator.get(input);
}
if (list == null) {
final String[] stringValues = input.split(separator);
list = new java.util.ArrayList<>();
for (final String s : stringValues) {
list.add(Integer.valueOf(s));
}
if (cacheBySeparator != null) {
cacheBySeparator.put(input, list);
}
}
return list;
} |
avec
TaRoutine.parseListInteger(context.variable,",",true).contains(42)
Partager