Guest User

Untitled

a guest
Jan 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.util.stream.Collectors
  2. import java.util.stream.Stream
  3. import groovy.transform.Field
  4.  
  5. @Field
  6. Map<String, String> sampleMap = [
  7. 'SampleKey1': 'SampleValue1',
  8. 'SampleKey2': 'SampleValue2'
  9. ]
  10.  
  11. //example param value: "C/SampleKey1/someFile, C/SampleKey2/someFile2"
  12. private Collection<String> getValues(String param) {
  13. Stream.of(param.split(','))
  14. .map { getValueFromOnePath(it) }
  15. .filter { !it.isEmpty() }
  16. .distinct()
  17. .collect(Collectors.toList())
  18. }
  19.  
  20. private String getValueFromOnePath(String path) {
  21. String[] pathParts = path.split('/')
  22. if (pathParts.size() < 2) {
  23. return ''
  24. }
  25. return sampleMap[pathParts[1]] ?: ''
  26. }
  27.  
  28. "C/SampleKey1/someFile, C/SampleKey2/someFile2"
  29.  
  30. [SampleValue1, SampleValue2]
Add Comment
Please, Sign In to add comment