<commit_before>package etomica;

import etomica.atom.AtomPositionDefinition;
import etomica.nbr.NeighborManagerAgent;
import etomica.utility.Arrays;

//import etomica.electrostatics.*;

/**
 * AtomType holds fields that are common to many atoms. It serves many
 * functions:
 * <ul>
 * <li>it holds parameters that define the general features of the atom (e.g.,
 * size).
 * <li>it holds an index manager that is used to interpret the atom's index
 * held in its node
 * <li>it holds a class used to manage neighbors, by indicating which
 * potentials apply to the atom
 * </ul>
 * The AtomType of an atom is set by its AtomFactory when it builds a molecule.
 * Each Atom has an instance variable named "type" that holds the AtomType
 * instance. <br>
 * AtomType instances are arranged in a hierarchy that parallels the species
 * hierarchy. The AtomType of an atom group will be an instance of
 * AtomTypeGroup, and will have a set of child types that are the types of the
 * child atoms of the atom group. Whereas an atom group may have more than one
 * child of a given type, an AtomTypeGroup will have the AtomType for those
 * atoms represented only once.
 */

public abstract class AtomType implements java.io.Serializable, Comparable {

    public static Parameter.Source[] parameterSource = new Parameter.Source[0];
    AtomFactory creator;//set in constructor of AtomFactory
    public Parameter[] parameter;
    protected int speciesIndex = -1;
    private Species species;

    //fields for linked list of all instances of AtomType
    public final AtomType previousInstance;
    private static AtomType lastInstance;

    private final NeighborManagerAgent neighborManagerAgent;

    private final AtomIndexManager indexManager;
    private AtomPositionDefinition positionDefinition;

    private AtomTypeGroup parentType;

    //    private Parameter.Electrostatic electroParameter;

    /**
     * Used only to create root type.
     */
    AtomType(AtomIndexManager indexManager) {
        parentType = null;
        this.indexManager = indexManager;
        positionDefinition = null;
        previousInstance = null;
        neighborManagerAgent = null;
    }

    /**
     * Primary constructor called by subclasses to make the instance.
     * 
     * @param parentType
     *            the instance of the AtomType that is the parent of this in the
     *            AtomType hierarchy. This constructor adds this instance to the
     *            list of child types of the given parent (if not null, which is
     *            permitted and may arise if working outside the species tree
     *            hierarchy)
     * @param positionDefinition
     *            used by many classes as default choice for defining the
     *            spatial position of an instance of an atom(group) of this type
     */
    public AtomType(AtomTypeGroup parentType,
            AtomPositionDefinition positionDefinition) {
        this.parentType = parentType;
        if (parentType == null) {
            indexManager = AtomIndexManager
                    .makeSimpleIndexManager(Default.BIT_LENGTH);
        } else {
            indexManager = parentType.getIndexManager().makeChildManager();
            parentType.childTypes = (AtomType[]) Arrays.addObject(
                    parentType.childTypes, this);
        }
        this.positionDefinition = positionDefinition;

        //update linked list of instances
        this.previousInstance = lastInstance;
        lastInstance = this;

        //set up global parameters
        parameter = new Parameter[parameterSource.length];
        for (int i = 0; i < parameter.length; i++) {
            parameter[i] = parameterSource[i].makeParameter();
        }

        //        System.out.println("AtomType constructor:"+mass);
        neighborManagerAgent = new NeighborManagerAgent();
    }

    /**
     * Indicates whether this type is at the bottom of the AtomType hierarchy.
     * 
     * @return true if this type is an instance of AtomTypeLeaf
     */
    public abstract boolean isLeaf();

    /**
     * Returns the parent AtomType of this AtomType.
     */
    public AtomType getParentType() {
        return parentType;
    }

    /**
     * Returns the index manager used to set and interpret the 
     * index of an atom of this type.
     */
    public AtomIndexManager getIndexManager() {
        return indexManager;
    }

    /**
     * Implementation of Comparable interface, based on type index value.  <commit_msg>give AtomType instances an index that can be used to references array objects<commit_after>package etomica;

import etomica.atom.AtomPositionDefinition;
import etomica.nbr.NeighborManagerAgent;
import etomica.utility.Arrays;

//import etomica.electrostatics.*;

/**
 * AtomType holds fields that are common to many atoms. It serves many
 * functions:
 * <ul>
 * <li>it holds parameters that define the general features of the atom (e.g.,
 * size).
 * <li>it holds an index manager that is used to interpret the atom's index
 * held in its node
 * <li>it holds a class used to manage neighbors, by indicating which
 * potentials apply to the atom
 * </ul>
 * The AtomType of an atom is set by its AtomFactory when it builds a molecule.
 * Each Atom has an instance variable named "type" that holds the AtomType
 * instance. <br>
 * AtomType instances are arranged in a hierarchy that parallels the species
 * hierarchy. The AtomType of an atom group will be an instance of
 * AtomTypeGroup, and will have a set of child types that are the types of the
 * child atoms of the atom group. Whereas an atom group may have more than one
 * child of a given type, an AtomTypeGroup will have the AtomType for those
 * atoms represented only once.
 */

public abstract class AtomType implements java.io.Serializable, Comparable {

    public static Parameter.Source[] parameterSource = new Parameter.Source[0];
    AtomFactory creator;//set in constructor of AtomFactory
    public Parameter[] parameter;
    protected int speciesIndex = -1;
    private Species species;
    private int index;

    //fields for linked list of all instances of AtomType
    public final AtomType previousInstance;
    private static AtomType lastInstance;

    private final NeighborManagerAgent neighborManagerAgent;

    private final AtomIndexManager indexManager;
    private AtomPositionDefinition positionDefinition;

    private AtomTypeGroup parentType;

    //    private Parameter.Electrostatic electroParameter;

    /**
     * Used only to create root type.
     */
    AtomType(AtomIndexManager indexManager) {
        parentType = null;
        this.indexManager = indexManager;
        positionDefinition = null;
        previousInstance = null;
        neighborManagerAgent = null;
        index = 0;
    }

    /**
     * Primary constructor called by subclasses to make the instance.
     * 
     * @param parentType
     *            the instance of the AtomType that is the parent of this in the
     *            AtomType hierarchy. This constructor adds this instance to the
     *            list of child types of the given parent (if not null, which is
     *            permitted and may arise if working outside the species tree
     *            hierarchy)
     * @param positionDefinition
     *            used by many classes as default choice for defining the
     *            spatial position of an instance of an atom(group) of this type
     */
    public AtomType(AtomTypeGroup parentType,
            AtomPositionDefinition positionDefinition) {
        this.parentType = parentType;
        if (parentType == null) {
            indexManager = AtomIndexManager
                    .makeSimpleIndexManager(Default.BIT_LENGTH);
            index = 0;
        } else {
            indexManager = parentType.getIndexManager().makeChildManager();
            parentType.childTypes = (AtomType[]) Arrays.addObject(
                    parentType.childTypes, this);
            index = requestIndex();
        }
        this.positionDefinition = positionDefinition;

        //update linked list of instances
        this.previousInstance = lastInstance;
        lastInstance = this;

        //set up global parameters
        parameter = new Parameter[parameterSource.length];
        for (int i = 0; i < parameter.length; i++) {
            parameter[i] = parameterSource[i].makeParameter();
        }

        //        System.out.println("AtomType constructor:"+mass);
        neighborManagerAgent = new NeighborManagerAgent();
    }
    
    public int getIndex() {
        return index;
    }
    
    private int requestIndex() {
        if(parentType == null) return index++;
        return ((AtomType)parentType).requestIndex();
    }

    /**
     * Indicates whether this type is at the bottom of the AtomType hierarchy.
     * 
     * @return true if this type is an instance of AtomTypeLeaf
     */
    public abstract boolean isLeaf();

    /**
     * Returns the parent AtomType of this AtomType.
     */
    public AtomType getParentType() {
        return parentType;
    }

    /**
     * Returns the index manager used to set and interpret the 
     * index of an atom of this type.
     */
    public AtomIndexManager getIndexManager() {
        return indexManager;
    }

    /**
     * Implementation of Comparable interface, based on type index value.  
{'fraction_non_alphanumeric': 0.06609898882384246, 'fraction_numerical': 0.0008515167642362959, 'mean_word_length': 2.5848912628767646, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3179367', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2330, 'n_words': 941}