/**
 * Copyright (C) 2009 - 2009 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.engine.view;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.opengamma.engine.analytics.AnalyticValue;
import com.opengamma.engine.analytics.AnalyticValueDefinition;
import com.opengamma.engine.position.Position;

/**
 * The model of results for a particular {@link Position} within a
 * {@link ViewComputationResultModelImpl}.
 *
 * @author kirk
 */
public class PositionResultModel implements Serializable {
  private final Position _position;
  private final Map<AnalyticValueDefinition<?>, AnalyticValue<?>> _results = new HashMap<AnalyticValueDefinition<?>, AnalyticValue<?>>();
  
  public PositionResultModel(Position position) {
    if(position == null) {
      throw new NullPointerException("Must specify a valid position.");
    }
    _position = position;
  }

  /**
   * @return the position
   */
  public Position getPosition() {
    return _position;
  }
  
  public Map<AnalyticValueDefinition<?>, AnalyticValue<?>> getAllResults() {
    return Collections.<AnalyticValueDefinition<?>, AnalyticValue<?>>unmodifiableMap(_results);
  }
  
  public void add(AnalyticValue<?> value) {
    if(value == null) {
      throw new NullPointerException("Cannot add a null value.");
    }
    if(value.getDefinition() == null) {
      throw new IllegalArgumentException("Value must have a valid definition.");
    }
    _results.put(value.getDefinition(), value);
  }
  
  public AnalyticValue<?> get(AnalyticValueDefinition<?> definition) {
    if(definition == null) {
      return null;
    }
    return _results.get(definition);
  }

}

@@ -351,16 +351,89 @@
 nition;%0A
+import com.opengamma.engine.analytics.AnalyticValueDefinitionComparator;%0A
 import c
@@ -1767,39 +1767,243 @@
     
-return _results.get(definition)
+for(Map.Entry%3CAnalyticValueDefinition%3C?%3E, AnalyticValue%3C?%3E%3E entry : _results.entrySet()) %7B%0A      if(AnalyticValueDefinitionComparator.matches(definition, entry.getKey())) %7B%0A        return entry.getValue();%0A      %7D%0A    %7D%0A    return null
 ;%0A  

Return individual values based on matching and not equality.