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.spi.loader;
017
018import org.javamoney.moneta.spi.LoadDataInformation;
019
020/**
021 * Builder of {@link LoadableResource}.
022 */
023public class LoadableResourceBuilder {
024
025        private LoadDataInformation loadDataInformation;
026
027        private ResourceCache cache;
028
029        public LoadableResourceBuilder withLoadDataInformation(LoadDataInformation loadDataInformation) {
030                this.loadDataInformation = loadDataInformation;
031                return this;
032        }
033
034        public LoadableResourceBuilder withCache(ResourceCache cache) {
035                this.cache = cache;
036                return this;
037        }
038
039        public LoadableResource build() {
040                if(cache==null) {
041                        throw new IllegalStateException("The cache should be informed");
042                }
043                if(loadDataInformation==null) {
044                        throw new IllegalStateException("The loadDataInformation should be informed");
045                }
046                return new LoadableResource(cache, loadDataInformation);
047        }
048
049        @Override
050        public String toString() {
051                String sb = LoadableResourceBuilder.class.getName() + '{' +
052                                " loadDataInformation: " + loadDataInformation + ',' +
053                                " cache: " + loadDataInformation + '}';
054                return sb;
055        }
056}