You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TableIterableBuilder.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. Copyright (c) 2015 James Ahlborn
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.util;
  14. import java.util.Iterator;
  15. import java.util.stream.Stream;
  16. import java.util.stream.StreamSupport;
  17. import com.healthmarketscience.jackcess.Database;
  18. import com.healthmarketscience.jackcess.Table;
  19. import com.healthmarketscience.jackcess.impl.DatabaseImpl;
  20. /**
  21. * Builder style class for constructing a {@link Database} Iterable/Iterator
  22. * for {@link Table}s. By default, normal (non-system, non-linked tables) and
  23. * linked tables are included and system tables are not.
  24. *
  25. * @author James Ahlborn
  26. * @usage _general_class_
  27. */
  28. public class TableIterableBuilder implements Iterable<Table>
  29. {
  30. private final Database _db;
  31. private boolean _includeNormalTables = true;
  32. private boolean _includeSystemTables;
  33. private boolean _includeLinkedTables = true;
  34. public TableIterableBuilder(Database db) {
  35. _db = db;
  36. }
  37. public boolean isIncludeNormalTables() {
  38. return _includeNormalTables;
  39. }
  40. public boolean isIncludeSystemTables() {
  41. return _includeSystemTables;
  42. }
  43. public boolean isIncludeLinkedTables() {
  44. return _includeLinkedTables;
  45. }
  46. public TableIterableBuilder setIncludeNormalTables(boolean includeNormalTables) {
  47. _includeNormalTables = includeNormalTables;
  48. return this;
  49. }
  50. public TableIterableBuilder setIncludeSystemTables(boolean includeSystemTables) {
  51. _includeSystemTables = includeSystemTables;
  52. return this;
  53. }
  54. public TableIterableBuilder setIncludeLinkedTables(boolean includeLinkedTables) {
  55. _includeLinkedTables = includeLinkedTables;
  56. return this;
  57. }
  58. /**
  59. * Convenience method to set the flags to include only non-linked (local)
  60. * user tables.
  61. */
  62. public TableIterableBuilder withLocalUserTablesOnly() {
  63. setIncludeNormalTables(true);
  64. setIncludeSystemTables(false);
  65. return setIncludeLinkedTables(false);
  66. }
  67. /**
  68. * Convenience method to set the flags to include only system tables.
  69. */
  70. public TableIterableBuilder withSystemTablesOnly() {
  71. setIncludeNormalTables(false);
  72. setIncludeSystemTables(true);
  73. return setIncludeLinkedTables(false);
  74. }
  75. @Override
  76. public Iterator<Table> iterator() {
  77. return ((DatabaseImpl)_db).iterator(this);
  78. }
  79. /**
  80. * @return a Stream using the default Iterator.
  81. */
  82. public Stream<Table> stream() {
  83. return StreamSupport.stream(spliterator(), false);
  84. }
  85. }