001package ca.uhn.fhir.util; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2017 University Health Network 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import java.util.HashSet; 024import java.util.List; 025import java.util.Set; 026 027import org.hl7.fhir.instance.model.api.IPrimitiveType; 028 029import ca.uhn.fhir.model.primitive.StringDt; 030 031public class DatatypeUtil { 032 033 /** 034 * Convert a list of FHIR String objects to a set of native java Strings 035 */ 036 public static Set<String> toStringSet(List<StringDt> theStringList) { 037 HashSet<String> retVal = new HashSet<String>(); 038 if (theStringList != null) { 039 for (StringDt string : theStringList) { 040 if (string != null && string.getValue()!=null) { 041 retVal.add(string.getValue()); 042 } 043 } 044 } 045 return retVal; 046 } 047 048 /** 049 * Joins a list of strings with a single space (' ') between each string 050 */ 051 public static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) { 052 StringBuilder b = new StringBuilder(); 053 for (IPrimitiveType<String> next : theStrings) { 054 if (next.isEmpty()) { 055 continue; 056 } 057 if (b.length() > 0) { 058 b.append(' '); 059 } 060 b.append(next.getValue()); 061 } 062 return b.toString(); 063 } 064 065}