PositionAttributeAggregationFunction implements AggregationFunction<String> { @Override public String classifyPosition(final Position position) { String positionAttribute = position.getAttributes().get(getAttribute()); if (positionAttribute != null) { return positionAttribute; } for (Trade trade : position.getTrades()) { final String value = trade.getAttributes().get(getAttribute()); if (value != null) { return value; } } return getUnknownClassification(); } PositionAttributeAggregationFunction(final String attribute);  PositionAttributeAggregationFunction(final String attribute, final String unknownClassification); String getUnknownClassification(); String getAttribute(); @Override String classifyPosition(final Position position); String getName(); @Override Collection<String> getRequiredEntries(); @Override int compare(String o1, String o2); @Override Comparator<Position> getPositionComparator();  }
@Test public void positionAttribute() { SimplePosition position = new SimplePosition(); position.addAttribute(ATTR_NAME, POS_VALUE); assertEquals(POS_VALUE, _aggFn.classifyPosition(position)); }
@Test public void tradeAttribute() { SimplePosition position = new SimplePosition(); SimpleTrade trade = new SimpleTrade(); trade.addAttribute(ATTR_NAME, TRADE_VALUE); position.addTrade(trade); assertEquals(TRADE_VALUE, _aggFn.classifyPosition(position)); }
@Test public void positionAndTradeAttributes() { SimplePosition position = new SimplePosition(); position.addAttribute(ATTR_NAME, POS_VALUE); SimpleTrade trade = new SimpleTrade(); trade.addAttribute(ATTR_NAME, TRADE_VALUE); position.addTrade(trade); assertEquals(POS_VALUE, _aggFn.classifyPosition(position)); }