gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / util / IterableBuilder.java @ 2345
History | View | Annotate | Download (1.91 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.tools.util; |
24 |
|
25 |
import java.util.ArrayList; |
26 |
import java.util.Collections; |
27 |
import java.util.Iterator; |
28 |
import java.util.List; |
29 |
|
30 |
/**
|
31 |
*
|
32 |
* @author gvSIG Team
|
33 |
*/
|
34 |
public class IterableBuilder<T> { |
35 |
|
36 |
public List<T> l; |
37 |
public Iterator<T> it; |
38 |
|
39 |
public IterableBuilder() {
|
40 |
this.l = null; |
41 |
this.it = null; |
42 |
} |
43 |
|
44 |
public IterableBuilder(Iterator<T> iterator) { |
45 |
this.l = null; |
46 |
this.it = iterator;
|
47 |
} |
48 |
|
49 |
public IterableBuilder add(Iterator<T> iterator) { |
50 |
this.it = iterator;
|
51 |
return this; |
52 |
} |
53 |
|
54 |
public IterableBuilder add(T value) {
|
55 |
if( this.l==null ) { |
56 |
this.l = new ArrayList<>(); |
57 |
} |
58 |
this.l.add(value);
|
59 |
return this; |
60 |
} |
61 |
|
62 |
public Iterable<T> build(Iterator<T> it) { |
63 |
return () -> it;
|
64 |
} |
65 |
|
66 |
public Iterable<T> build() { |
67 |
if( this.l!=null ) { |
68 |
return this.l; |
69 |
} |
70 |
if( this.it!=null ) { |
71 |
return () -> it;
|
72 |
} |
73 |
return Collections.EMPTY_LIST; |
74 |
} |
75 |
} |