MCPcopy Create free account
hub / github.com/WinVector/Logistic / AdapterIterableBase

Class AdapterIterableBase

src/com/winvector/opt/impl/AdapterIterableBase.java:10–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import com.winvector.variables.VariableEncodings;
9
10public abstract class AdapterIterableBase<T extends ExampleRow> implements Iterable<T> {
11
12 private final Iterable<BurstMap> rawSource;
13 public final VariableEncodings adapter;
14
15 protected AdapterIterableBase(final VariableEncodings adapter, final Iterable<BurstMap> rawSource) {
16 this.rawSource = rawSource;
17 this.adapter = adapter;
18 }
19
20 protected SparseExampleRow buildSparseRow(final BurstMap row) {
21 final SparseSemiVec vec = adapter.vector(row);
22 if(null==vec) {
23 return null;
24 }
25 int catInt = -1; // allowed to be missing
26 final String resStr = row.getAsString(adapter.def().resultColumn);
27 if((resStr!=null)&&(resStr.length()>0)) {
28 final Integer category = adapter.category(resStr);
29 if(category!=null) {
30 catInt = category;
31 }
32 }
33 return new SparseExampleRow(vec,1.0,catInt);
34 }
35
36 protected abstract T buildRow(final BurstMap row);
37
38 private class AI implements Iterator<T> {
39 private Iterator<BurstMap> raw = rawSource.iterator();
40 private T next = null;
41
42 public AI() {
43 advance();
44 }
45
46 private void advance() {
47 next = null;
48 while((next==null)&&(raw!=null)) {
49 if(!raw.hasNext()) {
50 raw = null;
51 break;
52 }
53 final BurstMap row = raw.next();
54 next = buildRow(row);
55 }
56 }
57
58 @Override
59 public boolean hasNext() {
60 return next!=null;
61 }
62
63 @Override
64 public T next() {
65 if(!hasNext()) {
66 throw new NoSuchElementException();
67 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected