<commit_before>/*******************************************************************************
 * Copyright (c) 2013 CWI
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *
 *   * <NAME> - <EMAIL> - CWI
 *   * <NAME> - <EMAIL> - CWI
 *   * <NAME> - <EMAIL> - CWI
 *
 * Based on code by:
 *
 *   * <NAME> (<EMAIL>) - initial API and implementation
 *******************************************************************************/
package io.usethesource.vallang.impl.reference;

import java.util.HashSet;
import java.util.Iterator;

import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.exceptions.FactTypeUseException;
import io.usethesource.vallang.type.Type;
import io.usethesource.vallang.type.TypeFactory;

/*package*/ class SetWriter implements ISetWriter {
    protected final HashSet<IValue> setContent;
    protected Type eltType;
    protected Set constructedSet;

    /*package*/ SetWriter() {
        super();
        this.eltType = TypeFactory.getInstance().voidType();
        setContent = new HashSet<>();
    }

    @Override
    public Iterator<IValue> iterator() {
        return setContent.iterator();
    }
    
    private void put(IValue elem) {
        updateType(elem);
        setContent.add(elem);
    }

    private void updateType(IValue elem) {
        eltType = eltType.lub(elem.getType());
    }

    @Override
    public void insertTuple(IValue... fields) {
        insert(ValueFactory.getInstance().tuple(fields));
    }
    
    @Override
	public void insert(IValue... elems) throws FactTypeUseException {
        checkMutation();

        for (IValue elem : elems) {
            put(elem);
        }
    }

    @Override
	public void insertAll(Iterable<? extends IValue> collection) throws FactTypeUseException {
        checkMutation();

        for (IValue v : collection) {
            put(v);
        }
    }

    @Override
	public ISet done() {
        if (constructedSet == null) {
            constructedSet = new Set(ISet.TF.setType(eltType), setContent);
        }

        return constructedSet;
    }

    private void checkMutation() {
        if (constructedSet != null)
            throw new UnsupportedOperationException("Mutation of a finalized set is not supported.");
    }
}<commit_msg>fixed reference set writer type<commit_after>/*******************************************************************************
 * Copyright (c) 2013 CWI
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *
 *   * <NAME> - <EMAIL> - CWI
 *   * <NAME> - <EMAIL> - CWI
 *   * <NAME> - <EMAIL> - CWI
 *
 * Based on code by:
 *
 *   * <NAME> (<EMAIL>) - initial API and implementation
 *******************************************************************************/
package io.usethesource.vallang.impl.reference;

import java.util.HashSet;
import java.util.Iterator;

import io.usethesource.vallang.ISet;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.exceptions.FactTypeUseException;
import io.usethesource.vallang.type.Type;
import io.usethesource.vallang.type.TypeFactory;

/*package*/ class SetWriter implements ISetWriter {
    protected final HashSet<IValue> setContent;
    protected Type eltType;
    protected Set constructedSet;

    /*package*/ SetWriter() {
        super();
        this.eltType = TypeFactory.getInstance().voidType();
        setContent = new HashSet<>();
    }

    @Override
    public Iterator<IValue> iterator() {
        return setContent.iterator();
    }
    
    private void put(IValue elem) {
        updateType(elem);
        setContent.add(elem);
    }

    private void updateType(IValue elem) {
        eltType = eltType.lub(elem.getType());
    }

    @Override
    public void insertTuple(IValue... fields) {
        insert(ValueFactory.getInstance().tuple(fields));
    }
    
    @Override
	public void insert(IValue... elems) throws FactTypeUseException {
        checkMutation();

        for (IValue elem : elems) {
            put(elem);
        }
    }

    @Override
	public void insertAll(Iterable<? extends IValue> collection) throws FactTypeUseException {
        checkMutation();

        for (IValue v : collection) {
            put(v);
        }
    }

    @Override
	public ISet done() {
        if (constructedSet == null) {
            constructedSet = new Set(eltType, setContent);
        }

        return constructedSet;
    }

    private void checkMutation() {
        if (constructedSet != null)
            throw new UnsupportedOperationException("Mutation of a finalized set is not supported.");
    }
}
{'fraction_non_alphanumeric': 0.16448012531819073, 'fraction_numerical': 0.0031329547679655374, 'mean_word_length': 2.9750972762645915, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1373434', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1423, 'n_words': 358}