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

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

import javax.time.Instant;

import com.opengamma.engine.depgraph.DependencyGraphBuilder;
import com.opengamma.engine.function.resolver.CompiledFunctionResolver;
import com.opengamma.engine.view.ViewDefinition;

/**
 * Holds context relating to the partially-completed compilation of a view definition, for passing to different stages
 * of the compilation.
 */
public class ViewCompilationContext {

  private final ViewDefinition _viewDefinition;
  private final ViewCompilationServices _services;
  private final Map<String, DependencyGraphBuilder> _builders;

  /* package */ViewCompilationContext(ViewDefinition viewDefinition, ViewCompilationServices compilationServices, Instant atInstant) {
    _viewDefinition = viewDefinition;
    _services = compilationServices;
    _builders = generateBuilders(viewDefinition, compilationServices, atInstant);
  }

  // --------------------------------------------------------------------------
  public ViewDefinition getViewDefinition() {
    return _viewDefinition;
  }

  public ViewCompilationServices getServices() {
    return _services;
  }

  public Map<String, DependencyGraphBuilder> getBuilders() {
    return Collections.unmodifiableMap(_builders);
  }

  // --------------------------------------------------------------------------
  private Map<String, DependencyGraphBuilder> generateBuilders(ViewDefinition viewDefinition, ViewCompilationServices compilationServices, Instant atInstant) {
    Map<String, DependencyGraphBuilder> result = new HashMap<String, DependencyGraphBuilder>();
    final CompiledFunctionResolver functionResolver = compilationServices.getFunctionResolver().compile(atInstant);
    for (String configName : viewDefinition.getAllCalculationConfigurationNames()) {
      DependencyGraphBuilder builder = new DependencyGraphBuilder();
      builder.setCalculationConfigurationName(configName);
      builder.setLiveDataAvailabilityProvider(compilationServices.getLiveDataAvailabilityProvider());
      builder.setTargetResolver(compilationServices.getComputationTargetResolver());
      builder.setFunctionResolver(functionResolver);
      builder.setCompilationContext(compilationServices.getFunctionCompilationContext());<commit_msg>Review comments.<commit_after>/**
 * Copyright (C) 2009 - 2010 by OpenGamma Inc.
 * 
 * Please see distribution for license.
 */
package com.opengamma.engine.view.compilation;

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

import javax.time.Instant;

import com.opengamma.engine.depgraph.DependencyGraphBuilder;
import com.opengamma.engine.function.resolver.CompiledFunctionResolver;
import com.opengamma.engine.view.ViewDefinition;

/**
 * Holds context relating to the partially-completed compilation of a view definition, for passing to different stages
 * of the compilation.
 */
public class ViewCompilationContext {

  private final ViewDefinition _viewDefinition;
  private final ViewCompilationServices _services;
  private final Map<String, DependencyGraphBuilder> _builders;

  /* package */ViewCompilationContext(ViewDefinition viewDefinition, ViewCompilationServices compilationServices, Instant atInstant) {
    _viewDefinition = viewDefinition;
    _services = compilationServices;
    _builders = generateBuilders(viewDefinition, compilationServices, atInstant);
  }

  // --------------------------------------------------------------------------
  public ViewDefinition getViewDefinition() {
    return _viewDefinition;
  }

  public ViewCompilationServices getServices() {
    return _services;
  }

  public Map<String, DependencyGraphBuilder> getBuilders() {
    return Collections.unmodifiableMap(_builders);
  }

  // --------------------------------------------------------------------------
  private Map<String, DependencyGraphBuilder> generateBuilders(ViewDefinition viewDefinition, ViewCompilationServices compilationServices, Instant atInstant) {
    Map<String, DependencyGraphBuilder> result = new HashMap<String, DependencyGraphBuilder>();
    final CompiledFunctionResolver functionResolver = compilationServices.getFunctionResolver().compile(atInstant);
    for (String configName : viewDefinition.getAllCalculationConfigurationNames()) {
      DependencyGraphBuilder builder = new DependencyGraphBuilder();
      builder.setCalculationConfigurationName(configName);
      builder.setLiveDataAvailabilityProvider(compilationServices.getLiveDataAvailabilityProvider());
      builder.setTargetResolver(compilationServices.getComputationTargetResolver());
      // REVIEW 2010-12-22 Andrew -- should the same function resolver be used for all view configurations? How do we select e.g. different function parameters, or re-prioritize the repository?
      builder.setFunctionResolver(functionResolver);
      // REVIEW 2010-12-22 Andrew -- should the same compilation context be used for all view configurations?
      // What about config that might influence a function's input requirements and abilities?
      // Could we pass the ViewCalculationConfiguration object and let the functions make decisions from that?
      builder.setCompilationContext(compilationServices.getFunctionCompilationContext());
{'fraction_non_alphanumeric': 0.12465475971276008, 'fraction_numerical': 0.00589210090222795, 'mean_word_length': 4.076635514018691, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7155050', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1229, 'n_words': 320}