001package ca.uhn.fhir.validation; 002 003/*- 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2021 Smile CDR, Inc. 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 org.apache.commons.lang3.Validate; 024 025import java.util.Collections; 026import java.util.HashSet; 027import java.util.Set; 028 029import static org.apache.commons.lang3.StringUtils.isNotBlank; 030 031public class ValidationOptions { 032 033 private static ValidationOptions ourEmpty; 034 private Set<String> myProfiles; 035 036 public Set<String> getProfiles() { 037 return myProfiles != null ? Collections.unmodifiableSet(myProfiles) : Collections.emptySet(); 038 } 039 040 public ValidationOptions addProfile(String theProfileUri) { 041 Validate.notBlank(theProfileUri); 042 043 if (myProfiles == null) { 044 myProfiles = new HashSet<>(); 045 } 046 myProfiles.add(theProfileUri); 047 return this; 048 } 049 050 public ValidationOptions addProfileIfNotBlank(String theProfileUri) { 051 if (isNotBlank(theProfileUri)) { 052 return addProfile(theProfileUri); 053 } 054 return this; 055 } 056 057 public static ValidationOptions empty() { 058 ValidationOptions retVal = ourEmpty; 059 if (retVal == null) { 060 retVal = new ValidationOptions(); 061 retVal.myProfiles = Collections.emptySet(); 062 ourEmpty = retVal; 063 } 064 return retVal; 065 } 066 067}