<commit_before>package org.flymine.metadata;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;

import org.flymine.util.StringUtil;


/**
 * Describe a business model class.  Gives access to attribute, reference and collection
 * descriptors.  Includes primary key information.
 *
 * @author <NAME>
 */


public class ClassDescriptor
{

    private final String name;        // name of this class
    private final String superclassName;
    private final String interfaces;
    private ClassDescriptor superclassDescriptor;
    private List interfaceNames = new ArrayList();
    private final List interfaceDescriptors = new ArrayList();

    private ClassDescriptor ultimateSuperclassDesc;
    private boolean ultimateSuperSet = false;

    private final boolean isInterface;
    private final List attDescriptors;
    private final List refDescriptors;
    private final List colDescriptors;
    private final Map fieldDescriptors = new HashMap();

    private final List pkFields = new ArrayList();
    private Model model;  // set when ClassDesriptor added to DescriptorRespository
    private boolean modelSet = false;
    private List subclassDescriptors;
    private boolean subSet = false;
    private List implementorDescriptors;
    private boolean implSet = false;

    /**
     * Construct a ClassDescriptor.
     * @param name the fully qualified name of the described class
     * @param superclassName the fully qualified super class name if one exists
     * @param interfaces a space string of fully qualified interface names
     * @param isInterface true if describing an interface
     * @param atts a list of AttributeDescriptors
     * @param refs a list of ReferenceDescriptors
     * @param cols a list of CollectionDescriptors
     * @throws IllegalArgumentException if fields are null
     */
    public ClassDescriptor(String name, String superclassName, String interfaces,
                              boolean isInterface, List atts, List refs, List cols)
        throws IllegalArgumentException {

        // must provide class name
        if (name == null || name == "") {
            throw new IllegalArgumentException("'name' parameter must be a valid String");
        }
        this.name = name;
        this.superclassName = superclassName;
        this.interfaces = interfaces;

        // split interface string into a Set
        if (interfaces != null && interfaces != "") {
            interfaceNames = StringUtil.tokenize(interfaces);
        }

        this.isInterface = isInterface;
        this.attDescriptors = atts;
        this.refDescriptors = refs;
        this.colDescriptors = cols;

        // build maps of names to FieldDescriptors and populate pkFields list

        Iterator attIter = attDescriptors.iterator();
        while (attIter.hasNext()) {
            AttributeDescriptor attDesc = (AttributeDescriptor) attIter.next();
            try {
                attDesc.setClassDescriptor(this);
            } catch (IllegalStateException e) {
                throw new IllegalArgumentException("AttributeDescriptor: " + attDesc.getName()
                                                   + "already has ClassDescriptor set.");
            }
            fieldDescriptors.put(attDesc.getName(), attDesc);
            if (attDesc.isPrimaryKey()) {
                this.pkFields.add(attDesc);
            }
        }

        Iterator refIter = refDescriptors.iterator();
        while (refIter.hasNext()) {
            ReferenceDescriptor refDesc = (ReferenceDescriptor) refIter.next();
            try {
                refDesc.setClassDescriptor(this);
            } catch (IllegalStateException e) {
                throw new IllegalArgumentException("ReferenceDescriptor: " + refDesc.getName()
                                                   + "already has ClassDescriptor set.");
            }
            fieldDescriptors.put(refDesc.getName(), refDesc);
            if (refDesc.isPrimaryKey()) {
                this.pkFields.add(refDesc);
            }
        }

        Iterator colIter = colDescriptors.iterator();
        while (colIter.hasNext()) {
            CollectionDescriptor colDesc = (CollectionDescriptor) colIter.next();
            try {
                colDesc.setClassDescriptor(this);
            } catch (IllegalStateException e) {
                throw new IllegalArgumentException("CollectionDescriptor: " + colDesc.getName()<commit_msg>corrected error message<commit_after>package org.flymine.metadata;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;

import org.flymine.util.StringUtil;


/**
 * Describe a business model class.  Gives access to attribute, reference and collection
 * descriptors.  Includes primary key information.
 *
 * @author <NAME>
 */


public class ClassDescriptor
{
    //    protected static final org.apache.log4j.Logger LOG
    //    = org.apache.log4j.Logger.getLogger(ClassDescriptor.class);

    private final String name;        // name of this class
    private final String superclassName;
    private final String interfaces;
    private ClassDescriptor superclassDescriptor;
    private List interfaceNames = new ArrayList();
    private final List interfaceDescriptors = new ArrayList();

    private ClassDescriptor ultimateSuperclassDesc;
    private boolean ultimateSuperSet = false;

    private final boolean isInterface;
    private final List attDescriptors;
    private final List refDescriptors;
    private final List colDescriptors;
    private final Map fieldDescriptors = new HashMap();

    private final List pkFields = new ArrayList();
    private Model model;  // set when ClassDesriptor added to DescriptorRespository
    private boolean modelSet = false;
    private List subclassDescriptors;
    private boolean subSet = false;
    private List implementorDescriptors;
    private boolean implSet = false;

    /**
     * Construct a ClassDescriptor.
     * @param name the fully qualified name of the described class
     * @param superclassName the fully qualified super class name if one exists
     * @param interfaces a space string of fully qualified interface names
     * @param isInterface true if describing an interface
     * @param atts a list of AttributeDescriptors
     * @param refs a list of ReferenceDescriptors
     * @param cols a list of CollectionDescriptors
     * @throws IllegalArgumentException if fields are null
     */
    public ClassDescriptor(String name, String superclassName, String interfaces,
                              boolean isInterface, List atts, List refs, List cols)
        throws IllegalArgumentException {

        // must provide class name
        if (name == null || name == "") {
            throw new IllegalArgumentException("'name' parameter must be a valid String");
        }
        this.name = name;
        //LOG.warn("MODEL: cld: name = " + name);
        this.superclassName = superclassName;
        this.interfaces = interfaces;

        // split interface string into a Set
        if (interfaces != null && interfaces != "") {
            interfaceNames = StringUtil.tokenize(interfaces);
        }

        this.isInterface = isInterface;
        this.attDescriptors = atts;
        this.refDescriptors = refs;
        this.colDescriptors = cols;

        // build maps of names to FieldDescriptors and populate pkFields list

        Iterator attIter = attDescriptors.iterator();
        while (attIter.hasNext()) {
            AttributeDescriptor attDesc = (AttributeDescriptor) attIter.next();
            try {
                attDesc.setClassDescriptor(this);
            } catch (IllegalStateException e) {
                throw new IllegalArgumentException("AttributeDescriptor: " + attDesc.getName()
                                                   + " already has ClassDescriptor ("
                                                   + this.name + ") set.");
            }
            fieldDescriptors.put(attDesc.getName(), attDesc);
            if (attDesc.isPrimaryKey()) {
                this.pkFields.add(attDesc);
            }
        }

        Iterator refIter = refDescriptors.iterator();
        while (refIter.hasNext()) {
            ReferenceDescriptor refDesc = (ReferenceDescriptor) refIter.next();
            try {
                refDesc.setClassDescriptor(this);
            } catch (IllegalStateException e) {
                throw new IllegalArgumentException("ReferenceDescriptor: " + refDesc.getName()
                                                   + "already has ClassDescriptor set.");
            }
            fieldDescriptors.put(refDesc.getName(), refDesc);
            if (refDesc.isPrimaryKey()) {
                this.pkFields.add(refDesc);
            }
        }

        Iterator colIter = colDescriptors.iterator();
        while (colIter.hasNext()) {
            CollectionDescriptor colDesc = (CollectionDescriptor) colIter.next();
            try {
                colDesc.setClassDescriptor(this);
            } catch (IllegalStateException e) {
                throw new IllegalArgumentException("CollectionDescriptor: " + colDesc.getName()
{'fraction_non_alphanumeric': 0.07665768194070081, 'fraction_numerical': 0.00021563342318059299, 'mean_word_length': 2.34149855907781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2767890', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2141, 'n_words': 682}