Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.stream.Collectors
- import java.util.stream.Stream
- import groovy.transform.Field
- @Field
- Map<String, String> sampleMap = [
- 'SampleKey1': 'SampleValue1',
- 'SampleKey2': 'SampleValue2'
- ]
- //example param value: "C/SampleKey1/someFile, C/SampleKey2/someFile2"
- private Collection<String> getValues(String param) {
- Stream.of(param.split(','))
- .map { getValueFromOnePath(it) }
- .filter { !it.isEmpty() }
- .distinct()
- .collect(Collectors.toList())
- }
- private String getValueFromOnePath(String path) {
- String[] pathParts = path.split('/')
- if (pathParts.size() < 2) {
- return ''
- }
- return sampleMap[pathParts[1]] ?: ''
- }
- "C/SampleKey1/someFile, C/SampleKey2/someFile2"
- [SampleValue1, SampleValue2]
Add Comment
Please, Sign In to add comment