<commit_before>//////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016, <NAME> - All Rights Reserved                /
//                                                                                       /
// Licensed under the GNU General Public License v3;                                     /
// you may not use this file except in compliance with the License.                      /
//                                                                                       /
// You may obtain a copy of the License at                                               /
//     http://www.gnu.org/licenses/gpl.html                                              /
//                                                                                       /
// Unless required by applicable law or agreed to in writing, software                   /
// distributed under the License is distributed on an "AS IS" BASIS,                     /
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.              /
// See the License for the specific language governing permissions and                   /
// limitations under the License.                                                        /
//                                                                                       /
// Written by <NAME> <<EMAIL>>, March 2016           /
// https://www.github.com/BloodShura                                                     /
//////////////////////////////////////////////////////////////////////////////////////////

package br.shura.venus.component.function;

import br.shura.venus.component.Container;
import br.shura.venus.exception.ScriptRuntimeException;
import br.shura.venus.executor.Context;
import br.shura.venus.executor.VenusExecutor;
import br.shura.venus.value.Value;
import br.shura.venus.value.ValueType;
import br.shura.x.collection.list.List;
import br.shura.x.collection.view.BasicView;
import br.shura.x.collection.view.View;

/**
 * Definition.java
 *
 * @author <a href="https://www.github.com/BloodShura">BloodShura</a> (<NAME>)
 * @contact <EMAIL>
 * @date 06/05/16 - 15:34
 * @since GAMMA - 0x3
 */
public final class Definition extends Container implements Function {
  private final List<Argument> arguments;
  private final String name;

  public Definition(String name, List<Argument> arguments) {
    this.arguments = arguments;
    this.name = name;
  }

  @Override
  public Value call(Context context, Value... arguments) throws ScriptRuntimeException {
    return VenusExecutor.run(this); // What about the context argument?
  }

  @Override
  public int getArgumentCount() { // Default impl. of getArgumentCount() calls getArgumentTypes(), but our impl. is expensive
    return arguments.size();
  }

  @Override
  public View<ValueType> getArgumentTypes() {
    return getArguments().reduce(Argument::getType);<commit_msg>Implemented context population of arguments in Definition class<commit_after>//////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016, <NAME> - All Rights Reserved                /
//                                                                                       /
// Licensed under the GNU General Public License v3;                                     /
// you may not use this file except in compliance with the License.                      /
//                                                                                       /
// You may obtain a copy of the License at                                               /
//     http://www.gnu.org/licenses/gpl.html                                              /
//                                                                                       /
// Unless required by applicable law or agreed to in writing, software                   /
// distributed under the License is distributed on an "AS IS" BASIS,                     /
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.              /
// See the License for the specific language governing permissions and                   /
// limitations under the License.                                                        /
//                                                                                       /
// Written by <NAME> <<EMAIL>>, March 2016           /
// https://www.github.com/BloodShura                                                     /
//////////////////////////////////////////////////////////////////////////////////////////

package br.shura.venus.component.function;

import br.shura.venus.component.Container;
import br.shura.venus.exception.ScriptRuntimeException;
import br.shura.venus.executor.Context;
import br.shura.venus.executor.VenusExecutor;
import br.shura.venus.value.Value;
import br.shura.venus.value.ValueType;
import br.shura.x.collection.list.List;
import br.shura.x.collection.view.BasicView;
import br.shura.x.collection.view.View;

/**
 * Definition.java
 *
 * @author <a href="https://www.github.com/BloodShura">BloodShura</a> (<NAME>)
 * @contact <EMAIL>
 * @date 06/05/16 - 15:34
 * @since GAMMA - 0x3
 */
public final class Definition extends Container implements Function {
  private final List<Argument> arguments;
  private final String name;

  public Definition(String name, List<Argument> arguments) {
    this.arguments = arguments;
    this.name = name;
  }

  @Override
  public Value call(Context context, Value... arguments) throws ScriptRuntimeException {
    int i = 0;

    for (Argument argument : getArguments()) {
      context.setVar(argument.getName(), arguments[i++]);
    }

    return VenusExecutor.run(this);
  }

  @Override
  public int getArgumentCount() { // Default impl. of getArgumentCount() calls getArgumentTypes(), but our impl. is expensive
    return arguments.size();
  }

  @Override
  public View<ValueType> getArgumentTypes() {
    return getArguments().reduce(Argument::getType);
{'fraction_non_alphanumeric': 0.14499501163950781, 'fraction_numerical': 0.007149983372131693, 'mean_word_length': 1.2604284103720407, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1884588', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1250, 'n_words': 388}