View Javadoc
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.hl7v2;
18  
19  import org.openehealth.ipf.commons.ihe.core.TransactionOptions;
20  
21  import java.util.*;
22  import java.util.stream.Collectors;
23  
24  /**
25   * @author Christian Ohr
26   */
27  public interface HL7v2TransactionOption extends TransactionOptions<String> {
28  
29  
30      static List<String> concat(HL7v2TransactionOption options, List<String> suffix) {
31          if (suffix != null && !suffix.isEmpty()) {
32              // Remove potential duplicates
33              Set<String> events = new HashSet<>(options.getSupportedThings());
34              events.addAll(suffix);
35              return new ArrayList<>(events);
36          }
37          return options.getSupportedThings();
38      }
39  
40      static List<String> concat(HL7v2TransactionOption option, HL7v2TransactionOption otherOption, List<String> suffix) {
41          List<String> events = concat(otherOption, suffix);
42          return concat(option, events);
43      }
44  
45      /**
46       * Provides a concatenated string with all things the options support, separated with spaces
47       *
48       * @param options transaction options
49       * @param <T>     TransactionOptions type
50       * @return concatenated string
51       */
52      static <T extends HL7v2TransactionOption> String concatAllToString(List<? extends T> options) {
53          return options.stream()
54                  .flatMap(o -> o.getSupportedThings().stream())
55                  .map(Object::toString)
56                  .collect(Collectors.joining(" "));
57      }
58  }