View Javadoc
1   /*
2   Copyright (c) 2015 James Ahlborn
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, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16  
17  package com.healthmarketscience.jackcess.util;
18  
19  import java.util.Iterator;
20  
21  import com.healthmarketscience.jackcess.Database;
22  import com.healthmarketscience.jackcess.Table;
23  import com.healthmarketscience.jackcess.impl.DatabaseImpl;
24  
25  /**
26   * Builder style class for constructing a {@link Database} Iterable/Iterator
27   * for {@link Table}s.  By default, normal (non-system, non-linked tables) and
28   * linked tables are included and system tables are not.
29   *
30   * @author James Ahlborn
31   * @usage _general_class_
32   */
33  public class TableIterableBuilder implements Iterable<Table>
34  {
35    private final Database _db;
36    private boolean _includeNormalTables = true;
37    private boolean _includeSystemTables;
38    private boolean _includeLinkedTables = true;
39    
40    public TableIterableBuilder(Database db) {
41      _db = db;
42    }
43  
44    public boolean isIncludeNormalTables() {
45      return _includeNormalTables;
46    }
47    
48    public boolean isIncludeSystemTables() {
49      return _includeSystemTables;
50    }
51    
52    public boolean isIncludeLinkedTables() {
53      return _includeLinkedTables;
54    }
55    
56    public TableIterableBuilder setIncludeNormalTables(boolean includeNormalTables) {
57      _includeNormalTables = includeNormalTables;
58      return this;
59    }
60    
61    public TableIterableBuilder setIncludeSystemTables(boolean includeSystemTables) {
62      _includeSystemTables = includeSystemTables;
63      return this;
64    }
65  
66    public TableIterableBuilder setIncludeLinkedTables(boolean includeLinkedTables) {
67      _includeLinkedTables = includeLinkedTables;
68      return this;
69    }
70  
71    /**
72     * Convenience method to set the flags to include only non-linked (local)
73     * user tables.
74     */
75    public TableIterableBuilder withLocalUserTablesOnly() {
76      setIncludeNormalTables(true);
77      setIncludeSystemTables(false);
78      return setIncludeLinkedTables(false);
79    }
80    
81    /**
82     * Convenience method to set the flags to include only system tables.
83     */
84    public TableIterableBuilder withSystemTablesOnly() {
85      setIncludeNormalTables(false);
86      setIncludeSystemTables(true);
87      return setIncludeLinkedTables(false);
88    }
89    
90    public Iterator<Table> iterator() {
91      return ((DatabaseImpl)_db).iterator(this);
92    }
93  }