1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.healthmarketscience.jackcess.util;
18
19 import java.util.Collection;
20 import java.util.HashSet;
21 import java.util.Iterator;
22 import java.util.stream.Stream;
23 import java.util.stream.StreamSupport;
24
25 import com.healthmarketscience.jackcess.Column;
26 import com.healthmarketscience.jackcess.IndexCursor;
27 import com.healthmarketscience.jackcess.Row;
28 import com.healthmarketscience.jackcess.impl.IndexCursorImpl;
29
30
31
32
33
34
35
36
37 public class EntryIterableBuilder implements Iterable<Row>
38 {
39 private final IndexCursor _cursor;
40
41 private Collection<String> _columnNames;
42 private Object[] _entryValues;
43 private ColumnMatcher _columnMatcher;
44
45 public EntryIterableBuilder(IndexCursor cursor, Object... entryValues) {
46 _cursor = cursor;
47 _entryValues = entryValues;
48 }
49
50 public Collection<String> getColumnNames() {
51 return _columnNames;
52 }
53
54 public ColumnMatcher getColumnMatcher() {
55 return _columnMatcher;
56 }
57
58 public Object[] getEntryValues() {
59 return _entryValues;
60 }
61
62 public EntryIterableBuilder setColumnNames(Collection<String> columnNames) {
63 _columnNames = columnNames;
64 return this;
65 }
66
67 public EntryIterableBuilder addColumnNames(Iterable<String> columnNames) {
68 if(columnNames != null) {
69 for(String name : columnNames) {
70 addColumnName(name);
71 }
72 }
73 return this;
74 }
75
76 public EntryIterableBuilder addColumns(Iterable<? extends Column> cols) {
77 if(cols != null) {
78 for(Column col : cols) {
79 addColumnName(col.getName());
80 }
81 }
82 return this;
83 }
84
85 public EntryIterableBuilder addColumnNames(String... columnNames) {
86 if(columnNames != null) {
87 for(String name : columnNames) {
88 addColumnName(name);
89 }
90 }
91 return this;
92 }
93
94 private void addColumnName(String columnName) {
95 if(_columnNames == null) {
96 _columnNames = new HashSet<String>();
97 }
98 _columnNames.add(columnName);
99 }
100
101 public EntryIterableBuilder setEntryValues(Object... entryValues) {
102 _entryValues = entryValues;
103 return this;
104 }
105
106 public EntryIterableBuilder setColumnMatcher(ColumnMatcher columnMatcher) {
107 _columnMatcher = columnMatcher;
108 return this;
109 }
110
111 @Override
112 public Iterator<Row> iterator() {
113 return ((IndexCursorImpl)_cursor).entryIterator(this);
114 }
115
116
117
118
119 public Stream<Row> stream() {
120 return StreamSupport.stream(spliterator(), false);
121 }
122 }