1 package com.github.mygreen.supercsv.expression;
2
3 import java.util.Arrays;
4 import java.util.Collection;
5 import java.util.Objects;
6 import java.util.stream.Collectors;
7
8 import com.github.mygreen.supercsv.cellprocessor.format.TextPrinter;
9
10
11
12
13
14
15
16
17 public class CustomFunctions {
18
19
20
21
22
23
24
25
26
27
28
29
30 public static String defaultString(final String text) {
31 if(text == null) {
32 return "";
33 }
34
35 return text;
36 }
37
38
39
40
41
42
43
44 public static String join(final int[] array, final String delimiter) {
45
46 if(array == null || array.length == 0) {
47 return "";
48 }
49
50 String value = Arrays.stream(array)
51 .boxed()
52 .map(String::valueOf)
53 .collect(Collectors.joining(defaultString(delimiter)));
54
55 return value;
56 }
57
58
59
60
61
62
63
64 public static String join(final Object[] array, final String delimiter) {
65
66 if(array == null || array.length == 0) {
67 return "";
68 }
69
70 String value = Arrays.stream(array)
71 .map(v -> v.toString())
72 .collect(Collectors.joining(defaultString(delimiter)));
73
74 return value;
75 }
76
77
78
79
80
81
82
83
84
85 @SuppressWarnings({"rawtypes", "unchecked"})
86 public static String join(final Object[] array, final String delimiter, final TextPrinter printer) {
87
88 Objects.requireNonNull(printer);
89
90 if(array == null || array.length == 0) {
91 return "";
92 }
93
94 String value = Arrays.stream(array)
95 .map(v -> printer.print(v))
96 .collect(Collectors.joining(defaultString(delimiter)));
97
98 return value;
99 }
100
101
102
103
104
105
106
107 public static String join(final Collection<?> collection, final String delimiter) {
108
109 if(collection == null || collection.isEmpty()) {
110 return "";
111 }
112
113 String value = collection.stream()
114 .map(v -> v.toString())
115 .collect(Collectors.joining(defaultString(delimiter)));
116
117 return value;
118 }
119
120
121
122
123
124
125
126
127
128 @SuppressWarnings({"rawtypes", "unchecked"})
129 public static String join(final Collection<?> collection, final String delimiter, final TextPrinter printer) {
130
131 Objects.requireNonNull(printer);
132
133 if(collection == null || collection.isEmpty()) {
134 return "";
135 }
136
137 String value = collection.stream()
138 .map(v -> printer.print(v))
139 .collect(Collectors.joining(defaultString(delimiter)));
140
141 return value;
142 }
143
144 }