<commit_before>/*****************************************************************************
 * Source code information
 * -----------------------
 * Original author    <NAME>, HP Labs Bristol
 * Author email       <EMAIL>
 * Package            Jena
 * Created            5 Jan 2001
 * Filename           $RCSfile: OneToManyMap.java,v $
 * Revision           $Revision: 1.5 $
 * Release status     Preview-release $State: Exp $
 *
 * Last modified on   $Date: 2004-06-30 12:58:02 $
 *               by   $Author: chris-dollin $
 *
 * (c) Copyright 2001, 2002, 2003 Hewlett-Packard Development Company, LP
 * See end of file for details
 *****************************************************************************/

// Package
///////////////
package com.hp.hpl.jena.util;


// Imports
///////////////
import java.util.*;



/**
 * An extension to a standard map that supports one-to-many mappings: that is, there
 * may be zero, one or many values corresponding to a given key.
 *
 * @author <NAME>, HP Labs (<a href="mailto:<EMAIL>">email</a>)
 * @version CVS info: $Id: OneToManyMap.java,v 1.5 2004-06-30 12:58:02 chris-dollin Exp $
 */
public class OneToManyMap
    implements Map
{
    // Constants
    //////////////////////////////////


    // Static variables
    //////////////////////////////////


    // Instance variables
    //////////////////////////////////

    /** Encapsulated hash table stores the values */
    private Map m_table = new HashMap();


    // Constructors
    //////////////////////////////////


    // External signature methods
    //////////////////////////////////

    /**
     * Clear all entries from the map.
     */
    public void clear() {
        m_table.clear();
    }


    /**
     * Answer true if the map contains the given value as a key.
     *
     * @param key The key object to test for
     * @return True or false
     */
    public boolean containsKey( Object key ) {
        return m_table.containsKey( key );
    }


    /**
     * Answer true if the map contains the given object as a value
     * stored against any key. Note that this is quite an expensive
     * operation in the current implementation.
     *
     * @param value The value to test for
     * @return True if the value is in the map
     */
    public boolean containsValue( Object value ) {
        for (Iterator values = m_table.values().iterator();  values.hasNext(); ) {
            Object x = values.next();

            if (x == value) {
                return true;
            }
        }

        return false;
    }


    /**
     * Answer a set of the mappings in this map.  Each member of the set will
     * be a Map.Entry value.
     *
     * @return A Set of the mappings as Map.Entry values.
     */
    public Set entrySet() {
        Set s = HashUtils.createSet();

        for (Iterator e0 = m_table.keySet().iterator();  e0.hasNext(); ) {
            Object key = e0.next();
            List values = (List) m_table.get( key );

            // add each key-value pair to the result set
            for (ListIterator e1 = values.listIterator();  e1.hasNext(); ) {
                s.add( new Entry( key, e1.next() ) );
            }
        }

        return s;
    }


    /**
     * Compares the specified object with this map for equality.
     * Returns true if the given object is also a map and the two Maps
     * represent the same mappings. More formally, two maps t1 and t2 represent
     * the same mappings if t1.entrySet().equals(t2.entrySet()).
     *
     * This ensures that the equals method works properly across different
     * implementations of the Map interface.
     *
     * @param o The object to be compared for equality with this map.
     * @return True if the specified object is equal to this map.
     */
    public boolean equals( Object o ) {
        if (o instanceof java.util.Map) {
            return entrySet().equals( ((Map) o).entrySet() );
        }
        else
            return false;
    }


    /**
     * Get a value for this key.  Since this map is explicitly designed to
     * allow there to be more than one mapping per key, this method will return
     * an undetermined instance of the mapping. If no mapping exists, or the
     * selected value is null, null is returned.
     *
     * @param key The key to access the map.
     * @return One of the values this key corresponds to, or null.
     * @see #getAll
     */
    public Object get( Object key ) {
        ArrayList entry = (ArrayList) m_table.get( key );

        if (entry != null) {
            if (!entry.isEmpty()) {
                return entry.get( 0 );
            }
        }

        // not present
        return null;
    }


    /**
     * Answer an iterator over all of the values for the given key.  An iterator
     * is always supplied, even if the key is not present.
     *
     * @param key The key object
     * @return An iterator over all of the values for this key in the map
     */
    public Iterator getAll( Object key ) {
        ArrayList entry = (ArrayList) m_table.get( key );

        if (entry != null) {
            return entry.iterator();
        }
        else {
            return new ArrayList().iterator();
        }
    }


    /**
     * Returns the hash code value for this map. The hash code of a map is
     * defined to be the sum of the hashCodes of each entry in the map's
     * entrySet view. This ensures that t1.equals(t2) implies
     * that t1.hashCode()==t2.hashCode() for any two maps t1 and t2,
     * as required by the general contract of Object.hashCode
     */
    public int hashcode() {
        int hc = 0;

        for (Iterator i = entrySet().iterator();  i.hasNext(); ) {
            hc += i.next().hashCode();
        }

        return hc;
    }


    /**
     * Answer true if the map is empty of key-value mappings.
     *
     * @return True if there are no entries.
     */
    public boolean isEmpty() {
        return m_table.isEmpty();
    }


    /**
     * Answer a set of the keys in this map
     *
     * @return The keys of the map as a Set
     */
    public Set keySet() {
        return m_table.keySet();<commit_msg>Changed hashcode to hashCode to resolve user-reported bug<commit_after>/*****************************************************************************
 * Source code information
 * -----------------------
 * Original author    <NAME>, HP Labs Bristol
 * Author email       <EMAIL>
 * Package            Jena
 * Created            5 Jan 2001
 * Filename           $RCSfile: OneToManyMap.java,v $
 * Revision           $Revision: 1.6 $
 * Release status     Preview-release $State: Exp $
 *
 * Last modified on   $Date: 2004-09-25 18:45:47 $
 *               by   $Author: ian_dickinson $
 *
 * (c) Copyright 2001, 2002, 2003 Hewlett-Packard Development Company, LP
 * See end of file for details
 *****************************************************************************/

// Package
///////////////
package com.hp.hpl.jena.util;


// Imports
///////////////
import java.util.*;



/**
 * An extension to a standard map that supports one-to-many mappings: that is, there
 * may be zero, one or many values corresponding to a given key.
 *
 * @author <NAME>, HP Labs (<a href="mailto:<EMAIL>">email</a>)
 * @version CVS info: $Id: OneToManyMap.java,v 1.6 2004-09-25 18:45:47 ian_dickinson Exp $
 */
public class OneToManyMap
    implements Map
{
    // Constants
    //////////////////////////////////


    // Static variables
    //////////////////////////////////


    // Instance variables
    //////////////////////////////////

    /** Encapsulated hash table stores the values */
    private Map m_table = new HashMap();


    // Constructors
    //////////////////////////////////


    // External signature methods
    //////////////////////////////////

    /**
     * Clear all entries from the map.
     */
    public void clear() {
        m_table.clear();
    }


    /**
     * Answer true if the map contains the given value as a key.
     *
     * @param key The key object to test for
     * @return True or false
     */
    public boolean containsKey( Object key ) {
        return m_table.containsKey( key );
    }


    /**
     * Answer true if the map contains the given object as a value
     * stored against any key. Note that this is quite an expensive
     * operation in the current implementation.
     *
     * @param value The value to test for
     * @return True if the value is in the map
     */
    public boolean containsValue( Object value ) {
        for (Iterator values = m_table.values().iterator();  values.hasNext(); ) {
            Object x = values.next();

            if (x == value) {
                return true;
            }
        }

        return false;
    }


    /**
     * Answer a set of the mappings in this map.  Each member of the set will
     * be a Map.Entry value.
     *
     * @return A Set of the mappings as Map.Entry values.
     */
    public Set entrySet() {
        Set s = HashUtils.createSet();

        for (Iterator e0 = m_table.keySet().iterator();  e0.hasNext(); ) {
            Object key = e0.next();
            List values = (List) m_table.get( key );

            // add each key-value pair to the result set
            for (ListIterator e1 = values.listIterator();  e1.hasNext(); ) {
                s.add( new Entry( key, e1.next() ) );
            }
        }

        return s;
    }


    /**
     * Compares the specified object with this map for equality.
     * Returns true if the given object is also a map and the two Maps
     * represent the same mappings. More formally, two maps t1 and t2 represent
     * the same mappings if t1.entrySet().equals(t2.entrySet()).
     *
     * This ensures that the equals method works properly across different
     * implementations of the Map interface.
     *
     * @param o The object to be compared for equality with this map.
     * @return True if the specified object is equal to this map.
     */
    public boolean equals( Object o ) {
        if (o instanceof java.util.Map) {
            return entrySet().equals( ((Map) o).entrySet() );
        }
        else
            return false;
    }


    /**
     * Get a value for this key.  Since this map is explicitly designed to
     * allow there to be more than one mapping per key, this method will return
     * an undetermined instance of the mapping. If no mapping exists, or the
     * selected value is null, null is returned.
     *
     * @param key The key to access the map.
     * @return One of the values this key corresponds to, or null.
     * @see #getAll
     */
    public Object get( Object key ) {
        ArrayList entry = (ArrayList) m_table.get( key );

        if (entry != null) {
            if (!entry.isEmpty()) {
                return entry.get( 0 );
            }
        }

        // not present
        return null;
    }


    /**
     * Answer an iterator over all of the values for the given key.  An iterator
     * is always supplied, even if the key is not present.
     *
     * @param key The key object
     * @return An iterator over all of the values for this key in the map
     */
    public Iterator getAll( Object key ) {
        ArrayList entry = (ArrayList) m_table.get( key );

        if (entry != null) {
            return entry.iterator();
        }
        else {
            return new ArrayList().iterator();
        }
    }


    /**
     * Returns the hash code value for this map. The hash code of a map is
     * defined to be the sum of the hashCodes of each entry in the map's
     * entrySet view. This ensures that t1.equals(t2) implies
     * that t1.hashCode()==t2.hashCode() for any two maps t1 and t2,
     * as required by the general contract of Object.hashCode
     */
    public int hashCode() {
        int hc = 0;

        for (Iterator i = entrySet().iterator();  i.hasNext(); ) {
            hc += i.next().hashCode();
        }

        return hc;
    }


    /**
     * Answer true if the map is empty of key-value mappings.
     *
     * @return True if there are no entries.
     */
    public boolean isEmpty() {
        return m_table.isEmpty();
    }


    /**
     * Answer a set of the keys in this map
     *
     * @return The keys of the map as a Set
     */
    public Set keySet() {
        return m_table.keySet();
{'fraction_non_alphanumeric': 0.14930555555555555, 'fraction_numerical': 0.010820413436692506, 'mean_word_length': 1.7321861901610414, 'pattern_counts': {'":': 0, '<': 15, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '516426', 'n_tokens_mistral': 3461, 'n_tokens_neox': 3237, 'n_words': 1320}