001/*-
002 * #%L
003 * HAPI FHIR JPA Server - Master Data Management
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.jpa.mdm.svc.candidate;
021
022import java.util.ArrayList;
023import java.util.Collections;
024import java.util.List;
025import java.util.stream.Stream;
026
027public class CandidateList {
028        private final CandidateStrategyEnum myStrategy;
029        private final List<MatchedGoldenResourceCandidate> myList = new ArrayList<>();
030
031        public CandidateList(CandidateStrategyEnum theStrategy) {
032                myStrategy = theStrategy;
033        }
034
035        public CandidateStrategyEnum getStrategy() {
036                return myStrategy;
037        }
038
039        public boolean isEmpty() {
040                return myList.isEmpty();
041        }
042
043        public void addAll(List<MatchedGoldenResourceCandidate> theList) {
044                myList.addAll(theList);
045        }
046
047        public MatchedGoldenResourceCandidate getOnlyMatch() {
048                assert myList.size() == 1;
049                return myList.get(0);
050        }
051
052        public boolean exactlyOneMatch() {
053                return myList.size() == 1;
054        }
055
056        public Stream<MatchedGoldenResourceCandidate> stream() {
057                return myList.stream();
058        }
059
060        public List<MatchedGoldenResourceCandidate> getCandidates() {
061                return Collections.unmodifiableList(myList);
062        }
063
064        public MatchedGoldenResourceCandidate getFirstMatch() {
065                return myList.get(0);
066        }
067
068        public boolean isEidMatch() {
069                return myStrategy.isEidMatch();
070        }
071
072        public int size() {
073                return myList.size();
074        }
075}