<commit_before>/**
 * 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);
  }

}<commit_msg>Return individual values based on matching and not equality.<commit_after>/**
 * 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.analytics.AnalyticValueDefinitionComparator;
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;
    }
    for(Map.Entry<AnalyticValueDefinition<?>, AnalyticValue<?>> entry : _results.entrySet()) {
      if(AnalyticValueDefinitionComparator.matches(definition, entry.getKey())) {
        return entry.getValue();
      }
    }
    return null;
  }

}
{'fraction_non_alphanumeric': 0.1174025974025974, 'fraction_numerical': 0.004155844155844156, 'mean_word_length': 4.211096075778078, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4888445', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1074, 'n_words': 268}