/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.aggregation;

import java.util.Collection;
import java.util.Collections;

import com.opengamma.core.position.Position;
import com.opengamma.financial.security.FinancialSecurityUtils;
/**
 * Function to classify positions by Currency.
 *
 */
public class CurrencyAggregationFunction implements AggregationFunction<String> {

  private static final String NAME = "Currency";
  
  @Override
  public String classifyPosition(Position position) {
    try {
      return FinancialSecurityUtils.getCurrency(position.getSecurity()).toString();
    } catch (UnsupportedOperationException ex) {
      return "No or multiple currencies";
    }
  }

  public String getName() {
    return NAME;
  }

  @Override
  public Collection<String> getRequiredEntries() {
    return Collections.emptyList();
  }
}

@@ -346,16 +346,58 @@
 yUtils;%0A
+import com.opengamma.util.money.Currency;%0A
 /**%0A * F
@@ -578,16 +578,89 @@
 rency%22;%0A
+  private static final String NO_CURRENCY = %22No or multiple currencies%22;%0A
   %0A  @Ov
@@ -736,22 +736,35 @@
 %7B%0A      
-return
+Currency currency =
  Financi
@@ -814,16 +814,105 @@
 urity())
+;%0A      if (currency == null) %7B%0A        return NO_CURRENCY;%0A      %7D%0A      return currency
 .toStrin
@@ -982,35 +982,19 @@
 urn 
-%22No or multiple currencies%22
+NO_CURRENCY
 ;%0A  

Handle no currency properly, as well as multiple currency