<commit_before>package org.intermine.metadata;

/*
 * Copyright (C) 2002-2010 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;
import java.math.BigDecimal;

import org.intermine.model.InterMineObject;
import org.intermine.modelproduction.MetadataManager;
import org.intermine.util.TypeUtil;

/**
 * Represents a named business model, makes available metadata for each class
 * within model.
 *
 * @author <NAME>
 */
public class Model
{
    private static Map<String, Model> models = new HashMap<String, Model>();

    private final String modelName;
    private final String packageName;
    private final Map<String, ClassDescriptor> cldMap = new LinkedHashMap<String,
            ClassDescriptor>();
    private final Map<ClassDescriptor, Set<ClassDescriptor>> subMap
        = new LinkedHashMap<ClassDescriptor, Set<ClassDescriptor>>();
    private final Map<Class, Set<ClassDescriptor>> classToClassDescriptorSet
        = new HashMap<Class, Set<ClassDescriptor>>();
    private final Map<Class, Map<String, FieldDescriptor>> classToFieldDescriptorMap
        = new HashMap<Class, Map<String, FieldDescriptor>>();
    private final Map<Class, Map<String, Class>> classToCollectionsMap
        = new HashMap<Class, Map<String, Class>>();

    private boolean generatedClassesAvailable = true;

    /**
     * Return a Model for specified model name (loading Model if necessary)
     * @param name the name of the model
     * @return the relevant metadata
     */
    public static Model getInstanceByName(String name) {
        if (!models.containsKey(name)) {
            models.put(name, MetadataManager.loadModel(name));
        }
        return models.get(name);
    }

    /**
     * Adds model to known models.
     *
     * @param name the model name
     * @param model the model
     */
    public static void addModel(String name, Model model) {
        models.put(name, model);
    }

