<commit_before>package org.flymine.metadata;

/*
 * Copyright (C) 2002-2003 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 org.flymine.util.Util;

/**
 * Describes a field that references a collection of other objects.
 * getReverseReferenceDescriptor()
 * allows one ot work out the multiplicity of the association's other end.
 *
 * @author <NAME>
 */

public class CollectionDescriptor extends ReferenceDescriptor
{
    protected final boolean ordered;
    private boolean setReverseRef = false;
    protected final Class collectionClass;

    /**
     * Construct a CollectionDescriptor.  name and referencedType may not be null.
     * @param name name of this field in parent class
     * @param primaryKey is this field part of the primary key
     * @param referencedType the fully qualified name of the business object type in this collection
     * @param reverseRefName name of field in the referenced class that points back to this class
     *                       (may be null)
     * @param ordered true if the collection ordered
     * @throws IllegalArgumentException if arguments are null
     */
    public CollectionDescriptor(String name, boolean primaryKey, String referencedType,
                                   String reverseRefName, boolean ordered) {
        // should define type of collection properly somehow
        super(name, primaryKey, referencedType, reverseRefName);
        this.ordered = ordered;
        if (ordered) {
            collectionClass = java.util.ArrayList.class;
        } else {
            collectionClass = java.util.HashSet.class;
        }
    }

    /**
     * Returns a ClassDescriptor for the type of object contained in this collection.
     * @return ClassDescriptor for the type of object contained within the collection
     * @throws IllegalStateException if the model is not yet set
     */
    public ClassDescriptor getReferencedClassDescriptor() throws IllegalStateException {
        return super.getReferencedClassDescriptor();
    }

    /**
     * Gets the field in the referenced object (i.e. objects in the collection) that
     * refers back to this class.  Note that this will be null in a unidirectional
     * relationship, a ReferenceDescriptor in a N:1 and a CollectionDescriptor in a M:N.
     * @return a FieldDescriptor referring back to this class.
     * @throws IllegalStateException if the model is not yet set
     */
    public ReferenceDescriptor getReverseReferenceDescriptor() throws IllegalStateException {
        return super.getReverseReferenceDescriptor();
    }


    /**
     * Get the class of collection this field represents
     * @return the type of collection
     */
    public Class getCollectionClass() {
        return this.collectionClass;
    }

    /**
     * True if the collection is ordered.
     * @return true if the collection is ordered
     */
    public boolean isOrdered() {
        return ordered;
    }
    
    /**
     * @see FieldDescriptor#relationType
     */
    public int relationType() {
        ReferenceDescriptor rd = getReverseReferenceDescriptor();
        if (rd == null || rd instanceof CollectionDescriptor) {
            return M_N_RELATION;
        } else {
            return ONE_N_RELATION;
        } 
    }

    /**
     * @see Object#equals
     */
    public boolean equals(Object obj) {
        if (obj instanceof CollectionDescriptor) {
            CollectionDescriptor ref = (CollectionDescriptor) obj;
            return name.equals(ref.name)
                && primaryKey == ref.primaryKey
                && referencedType.equals(ref.referencedType)
                && Util.equals(reverseRefName, ref.reverseRefName)
                && ordered == ref.ordered;
        }
        return false;
    }

    /**
     * @see Object#hashCode
     */
    public int hashCode() {
        return 3 * name.hashCode()
            + 5 * (primaryKey ? 1 : 0)
            + 7 * referencedType.hashCode()
            + 11 * Util.hashCode(reverseRefName)
            + 13 * (ordered ? 1 : 0);
    }

    /**
     * @see Object#toString
     */
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("<collection name=\"" + name + "\" referenced-type=\"" + referencedType + "\"")
            .append(" ordered=\"" + ordered + "\"")
            .append(reverseRefName != null ? " reverse-reference=\"" + reverseRefName + "\"" : "")
            .append(" primary-key=\"" + primaryKey + "\"/>");
        return sb.toString();
    }
}<commit_msg>ensure that identical CollectionDescriptors with different parent ClassDescriptors are not .equals()<commit_after>package org.flymine.metadata;

