001/**
002 * Copyright (c) 2012, 2015, Credit Suisse (Anatole Tresch), Werner Keil and others by the @author tag.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016package org.javamoney.moneta.internal.loader;
017
018import java.util.Objects;
019
020import org.javamoney.moneta.spi.LoadDataInformation;
021
022/**
023 * @param resourceId       The dataId.
024 * @param cache            The cache to be used for storing remote data locally.
025 * @param properties       The configuration properties.
026 * @param fallbackLocation teh fallback ULR, not null.
027 * @param locations        the remote locations, not null (but may be empty!)
028 */
029public class LoadableResourceBuilder {
030
031        private LoadDataInformation loadDataInformation;
032
033        private ResourceCache cache;
034
035        public LoadableResourceBuilder withLoadDataInformation(LoadDataInformation loadDataInformation) {
036                this.loadDataInformation = loadDataInformation;
037                return this;
038        }
039
040        public LoadableResourceBuilder withCache(ResourceCache cache) {
041                this.cache = cache;
042                return this;
043        }
044
045        public LoadableResource build() {
046                if(Objects.isNull(cache)) {
047                        throw new IllegalStateException("The cache should be informed");
048                }
049                if(Objects.isNull(loadDataInformation)) {
050                        throw new IllegalStateException("The loadDataInformation should be informed");
051                }
052                return new LoadableResource(cache, loadDataInformation);
053        }
054
055        @Override
056        public String toString() {
057                StringBuilder sb = new StringBuilder();
058                sb.append(LoadableResourceBuilder.class.getName()).append('{')
059                .append(" loadDataInformation: ").append(loadDataInformation).append(',')
060                .append(" cache: ").append(loadDataInformation).append('}');
061                return sb.toString();
062        }
063}