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