1 /*
2 * Copyright 2018 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.openehealth.ipf.commons.ihe.core;
18
19 import java.util.List;
20 import java.util.stream.Collectors;
21 import java.util.stream.Stream;
22
23 /**
24 * Some utilities for {@link TransactionOptions}
25 */
26 public interface TransactionOptionUtils {
27
28 /**
29 * Splits a string containing comma-separated {@link TransactionOptions transaction option enum names}
30 * into a list of {@link TransactionOptions}.
31 *
32 * @param optionString option string, comma-separated
33 * @param clazz TransactionOptions enum
34 * @param <T> TransactionOptions type
35 * @return list of TransactionOptions
36 */
37 static <T extends Enum<T> & TransactionOptions<?>> List<T> split(String optionString, Class<T> clazz) {
38 if (optionString == null || optionString.isEmpty()) return null;
39 String[] optionStrings = optionString.split("\\s*,\\s*");
40 return Stream.of(optionStrings)
41 .map(s -> Enum.valueOf(clazz, s))
42 .collect(Collectors.toList());
43 }
44
45 }