1 package com.exsoinn.util.epf;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6 import java.util.stream.Collectors;
7
8
9
10
11 public class Utilities {
12 public static final String MULTI_VAL_DELIM = "||";
13
14
15
16
17 private Utilities() {
18
19 }
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 public static String toDelimitedString(List<Context> pCtxList) throws IllegalArgumentException {
36 List<String> leftOpVals = new ArrayList<>();
37 Iterator<Context> srIt = pCtxList.iterator();
38 while (srIt.hasNext()) {
39 Context c = srIt.next();
40
41 if (c.isRecursible()) {
42 if (c.entrySet().size() > 1) {
43 throw new IllegalArgumentException("A complex object in the context list "
44 + "contained more than one name/value pair: " + c.stringRepresentation());
45 }
46 leftOpVals.add(c.entrySet().iterator().next().getValue().stringRepresentation());
47 } else if (c.isPrimitive()) {
48 leftOpVals.add(c.stringRepresentation());
49 } else {
50 throw new IllegalArgumentException("An object in the array "
51 + "is neither complex nor a primitive, unsure what to do: " + c.stringRepresentation());
52 }
53 }
54 return leftOpVals.stream().collect(Collectors.joining(MULTI_VAL_DELIM));
55 }
56 }