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

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.ObjectUtils;

import com.opengamma.engine.ComputationTarget;
import com.opengamma.engine.ComputationTargetType;
import com.opengamma.engine.value.ComputedValue;
import com.opengamma.engine.value.ValueRequirement;
import com.opengamma.engine.value.ValueSpecification;

/**
 * A function suitable for use in mock environments.
 *
 */
public class MockFunction extends AbstractFunction implements FunctionInvoker {
  private final ComputationTarget _target;
  private final Set<ValueRequirement> _requirements = new HashSet<ValueRequirement>();
  private final Set<ValueSpecification> _resultSpecs = new HashSet<ValueSpecification>();
  private final Set<ComputedValue> _results = new HashSet<ComputedValue>();
  
  public MockFunction(ComputationTarget target) {
    this(target, Collections.<ValueRequirement>emptySet(), Collections.<ComputedValue>emptySet());
  }

  public MockFunction(ComputationTarget target, Collection<ValueRequirement> requirements, Collection<ComputedValue> results) {
    _target = target;
    _requirements.addAll(requirements);
    _results.addAll(results);
    for (ComputedValue result : _results) {
      _resultSpecs.add(result.getSpecification());
    }
  }

  @Override
  public boolean canApplyTo(FunctionCompilationContext context, ComputationTarget target) {
    return ObjectUtils.equals(target, _target);
  }

  @Override
  public Set<ValueRequirement> getRequirements(FunctionCompilationContext context, ComputationTarget target) {
    return _requirements;
  }

  @Override
  public Set<ValueSpecification> getResults(FunctionCompilationContext context, ComputationTarget target) {
    return _resultSpecs;
  }

  @Override
  public String getShortName() {
    return "Fn for " + _target;
  }

  @Override
  public ComputationTargetType getTargetType() {
    return _target.getType();
  }

  @Override
  public Set<ComputedValue> execute(FunctionExecutionContext executionContext, FunctionInputs inputs,
      ComputationTarget target, Set<ValueRequirement> desiredValues) {
    Set<ComputedValue> results = new HashSet<ComputedValue>();
    for (ComputedValue result : _results) {
      if(desiredValues.contains(result.getSpecification().getRequirementSpecification())) {
        results.add(result);
      }
    }
    return results;
  }

}<commit_msg>[DVI-34] Checkstyle fixes for c.og.engine unit tests.<commit_after>/**
 * Copyright (C) 2009 - 2010 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.engine.function;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.ObjectUtils;

import com.opengamma.engine.ComputationTarget;
import com.opengamma.engine.ComputationTargetType;
import com.opengamma.engine.value.ComputedValue;
import com.opengamma.engine.value.ValueRequirement;
import com.opengamma.engine.value.ValueSpecification;

/**
 * A function suitable for use in mock environments.
 *
 */
public class MockFunction extends AbstractFunction implements FunctionInvoker {
  private final ComputationTarget _target;
  private final Set<ValueRequirement> _requirements = new HashSet<ValueRequirement>();
  private final Set<ValueSpecification> _resultSpecs = new HashSet<ValueSpecification>();
  private final Set<ComputedValue> _results = new HashSet<ComputedValue>();
  
  public MockFunction(ComputationTarget target) {
    this(target, Collections.<ValueRequirement>emptySet(), Collections.<ComputedValue>emptySet());
  }

  public MockFunction(ComputationTarget target, Collection<ValueRequirement> requirements, Collection<ComputedValue> results) {
    _target = target;
    _requirements.addAll(requirements);
    _results.addAll(results);
    for (ComputedValue result : _results) {
      _resultSpecs.add(result.getSpecification());
    }
  }

  @Override
  public boolean canApplyTo(FunctionCompilationContext context, ComputationTarget target) {
    return ObjectUtils.equals(target, _target);
  }

  @Override
  public Set<ValueRequirement> getRequirements(FunctionCompilationContext context, ComputationTarget target) {
    return _requirements;
  }

  @Override
  public Set<ValueSpecification> getResults(FunctionCompilationContext context, ComputationTarget target) {
    return _resultSpecs;
  }

  @Override
  public String getShortName() {
    return "Fn for " + _target;
  }

  @Override
  public ComputationTargetType getTargetType() {
    return _target.getType();
  }

  @Override
  public Set<ComputedValue> execute(FunctionExecutionContext executionContext, FunctionInputs inputs,
      ComputationTarget target, Set<ValueRequirement> desiredValues) {
    Set<ComputedValue> results = new HashSet<ComputedValue>();
    for (ComputedValue result : _results) {
      if (desiredValues.contains(result.getSpecification().getRequirementSpecification())) {
        results.add(result);
      }
    }
    return results;
  }

}
{'fraction_non_alphanumeric': 0.09165867689357622, 'fraction_numerical': 0.0034515819750719078, 'mean_word_length': 5.136470588235294, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '934648', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1428, 'n_words': 325}