001/*-
002 * #%L
003 * HAPI FHIR - Core Library
004 * %%
005 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.validation;
021
022import org.apache.commons.lang3.Validate;
023
024import java.util.Collections;
025import java.util.HashSet;
026import java.util.Set;
027
028import static org.apache.commons.lang3.StringUtils.isNotBlank;
029
030public class ValidationOptions {
031
032        private static ValidationOptions ourEmpty;
033        private Set<String> myProfiles;
034
035        public ValidationOptions() {}
036
037        public Set<String> getProfiles() {
038                return myProfiles != null ? Collections.unmodifiableSet(myProfiles) : Collections.emptySet();
039        }
040
041        public ValidationOptions addProfile(String theProfileUri) {
042                Validate.notBlank(theProfileUri);
043
044                if (myProfiles == null) {
045                        myProfiles = new HashSet<>();
046                }
047                myProfiles.add(theProfileUri);
048                return this;
049        }
050
051        public ValidationOptions addProfileIfNotBlank(String theProfileUri) {
052                if (isNotBlank(theProfileUri)) {
053                        return addProfile(theProfileUri);
054                }
055                return this;
056        }
057
058        public static ValidationOptions empty() {
059                ValidationOptions retVal = ourEmpty;
060                if (retVal == null) {
061                        retVal = new ValidationOptions();
062                        retVal.myProfiles = Collections.emptySet();
063                        ourEmpty = retVal;
064                }
065                return retVal;
066        }
067}