<commit_before>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.sesame.config;

import com.opengamma.sesame.engine.ComponentMap;
import com.opengamma.sesame.function.Parameter;
import com.opengamma.sesame.graph.Node;
import com.opengamma.sesame.graph.NodeDecorator;
import com.opengamma.util.ArgumentChecker;

/**
 *
 */
public class GraphConfig {

  public static final GraphConfig EMPTY = new GraphConfig(FunctionConfig.EMPTY);

  private final FunctionConfig _functionConfig;
  private final ComponentMap _components;
  private final NodeDecorator _nodeDecorator;

  public GraphConfig(FunctionConfig functionConfig, ComponentMap components, NodeDecorator nodeDecorator) {
    _functionConfig = ArgumentChecker.notNull(functionConfig, "functionConfig");
    _components = ArgumentChecker.notNull(components, "components");
    _nodeDecorator = ArgumentChecker.notNull(nodeDecorator, "nodeDecorator");
  }

  public GraphConfig(FunctionConfig functionConfig) {
    _functionConfig = functionConfig;
    _components = ComponentMap.EMPTY;
    _nodeDecorator = NodeDecorator.IDENTITY;
  }

  public Object getConstructorArgument(Class<?> objectType, Parameter parameter) {
    FunctionArguments args = _functionConfig.getFunctionArguments(objectType);
    Object arg = args.getArgument(parameter.getName());
    if (arg == null) {
      return null;
    } else if (parameter.getType().isInstance(arg)) {
      return arg;
    } else {
      throw new IllegalArgumentException("Argument (" + arg + ": " + arg.getClass().getSimpleName() + ") isn't of the " +
                                             "required type for " + parameter.getFullName());
    }
  }

  public Class<?> getImplementationType(Class<?> interfaceType) {
    return _functionConfig.getFunctionImplementation(interfaceType);
  }

  public Object getObject(Class<?> type) {<commit_msg>SSM-25 - Handle autoboxing of parameters<commit_after>/**
 * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.sesame.config;

import org.apache.commons.lang.ClassUtils;

import com.opengamma.sesame.engine.ComponentMap;
import com.opengamma.sesame.function.Parameter;
import com.opengamma.sesame.graph.Node;
import com.opengamma.sesame.graph.NodeDecorator;
import com.opengamma.util.ArgumentChecker;

/**
 *
 */
public class GraphConfig {

  public static final GraphConfig EMPTY = new GraphConfig(FunctionConfig.EMPTY);

  private final FunctionConfig _functionConfig;
  private final ComponentMap _components;
  private final NodeDecorator _nodeDecorator;

  public GraphConfig(FunctionConfig functionConfig, ComponentMap components, NodeDecorator nodeDecorator) {
    _functionConfig = ArgumentChecker.notNull(functionConfig, "functionConfig");
    _components = ArgumentChecker.notNull(components, "components");
    _nodeDecorator = ArgumentChecker.notNull(nodeDecorator, "nodeDecorator");
  }

  public GraphConfig(FunctionConfig functionConfig) {
    _functionConfig = functionConfig;
    _components = ComponentMap.EMPTY;
    _nodeDecorator = NodeDecorator.IDENTITY;
  }

  public Object getConstructorArgument(Class<?> objectType, Parameter parameter) {
    FunctionArguments args = _functionConfig.getFunctionArguments(objectType);
    Object arg = args.getArgument(parameter.getName());
    if (arg == null) {
      return null;
    // this takes into account boxing of primitives which Class.isAssignableFrom() doesn't
    } else if (ClassUtils.isAssignable(parameter.getType(), arg.getClass(), true)) {
      return arg;
    } else {
      throw new IllegalArgumentException("Argument (" + arg + ": " + arg.getClass().getSimpleName() + ") isn't of the " +
                                             "required type for " + parameter.getFullName());
    }
  }

  public Class<?> getImplementationType(Class<?> interfaceType) {
    return _functionConfig.getFunctionImplementation(interfaceType);
  }

  public Object getObject(Class<?> type) {
{'fraction_non_alphanumeric': 0.09745454545454546, 'fraction_numerical': 0.0024242424242424242, 'mean_word_length': 4.344559585492228, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2558120', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1120, 'n_words': 264}