001package ca.uhn.fhir.rest.server;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2016 University Health Network
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.Collections;
024import java.util.List;
025
026import org.hl7.fhir.instance.model.api.IBaseResource;
027
028import ca.uhn.fhir.model.primitive.InstantDt;
029
030/**
031 * Utility methods for working with {@link IBundleProvider}
032 */
033public class BundleProviders {
034
035        /** Non instantiable */
036        private BundleProviders() {
037                //nothing
038        }
039
040        /**
041         * Create a new unmodifiable empty resource list with the current time as the publish date.
042         */
043        public static IBundleProvider newEmptyList() {
044                final InstantDt published = InstantDt.withCurrentTime();
045                return new IBundleProvider() {
046                        @Override
047                        public List<IBaseResource> getResources(int theFromIndex, int theToIndex) {
048                                return Collections.emptyList();
049                        }
050
051                        @Override
052                        public int size() {
053                                return 0;
054                        }
055
056                        @Override
057                        public InstantDt getPublished() {
058                                return published;
059                        }
060
061                        @Override
062                        public Integer preferredPageSize() {
063                                return null;
064                        }
065                };
066        }
067
068        public static IBundleProvider newList(IBaseResource theResource) {
069                return new SimpleBundleProvider(theResource);
070        }
071
072        public static IBundleProvider newList(List<IBaseResource> theResources) {
073                return new SimpleBundleProvider(theResources);
074        }
075}