View Javadoc
1   /*
2    * Copyright 2012-2018 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.ds;
17  
18  import java.util.ArrayList;
19  import java.util.LinkedHashMap;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Set;
23  
24  public class DataStoreFactory {
25      protected Map<String, DataStore> dataStoreMap = new LinkedHashMap<>();
26  
27      public void add(final String name, final DataStore dataStore) {
28          if (name == null || dataStore == null) {
29              throw new IllegalArgumentException("name or dataStore is null.");
30          }
31          dataStoreMap.put(name, dataStore);
32      }
33  
34      public DataStore getDataStore(final String name) {
35          return dataStoreMap.get(name);
36      }
37  
38      public List<String> getDataStoreNameList() {
39          final Set<String> nameSet = dataStoreMap.keySet();
40          final List<String> nameList = new ArrayList<>();
41          nameList.addAll(nameSet);
42          return nameList;
43      }
44  
45  }