001package ca.uhn.fhir.validation; 002 003/*- 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2022 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 ValidationOptions() { 037 } 038 039 public Set<String> getProfiles() { 040 return myProfiles != null ? Collections.unmodifiableSet(myProfiles) : Collections.emptySet(); 041 } 042 043 public ValidationOptions addProfile(String theProfileUri) { 044 Validate.notBlank(theProfileUri); 045 046 if (myProfiles == null) { 047 myProfiles = new HashSet<>(); 048 } 049 myProfiles.add(theProfileUri); 050 return this; 051 } 052 053 public ValidationOptions addProfileIfNotBlank(String theProfileUri) { 054 if (isNotBlank(theProfileUri)) { 055 return addProfile(theProfileUri); 056 } 057 return this; 058 } 059 060 public static ValidationOptions empty() { 061 ValidationOptions retVal = ourEmpty; 062 if (retVal == null) { 063 retVal = new ValidationOptions(); 064 retVal.myProfiles = Collections.emptySet(); 065 ourEmpty = retVal; 066 } 067 return retVal; 068 } 069 070}