/*
 * Copyright (C) 2002-2003 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 org.flymine.util.Util;

/**
 * Describes a field that references a collection of other objects.
 * getReverseReferenceDescriptor()
 * allows one ot work out the multiplicity of the association's other end.
 *
 * @author <NAME>
 */

public class CollectionDescriptor extends ReferenceDescriptor
{
    protected final boolean ordered;
    private boolean setReverseRef = false;
    protected final Class collectionClass;

    /**
     * Construct a CollectionDescriptor.  name and referencedType may not be null.
     * @param name name of this field in parent class
     * @param primaryKey is this field part of the primary key
     * @param referencedType the fully qualified name of the business object type in this collection
     * @param reverseRefName name of field in the referenced class that points back to this class
     *                       (may be null)
     * @param ordered true if the collection ordered
     * @throws IllegalArgumentException if arguments are null
     */
    public CollectionDescriptor(String name, boolean primaryKey, String referencedType,
                                   String reverseRefName, boolean ordered) {
        // should define type of collection properly somehow
        super(name, primaryKey, referencedType, reverseRefName);
        this.ordered = ordered;
        if (ordered) {
            collectionClass = java.util.ArrayList.class;
        } else {
            collectionClass = java.util.HashSet.class;
        }
    }

    /**
     * Returns a ClassDescriptor for the type of object contained in this collection.
     * @return ClassDescriptor for the type of object contained within the collection
     * @throws IllegalStateException if the model is not yet set
     */
    public ClassDescriptor getReferencedClassDescriptor() throws IllegalStateException {
        return super.getReferencedClassDescriptor();
    }

    /**
     * Gets the field in the referenced object (i.e. objects in the collection) that
     * refers back to this class.  Note that this will be null in a unidirectional
     * relationship, a ReferenceDescriptor in a N:1 and a CollectionDescriptor in a M:N.
     * @return a FieldDescriptor referring back to this class.
     * @throws IllegalStateException if the model is not yet set
     */
    public ReferenceDescriptor getReverseReferenceDescriptor() throws IllegalStateException {
        return super.getReverseReferenceDescriptor();
    }


    /**
     * Get the class of collection this field represents
     * @return the type of collection
     */
    public Class getCollectionClass() {
        return this.collectionClass;
    }

    /**
     * True if the collection is ordered.
     * @return true if the collection is ordered
     */
    public boolean isOrdered() {
        return ordered;
    }
    
    /**
     * @see FieldDescriptor#relationType
     */
    public int relationType() {
        ReferenceDescriptor rd = getReverseReferenceDescriptor();
        if (rd == null || rd instanceof CollectionDescriptor) {
            return M_N_RELATION;
        } else {
            return ONE_N_RELATION;
        } 
    }

    /**
     * @see Object#equals
     */
    public boolean equals(Object obj) {
        if (obj instanceof CollectionDescriptor) {
            CollectionDescriptor ref = (CollectionDescriptor) obj;
            return (cld == null || cld.getClassName().equals(ref.cld.getClassName()))
                && name.equals(ref.name)
                && primaryKey == ref.primaryKey
                && referencedType.equals(ref.referencedType)
                && Util.equals(reverseRefName, ref.reverseRefName)
                && ordered == ref.ordered;
        }
        return false;
    }

    /**
     * @see Object#hashCode
     */
    public int hashCode() {
        return 2 * (cld == null ? 0 : cld.getClassName().hashCode())
            + 3 * name.hashCode()
            + 5 * (primaryKey ? 1 : 0)
            + 7 * referencedType.hashCode()
            + 11 * Util.hashCode(reverseRefName)
            + 13 * (ordered ? 1 : 0);
    }

    /**
     * @see Object#toString
     */
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("<collection name=\"" + name + "\" referenced-type=\"" + referencedType + "\"")
            .append(" ordered=\"" + ordered + "\"")
            .append(reverseRefName != null ? " reverse-reference=\"" + reverseRefName + "\"" : "")
            .append(" primary-key=\"" + primaryKey + "\"/>");
        return sb.toString();
    }
}
{'fraction_non_alphanumeric': 0.08734476034075747, 'fraction_numerical': 0.00431078723185877, 'mean_word_length': 2.378640776699029, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2276861', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2366, 'n_words': 852}