Exemplo n.º 1
0
 @Override
 public Object getValue(final Object object, final String name) {
   if (object instanceof Position) {
     final Position position = (Position) object;
     if ("trade".equals(name)) {
       final Collection<Trade> trades = position.getTrades();
       if (trades.size() == 1) {
         return trades.iterator().next();
       } else if (trades.isEmpty()) {
         return UserExpression.NA;
       } else {
         return new AnyTradeAttribute(trades);
       }
     } else {
       Object value = position.getAttributes().get(name);
       if (value != null) {
         return value;
       } else {
         for (Trade trade : position.getTrades()) {
           value = trade.getAttributes().get(name);
           if (value != null) {
             return value;
           }
         }
         return UserExpression.NA;
       }
     }
   } else if (object instanceof AnyTradeAttribute) {
     final AnyTradeAttribute trades = (AnyTradeAttribute) object;
     for (Trade trade : trades.getTrades()) {
       final Object value = trade.getAttributes().get(name);
       if (value != null) {
         return value;
       }
     }
     return UserExpression.NA;
   } else if (object instanceof Trade) {
     final Trade trade = (Trade) object;
     final Object value = trade.getAttributes().get(name);
     if (value != null) {
       return value;
     } else {
       return UserExpression.NA;
     }
   } else {
     return UserExpression.NA;
   }
 }
Exemplo n.º 2
0
 @Override
 public Map<String, String> getAttributes() {
   Map<String, String> allAttributes = Maps.newHashMap();
   for (Trade trade : _trades) {
     allAttributes.putAll(trade.getAttributes());
   }
   return allAttributes;
 }