My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package org.shapelogic.streams;

import java.util.ArrayList;
import java.util.List;

import org.shapelogic.calculation.RecursiveContext;
import org.shapelogic.util.Constants;

/** ArrayOutputListStream takes a list of NumberStreams and creates a ListStream of double[].<br />
*
* This could be made more general, but start simple.<br />
*
* @author Sami Badawi
*
*/
public class ArrayOutputListStream extends BaseListStreamList<Number,double[]> {

/** Parallel to the NumberedStream. */
protected List<String> _ohNames;
protected boolean _setupRun = false;

/** Use the ohName to also be the name of the input stream. <br />
*
* @param ohNames
* @param maxLast
*/
public ArrayOutputListStream(List<String> ohNames,
RecursiveContext recursiveContext, String name, int maxLast) {
super(null,maxLast);
_ohNames = ohNames;
_context = recursiveContext.getContext();
_parentContext = recursiveContext.getParentContext();
_inputStream = new ArrayList();
if (name != null)
_context.put(name, this);
_name = name;
}

public ArrayOutputListStream(List<String> ohNames, RecursiveContext recursiveContext,int maxLast) {
this (ohNames, recursiveContext, (String) null, maxLast);
}

public ArrayOutputListStream(List<String> ohNames, RecursiveContext recursiveContext) {
this(ohNames, recursiveContext, Constants.LAST_UNKNOWN);
}

public ArrayOutputListStream(List<String> ohNames, RecursiveContext recursiveContext, List<NumberedStream<Number> > inputStream, int maxLast) {
super(inputStream, maxLast);
_ohNames = ohNames;
}

public ArrayOutputListStream(List<String> ohNames, RecursiveContext recursiveContext, List<NumberedStream<Number> > inputStream) {
this(ohNames,recursiveContext,inputStream,Constants.LAST_UNKNOWN);
}

@Override
public void setup() {
_setupRun = true;
for (String streamName: _ohNames) {
NumberedStream numberedStream = StreamFactory.findNumberedStream(streamName, this);
if (numberedStream != null)
getInputStream().add(numberedStream);
else
throw new RuntimeException("No stream found for name: " + _ohNames);
}
_setupRun = true;
}

@Override
public double[] invoke(List<Number> input) {
double[] result = new double[input.size()];
int i = 0;
for (Number bool : input) {
result[i] = bool.doubleValue();
i++;
}
return result;
}

@Override
public List<NumberedStream<Number> > getInputStream() {
if (!_setupRun)
setup();
return _inputStream;
}
}

Change log

r993 by sami.badawi on Jan 2, 2009   Diff
Bug fix.
Go to: 
Project members, sign in to write a code review

Older revisions

r988 by sami.badawi on Dec 30, 2008   Diff
Changed to use lazy init of the input
streams.
r981 by sami.badawi on Dec 29, 2008   Diff
ArrayOutputListStream takes a list of
NumberStreams and creates a ListStream
of double[].
All revisions of this file

File info

Size: 2582 bytes, 86 lines
Powered by Google Project Hosting