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.

EntryIterableBuilder.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Copyright (c) 2013 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.Collection;
  15. import java.util.HashSet;
  16. import java.util.Iterator;
  17. import com.healthmarketscience.jackcess.Column;
  18. import com.healthmarketscience.jackcess.IndexCursor;
  19. import com.healthmarketscience.jackcess.Row;
  20. import com.healthmarketscience.jackcess.impl.IndexCursorImpl;
  21. /**
  22. * Builder style class for constructing an {@link IndexCursor} entry
  23. * Iterable/Iterator.
  24. *
  25. * @author James Ahlborn
  26. * @usage _general_class_
  27. */
  28. public class EntryIterableBuilder implements Iterable<Row>
  29. {
  30. private final IndexCursor _cursor;
  31. private Collection<String> _columnNames;
  32. private Object[] _entryValues;
  33. private ColumnMatcher _columnMatcher;
  34. public EntryIterableBuilder(IndexCursor cursor, Object... entryValues) {
  35. _cursor = cursor;
  36. _entryValues = entryValues;
  37. }
  38. public Collection<String> getColumnNames() {
  39. return _columnNames;
  40. }
  41. public ColumnMatcher getColumnMatcher() {
  42. return _columnMatcher;
  43. }
  44. public Object[] getEntryValues() {
  45. return _entryValues;
  46. }
  47. public EntryIterableBuilder setColumnNames(Collection<String> columnNames) {
  48. _columnNames = columnNames;
  49. return this;
  50. }
  51. public EntryIterableBuilder addColumnNames(Iterable<String> columnNames) {
  52. if(columnNames != null) {
  53. for(String name : columnNames) {
  54. addColumnName(name);
  55. }
  56. }
  57. return this;
  58. }
  59. public EntryIterableBuilder addColumns(Iterable<? extends Column> cols) {
  60. if(cols != null) {
  61. for(Column col : cols) {
  62. addColumnName(col.getName());
  63. }
  64. }
  65. return this;
  66. }
  67. public EntryIterableBuilder addColumnNames(String... columnNames) {
  68. if(columnNames != null) {
  69. for(String name : columnNames) {
  70. addColumnName(name);
  71. }
  72. }
  73. return this;
  74. }
  75. private void addColumnName(String columnName) {
  76. if(_columnNames == null) {
  77. _columnNames = new HashSet<String>();
  78. }
  79. _columnNames.add(columnName);
  80. }
  81. public EntryIterableBuilder setEntryValues(Object... entryValues) {
  82. _entryValues = entryValues;
  83. return this;
  84. }
  85. public EntryIterableBuilder setColumnMatcher(ColumnMatcher columnMatcher) {
  86. _columnMatcher = columnMatcher;
  87. return this;
  88. }
  89. @Override
  90. public Iterator<Row> iterator() {
  91. return ((IndexCursorImpl)_cursor).entryIterator(this);
  92. }
  93. }