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