View Javadoc
1   package ca.uhn.fhir.util;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.hl7.fhir.instance.model.api.IPrimitiveType;
24  
25  import java.util.HashSet;
26  import java.util.List;
27  import java.util.Set;
28  
29  public class DatatypeUtil {
30  
31  	/**
32  	 * Convert a list of FHIR String objects to a set of native java Strings
33  	 */
34  	public static Set<String> toStringSet(List<? extends IPrimitiveType<?>> theStringList) {
35  		HashSet<String> retVal = new HashSet<>();
36  		if (theStringList != null) {
37  			for (IPrimitiveType<?> string : theStringList) {
38  				if (string != null && string.getValue()!=null) {
39  					retVal.add(string.getValueAsString());
40  				}
41  			}
42  		}
43  		return retVal;
44  	}
45  
46  	/**
47  	 * Joins a list of strings with a single space (' ') between each string 
48  	 */
49  	public static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
50  		StringBuilder b = new StringBuilder();
51  		for (IPrimitiveType<String> next : theStrings) {
52  			if (next.isEmpty()) {
53  				continue;
54  			}
55  			if (b.length() > 0) {
56  				b.append(' ');
57  			}
58  			b.append(next.getValue());
59  		}
60  		return b.toString();
61  	}
62  
63  }