<commit_before>/*
Copyright 2016 the original author or authors.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   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.
*/
package de.hs.mannheim.modUro.creator;

import de.hs.mannheim.modUro.model.ModelType;
import de.hs.mannheim.modUro.model.Node;
import de.hs.mannheim.modUro.model.Project;
import de.hs.mannheim.modUro.model.dialog.SettingFile;
import de.hs.mannheim.modUro.config.RegEx;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * ProjectCreator helps to create a Project by passing a SettingFile.
 *
 * @author <NAME> (<EMAIL>)
 */
public class ProjectCreator {

    //SettingFile for a Project with Nodes
    SettingFile settingFile;

    //Project Instance
    private Project project;

    /**
     * Constructor.
     */
    public ProjectCreator() {
    }

    /**
     * Creates name of the project.
     *
     * @return
     */
    private String createProjectName() {
        String name = settingFile.getName();
        return name;
    }

    /**
     * Creates List of Nodes of a project.
     *
     * @return
     */
    private List<Node> createNodeList() {
        List<Node> nodeList = settingFile.getNode();

        return nodeList;
    }

    /**
     * Creates List of ModelTypes.
     *
     * @return
     */
    private List<ModelType> createModelTypeList() {
        ModelType modelType;
        List<ModelType> modelTypeList = new ArrayList<>();
        ModelTypeCreator modelTypeCreator = new ModelTypeCreator();

        List<String> modelTypeName = getAllModelTypeName();
        List<File> allDir = listAllDirInAllNodes();
        List<File> dirList = new ArrayList<>();

        for (String name : modelTypeName) {
            for (File file : allDir) {
                if (file.getName().contains(name + "_")) {
                    dirList.add(file);
                }
            }
            modelTypeCreator.setFileList(dirList);
            modelTypeCreator.createModelType();
            modelType = modelTypeCreator.getModelType();
            modelTypeList.add(modelType);
            dirList.clear();
        }
        return modelTypeList;
    }

    /**
     * Lists all file in all nodes.
     *
     * @return
     */
    private List<File> listAllDirInAllNodes() {
        List<File> allDir = new ArrayList<>();

        for (Node node : settingFile.getNode()) {
            File[] dirs = node.getPath().listFiles(f -> f.isDirectory());
            for (File file : dirs) {
                allDir.add(file);
            }
        }

        return allDir;
    }

    /**
     * Create List with modeltype name.
     *
     * @return
     */
    private List<String> getAllModelTypeName() {
        List<String> modelTypeNameList = new ArrayList<>();

        for (Node node : settingFile.getNode()) {
            File[] dirs = node.getPath().listFiles(f -> f.isDirectory());
            for (File file : dirs) {
                String name;
                String[] tokenValue = file.getName().split(RegEx.MODEL_TYPE_REG_EX.getName());
                name = tokenValue[0];

                if (!modelTypeNameList.contains(name) && name.length() > 0) {
                    modelTypeNameList.add(name);
                }
            }
        }

        return modelTypeNameList;
    }

    public void createProject() {
        project = new Project(createProjectName(), createNodeList(), createModelTypeList());
    }

    public Project getProject() {
        return project;
    }

    public void setSettingFile(SettingFile settingFile) {
        this.settingFile = settingFile;
    }
}
<commit_msg>Bug fix: No more duplicate projects in tree view (was in the past only partially solved).<commit_after>/*
Copyright 2016 the original author or authors.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   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.
*/
package de.hs.mannheim.modUro.creator;

import de.hs.mannheim.modUro.model.ModelType;
import de.hs.mannheim.modUro.model.Node;
import de.hs.mannheim.modUro.model.Project;
import de.hs.mannheim.modUro.model.dialog.SettingFile;
import de.hs.mannheim.modUro.config.RegEx;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * ProjectCreator helps to create a Project by passing a SettingFile.
 *
 * @author <NAME> (<EMAIL>)
 */
public class ProjectCreator {

    //SettingFile for a Project with Nodes
    SettingFile settingFile;

    //Project Instance
    private Project project;

    /**
     * Constructor.
     */
    public ProjectCreator() {
    }

    /**
     * Creates name of the project.
     *
     * @return
     */
    private String createProjectName() {
        String name = settingFile.getName();
        return name;
    }

    /**
     * Creates List of Nodes of a project.
     *
     * @return
     */
    private List<Node> createNodeList() {
        List<Node> nodeList = settingFile.getNode();

        return nodeList;
    }

    /**
     * Creates List of ModelTypes.
     *
     * @return
     */
    private List<ModelType> createModelTypeList() {
        ModelType modelType;
        List<ModelType> modelTypeList = new ArrayList<>();
        ModelTypeCreator modelTypeCreator = new ModelTypeCreator();

        List<String> modelTypeName = getAllModelTypeName();
        List<File> allDir = listAllDirInAllNodes();
        List<File> dirList = new ArrayList<>();

        for (String name : modelTypeName) {
            for (File file : allDir) {
                if (file.getName().startsWith(name + "_")) {
                    dirList.add(file);
                }
            }
            modelTypeCreator.setFileList(dirList);
            modelTypeCreator.createModelType();
            modelType = modelTypeCreator.getModelType();
            modelTypeList.add(modelType);
            dirList.clear();
        }
        return modelTypeList;
    }

    /**
     * Lists all file in all nodes.
     *
     * @return
     */
    private List<File> listAllDirInAllNodes() {
        List<File> allDir = new ArrayList<>();

        for (Node node : settingFile.getNode()) {
            File[] dirs = node.getPath().listFiles(f -> f.isDirectory());
            for (File file : dirs) {
                allDir.add(file);
            }
        }

        return allDir;
    }

    /**
     * Create List with modeltype name.
     *
     * @return
     */
    private List<String> getAllModelTypeName() {
        List<String> modelTypeNameList = new ArrayList<>();

        for (Node node : settingFile.getNode()) {
            File[] dirs = node.getPath().listFiles(f -> f.isDirectory());
            for (File file : dirs) {
                String name;
                String[] tokenValue = file.getName().split(RegEx.MODEL_TYPE_REG_EX.getName());
                name = tokenValue[0];

                if (!modelTypeNameList.contains(name) && name.length() > 0) {
                    modelTypeNameList.add(name);
                }
            }
        }

        return modelTypeNameList;
    }

    public void createProject() {
        project = new Project(createProjectName(), createNodeList(), createModelTypeList());
    }

    public Project getProject() {
        return project;
    }

    public void setSettingFile(SettingFile settingFile) {
        this.settingFile = settingFile;
    }
}

{'fraction_non_alphanumeric': 0.10440891472868218, 'fraction_numerical': 0.0024224806201550387, 'mean_word_length': 2.1527300496372663, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2142301', 'n_tokens_mistral': 2325, 'n_tokens_neox': 2260, 'n_words': 615}