Class StringCollectionUtil
java.lang.Object
ch.tocco.nice2.toolbox.api.string.StringCollectionUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
cutOnMaxSizeAndJoinStrings
(Collection<String> collectionToJoin, String moreThanMaxElementsMessage) joins all elements of the collection using a line break.static <T> String
cutOnMaxSizeAndJoinStrings
(Collection<T> collectionToJoin, Function<T, String> transformerFunction, String moreThanMaxElementsMessage) behaves the same way ascutOnMaxSizeAndJoinStrings(Collection, String)
except that it accepts any type ofCollection
which will be transformed to a stringCollection
using the giventransformerFunction
.static String
joinOnLineBreaks
(Iterable<String> strings) static String
joinOnLineBreaks
(String... strings)
-
Method Details
-
cutOnMaxSizeAndJoinStrings
public static String cutOnMaxSizeAndJoinStrings(Collection<String> collectionToJoin, String moreThanMaxElementsMessage) joins all elements of the collection using a line break. if there are more elements incollectionToJoin
than defined inmaxSize
, the list will be shortened to a size ofMAX_SIZE
and the message inmoreThanMaxElementsMessage
will be appended at the end. Note: use the placeholder %s inmoreThanMaxElementsMessage
if you want to include the number of skipped records in the message- Parameters:
collectionToJoin
- the strings to joinmoreThanMaxElementsMessage
- the message to append when the collection is bigger thanmaxSize
-
cutOnMaxSizeAndJoinStrings
public static <T> String cutOnMaxSizeAndJoinStrings(Collection<T> collectionToJoin, Function<T, String> transformerFunction, String moreThanMaxElementsMessage) behaves the same way ascutOnMaxSizeAndJoinStrings(Collection, String)
except that it accepts any type ofCollection
which will be transformed to a stringCollection
using the giventransformerFunction
. Using this method probably results in a better performance than transforming theCollection
yourself because it will be shortened, if necessary, before the transformation- Parameters:
collectionToJoin
- the strings to jointransformerFunction
- a function which must return aString
moreThanMaxElementsMessage
- the message to append when the collection is bigger thanmaxSize
-
joinOnLineBreaks
-
joinOnLineBreaks
-