/** * Some checks for the add() methods. */ public void testAdd() { TimePeriodValues tpv = new TimePeriodValues("Test"); MySeriesChangeListener listener = new MySeriesChangeListener(); tpv.addChangeListener(listener); tpv.add(new TimePeriodValue(new SimpleTimePeriod(new Date(1L), new Date(3L)), 99.0)); assertEquals(99.0, tpv.getValue(0).doubleValue(), EPSILON); assertEquals(tpv, listener.getLastEvent().getSource()); // a null item should throw an IllegalArgumentException boolean pass = false; try { tpv.add((TimePeriodValue) null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
@SuppressWarnings({"unchecked", "rawtypes"}) public void reportValues(Map vars, MarketEvent event) { Millisecond time = new Millisecond(new Date(event.getPhysicalTime())); ArrayList list = new ArrayList(vars.keySet()); Iterator i = list.iterator(); while (i.hasNext()) { ReportVariable var = (ReportVariable) i.next(); Object value = vars.get(var); if (value instanceof Number) { double v = ((Number) value).doubleValue(); if (!Double.isNaN(v)) { reportValue(var.getName(), new TimePeriodValue(time, v)); } } else if (value instanceof Boolean) { reportValue(var.getName(), new TimePeriodValue(time, ((Boolean) value) .booleanValue() ? 1 : 0)); } } }
public void update() { TimePeriodValue tpValue; for (int i = 0; i < varNames.length; i++) { tpValue = ReportVariableBoard.getInstance().getValue(varNames[i]); if (tpValue != null) { if (tpValue.getValue() instanceof Double) { newData(formatter.format(((Double) tpValue.getValue()) .doubleValue())); } else { newData(tpValue.getValue()); } } else { newData(-1); } } }
public void update() { TimePeriodValue tpValue; for (int i = 0; i < varNames.length; i++) { tpValue = ReportVariableBoard.getInstance().getValue(varNames[i]); if (tpValue != null) { if (tpValue.getValue() instanceof Number) { double v = ((Number) tpValue.getValue()).doubleValue(); if (!Double.isNaN(v)) { resultsStats[i].newData(v); } } } else { logger.fatal("Please make sure the historicalDataReport variable " + varNames[i] + " exists!"); } } }
/** * Tests the equals() method. */ public void testEquals() { final TimePeriodValue tpv1 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); final TimePeriodValue tpv2 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); assertTrue(tpv1.equals(tpv2)); assertTrue(tpv2.equals(tpv1)); }
/** * Tests the equals() method. */ public void testEquals() { TimePeriodValue tpv1 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); TimePeriodValue tpv2 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); assertTrue(tpv1.equals(tpv2)); assertTrue(tpv2.equals(tpv1)); }
private ReportVariableBoard() { if (instance != null) throw new Error("ReportVariableBoard cannot be instantiated twice!"); instance = this; board = Collections.synchronizedMap(new HashMap<String, TimePeriodValue>()); }
/** * Test that an instance is equal to itself. */ public void testEqualsSelf() { final TimePeriodValue tpv = new TimePeriodValue(new Day(), 55.75); assertTrue(tpv.equals(tpv)); }
/** * Test that an instance is equal to itself. */ public void testEqualsSelf() { TimePeriodValue tpv = new TimePeriodValue(new Day(), 55.75); assertTrue(tpv.equals(tpv)); }
public TimePeriodValue getValue(String varName) { return board.get(varName); }
public TimePeriodValue getValue(ReportVariable var) { return getValue(var.getName()); }
public void reportValue(ReportVariable var, TimePeriodValue value) { reportValue(var.getName(), value); }
public void reportValue(String varName, TimePeriodValue value) { board.put(varName, value); }
public void reportValue(String varName, double value, MarketEvent event) { Millisecond time = new Millisecond(new Date(event.getPhysicalTime())); reportValue(varName, new TimePeriodValue(time, value)); }