    /**
     * Construct a Model with a name and set of ClassDescriptors.  The model will be
     * set to this in each of the ClassDescriptors. NB This method should only be called
     * by members of the modelproduction package, eventually it may be replaced with
     * a static addModel method linked to getInstanceByName.
     *
     * @param name name of model
     * @param packageName the package name of the model
     * @param clds a Set of ClassDescriptors in the model
     * @throws MetaDataException if inconsistencies found in model
     */
    public Model(String name, String packageName,
            Set<ClassDescriptor> clds) throws MetaDataException {
        if (name == null) {
            throw new NullPointerException("Model name cannot be null");
        }
        if (name.equals("")) {
            throw new IllegalArgumentException("Model name cannot be empty");
        }
        if (packageName == null) {
            throw new NullPointerException("Package name cannot be null");
        }
        if (clds == null) {
            throw new NullPointerException("Model ClassDescriptors list cannot be null");
        }

        this.modelName = name;
        this.packageName = packageName;

        LinkedHashSet<ClassDescriptor> orderedClds = new LinkedHashSet<ClassDescriptor>(clds);

        Set<ReferenceDescriptor> emptyRefs = Collections.emptySet();
        Set<CollectionDescriptor> emptyCols = Collections.emptySet();
        ClassDescriptor intermineObject = new ClassDescriptor(
                "org.intermine.model.InterMineObject", null, true,
                Collections.singleton(new AttributeDescriptor("id", "java.lang.Integer")),
                emptyRefs, emptyCols);
        orderedClds.add(intermineObject);

        // 1. Put all ClassDescriptors in model.
        for (ClassDescriptor cld : orderedClds) {
            String cldName = cld.getName();
            int lastDotPos = cldName.lastIndexOf(".");
            String cldPackage = (lastDotPos == -1 ? "" : cldName.substring(0, lastDotPos));
            if ((!"org.intermine.model.InterMineObject".equals(cldName))
                    && (!packageName.equals(cldPackage))) {
                throw new IllegalArgumentException("Class " + cldName + " is not in model package "
                        + packageName);
            }
            cldMap.put(cld.getName(), cld);<commit_msg>added quotes around classnames to make error messages easier to read<commit_after>package org.intermine.metadata;

/*
 * Copyright (C) 2002-2010 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedHashMap;
import java.util.Set;
import java.util.Stack;
import java.util.TreeSet;
import java.math.BigDecimal;

import org.intermine.model.InterMineObject;
import org.intermine.modelproduction.MetadataManager;
import org.intermine.util.TypeUtil;

/**
 * Represents a named business model, makes available metadata for each class
 * within model.
 *
 * @author <NAME>
 */
public class Model
{
    private static Map<String, Model> models = new HashMap<String, Model>();

    private final String modelName;
    private final String packageName;
    private final Map<String, ClassDescriptor> cldMap = new LinkedHashMap<String,
            ClassDescriptor>();
    private final Map<ClassDescriptor, Set<ClassDescriptor>> subMap
        = new LinkedHashMap<ClassDescriptor, Set<ClassDescriptor>>();
    private final Map<Class, Set<ClassDescriptor>> classToClassDescriptorSet
        = new HashMap<Class, Set<ClassDescriptor>>();
    private final Map<Class, Map<String, FieldDescriptor>> classToFieldDescriptorMap
        = new HashMap<Class, Map<String, FieldDescriptor>>();
    private final Map<Class, Map<String, Class>> classToCollectionsMap
        = new HashMap<Class, Map<String, Class>>();

    private boolean generatedClassesAvailable = true;

    /**
     * Return a Model for specified model name (loading Model if necessary)
     * @param name the name of the model
     * @return the relevant metadata
     */
    public static Model getInstanceByName(String name) {
        if (!models.containsKey(name)) {
            models.put(name, MetadataManager.loadModel(name));
        }
        return models.get(name);
    }

    /**
     * Adds model to known models.
     *
     * @param name the model name
     * @param model the model
     */
    public static void addModel(String name, Model model) {
        models.put(name, model);
    }

    /**
     * Construct a Model with a name and set of ClassDescriptors.  The model will be
     * set to this in each of the ClassDescriptors. NB This method should only be called
     * by members of the modelproduction package, eventually it may be replaced with
     * a static addModel method linked to getInstanceByName.
     *
     * @param name name of model
     * @param packageName the package name of the model
     * @param clds a Set of ClassDescriptors in the model
     * @throws MetaDataException if inconsistencies found in model
     */
    public Model(String name, String packageName,
            Set<ClassDescriptor> clds) throws MetaDataException {
        if (name == null) {
            throw new NullPointerException("Model name cannot be null");
        }
        if (name.equals("")) {
            throw new IllegalArgumentException("Model name cannot be empty");
        }
        if (packageName == null) {
            throw new NullPointerException("Package name cannot be null");
        }
        if (clds == null) {
            throw new NullPointerException("Model ClassDescriptors list cannot be null");
        }

        this.modelName = name;
        this.packageName = packageName;

        LinkedHashSet<ClassDescriptor> orderedClds = new LinkedHashSet<ClassDescriptor>(clds);

        Set<ReferenceDescriptor> emptyRefs = Collections.emptySet();
        Set<CollectionDescriptor> emptyCols = Collections.emptySet();
        ClassDescriptor intermineObject = new ClassDescriptor(
                "org.intermine.model.InterMineObject", null, true,
                Collections.singleton(new AttributeDescriptor("id", "java.lang.Integer")),
                emptyRefs, emptyCols);
        orderedClds.add(intermineObject);

        // 1. Put all ClassDescriptors in model.
        for (ClassDescriptor cld : orderedClds) {
            String cldName = cld.getName();
            int lastDotPos = cldName.lastIndexOf(".");
            String cldPackage = (lastDotPos == -1 ? "" : cldName.substring(0, lastDotPos));
            if ((!"org.intermine.model.InterMineObject".equals(cldName))
                    && (!packageName.equals(cldPackage))) {
                throw new IllegalArgumentException("Class `" + cldName + "` is not in model "
                        + "package `" + packageName + "`");
            }
            cldMap.put(cld.getName(), cld);
{'fraction_non_alphanumeric': 0.0933180920710797, 'fraction_numerical': 0.002286189338044269, 'mean_word_length': 2.8853451756156643, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '6345499', 'n_tokens_mistral': 2539, 'n_tokens_neox': 2504, 'n_words': 809}