<commit_before>package polyglot.util;

import java.util.*;
import polyglot.types.*;

/**
 * Class to implement sets containing <code>polyglot.types.Type </code>.  
 * Set membership is based on the subtype relationships.  Thus, if 
 * <code>S</code> is a supertype of <code>A</code> and <code>B</code>, then
 * { <code>S</code> } union { <code>A</code>,<code>B</code> } = 
 * { <code>S</code> }.  Similarily, we remove elements from the set such 
 * that if <code>s</code> is an element of a set <code>S</code>, then a
 * call to remove <code>r</code> removes all <code>s</code> s.t. r is a 
 * a supertype of s.
 */
public class SubtypeSet implements java.util.Set
{
    Vector v; 
    TypeSystem ts;

    /**
     * Creates an empty SubtypeSet
     */
    public SubtypeSet(TypeSystem ts) {
	v = new Vector();
        this.ts = ts;
    }

    /**
     * Creates a copy of the given SubtypeSet
     */
    public SubtypeSet(SubtypeSet s) {
      v = new Vector(s.v);
      ts = s.ts;
    }

    /**
     * Add an element of type <code>polyglot.types.Type</code> to the set
     * only if it has no supertypes already in the set. If we do add it, 
     * remove any subtypes of <code>o</code>
     * 
     * @param o The element to add.
     */
    public boolean add(Object o) {
        if (o == null) {
	    return false;
	}

	if (o instanceof Type) {
	    Type type = (Type) o;

	    if (type.isThrowable()) {
		boolean haveToAdd = true;

		for (Iterator i = v.iterator(); i.hasNext(); ) {
		    Type t = (Type) i.next();

		    if (ts.descendsFrom(t, type)) {
			i.remove();
		    }<commit_msg>Added constructor to SubtypeSet for creating a SubtypeSet based on an existing Collection.<commit_after>package polyglot.util;

import java.util.*;
import polyglot.types.*;

/**
 * Class to implement sets containing <code>polyglot.types.Type </code>.  
 * Set membership is based on the subtype relationships.  Thus, if 
 * <code>S</code> is a supertype of <code>A</code> and <code>B</code>, then
 * { <code>S</code> } union { <code>A</code>,<code>B</code> } = 
 * { <code>S</code> }.  Similarily, we remove elements from the set such 
 * that if <code>s</code> is an element of a set <code>S</code>, then a
 * call to remove <code>r</code> removes all <code>s</code> s.t. r is a 
 * a supertype of s.
 */
public class SubtypeSet implements java.util.Set
{
    Vector v; 
    TypeSystem ts;

    /**
     * Creates an empty SubtypeSet
     */
    public SubtypeSet(TypeSystem ts) {
	v = new Vector();
        this.ts = ts;
    }

    /**
     * Creates a copy of the given SubtypeSet
     */
    public SubtypeSet(SubtypeSet s) {
      v = new Vector(s.v);
      ts = s.ts;
    }

    public SubtypeSet(TypeSystem ts, Collection c) {
      this(ts);
      addAll(c);
    }

    /**
     * Add an element of type <code>polyglot.types.Type</code> to the set
     * only if it has no supertypes already in the set. If we do add it, 
     * remove any subtypes of <code>o</code>
     * 
     * @param o The element to add.
     */
    public boolean add(Object o) {
        if (o == null) {
	    return false;
	}

	if (o instanceof Type) {
	    Type type = (Type) o;

	    if (type.isThrowable()) {
		boolean haveToAdd = true;

		for (Iterator i = v.iterator(); i.hasNext(); ) {
		    Type t = (Type) i.next();

		    if (ts.descendsFrom(t, type)) {
			i.remove();
		    }
{'fraction_non_alphanumeric': 0.13903743315508021, 'fraction_numerical': 0.0, 'mean_word_length': 2.428716904276986, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, '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': '5304599', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1120, 'n_words': 373}