3 import ca.uqac.lif.cep.Processor;
4 import ca.uqac.lif.cep.tmf.Source;
5 import java.util.Queue;
6 import java.util.Random;
10 public static final String upper =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
12 protected static final String[] m_realNames = {
"MSFT",
"GOGL",
"APPL",
"AMZN",
"RHT",
"IBM",
"DVMT"};
14 protected String[] m_symbolNames;
16 protected float[] m_lastValues;
18 protected Random m_random;
20 protected int m_computeCount;
22 protected int m_maxDays = 0;
24 public TickerFeed(
int num_companies,
int num_days)
27 m_random =
new Random();
29 m_symbolNames =
new String[num_companies];
30 m_lastValues =
new float[num_companies];
31 for (
int i = 0; i < num_companies; i++)
33 if (i < m_realNames.length)
35 m_symbolNames[i] = m_realNames[i];
41 m_lastValues[i] = m_random.nextInt(1000);
58 StringBuilder sb =
new StringBuilder();
59 for (
int i = 0; i < length; i++)
61 sb.append(upper.charAt(m_random.nextInt(25)));
67 protected boolean compute(Object[] inputs, Queue<Object[]> outputs)
69 int num_day = m_computeCount / m_symbolNames.length;
70 if (num_day >= m_maxDays)
74 int pos = m_computeCount % m_symbolNames.length;
75 Object[] out =
new Object[3];
77 out[1] = m_symbolNames[pos];
78 float val = m_lastValues[pos] + 30f * (m_random.nextFloat() - 0.5f);
80 m_lastValues[pos] = val;
81 outputs.add(
new Object[] {out});
87 public Processor duplicate(
boolean with_state)
String randomString(int length)
Generates a random string of given length.