<commit_before>/*
 * Copyright 2006-2021 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MZmine; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

package io.github.mzmine.project.parameterssetup;

import static io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes.DATETIME;
import static io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes.DOUBLE;
import static io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes.TEXT;

import io.github.mzmine.datamodel.RawDataFile;
import io.github.mzmine.main.MZmineCore;
import io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes;
import io.github.mzmine.project.parameterssetup.columns.DateMetadataColumn;
import io.github.mzmine.project.parameterssetup.columns.DoubleMetadataColumn;
import io.github.mzmine.project.parameterssetup.columns.MetadataColumn;
import io.github.mzmine.project.parameterssetup.columns.StringMetadataColumn;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Holds the metadata of a project and represents it as a table (parameters are columns).
 */
public class MetadataTable {

  private final Map<MetadataColumn<?>, Map<RawDataFile, Object>> data;

  // define the header fields names of the file with imported metadata
  private enum HeaderFields {
    NAME, DESC, TYPE, FILE, VALUE
  }

  // we will need HeaderFields enum converted into array
  private final String[] HeaderFieldsArr = Stream.of(HeaderFields.values()).map(Enum::toString)
      .toArray(String[]::new);

  private final Logger logger = Logger.getLogger(this.getClass().getName());

  public MetadataTable() {
    this.data = new HashMap<>();
  }

  public MetadataTable(Map<MetadataColumn<?>, Map<RawDataFile, Object>> data) {
    this.data = data;
  }

  public Map<MetadataColumn<?>, Map<RawDataFile, Object>> getData() {
    return data;
  }

  /**
   * Clear the metadata table up.
   */
  public void clearData() {
    data.clear();
  }

  /**
   * Add new parameter column to the metadata table.
   *
   * @param column new parameter column
   */
  public void addColumn(MetadataColumn<?> column) {
    data.putIfAbsent(column, new HashMap<>());
  }

  /**<commit_msg>Logger must be used as a static variable;<commit_after>/*
 * Copyright 2006-2021 The MZmine Development Team
 *
 * This file is part of MZmine.
 *
 * MZmine is free software; you can redistribute it and/or modify it under the terms of the GNU
 * General Public License as published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * MZmine is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with MZmine; if not,
 * write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

package io.github.mzmine.project.parameterssetup;

import static io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes.DATETIME;
import static io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes.DOUBLE;
import static io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes.TEXT;

import io.github.mzmine.datamodel.RawDataFile;
import io.github.mzmine.main.MZmineCore;
import io.github.mzmine.project.parameterssetup.ProjectMetadataParameters.AvailableTypes;
import io.github.mzmine.project.parameterssetup.columns.DateMetadataColumn;
import io.github.mzmine.project.parameterssetup.columns.DoubleMetadataColumn;
import io.github.mzmine.project.parameterssetup.columns.MetadataColumn;
import io.github.mzmine.project.parameterssetup.columns.StringMetadataColumn;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Holds the metadata of a project and represents it as a table (parameters are columns).
 */
public class MetadataTable {

  private final Map<MetadataColumn<?>, Map<RawDataFile, Object>> data;

  // define the header fields names of the file with imported metadata
  private enum HeaderFields {
    NAME, DESC, TYPE, FILE, VALUE
  }

  // we will need HeaderFields enum converted into array
  private final String[] HeaderFieldsArr = Stream.of(HeaderFields.values()).map(Enum::toString)
      .toArray(String[]::new);

  private static final Logger logger = Logger.getLogger(MetadataTable.class.getName());

  public MetadataTable() {
    this.data = new HashMap<>();
  }

  public MetadataTable(Map<MetadataColumn<?>, Map<RawDataFile, Object>> data) {
    this.data = data;
  }

  public Map<MetadataColumn<?>, Map<RawDataFile, Object>> getData() {
    return data;
  }

  /**
   * Clear the metadata table up.
   */
  public void clearData() {
    data.clear();
  }

  /**
   * Add new parameter column to the metadata table.
   *
   * @param column new parameter column
   */
  public void addColumn(MetadataColumn<?> column) {
    data.putIfAbsent(column, new HashMap<>());
  }

  /**
{'fraction_non_alphanumeric': 0.09572363415005326, 'fraction_numerical': 0.0060873535230558514, 'mean_word_length': 4.564775613886537, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '18735', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1826, 'n_words': 584}