src/collections/Set.js
function Set(parameters, comparator) {
    parameters = parameters || new composites.Parameters(new Catalog());
    if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Set/v1');
    abstractions.Collection.call(this, utilities.types.SET, parameters);

    // the comparator and tree are private attributes so methods that use
    // them are defined in the constructor
    comparator = comparator || new utilities.Comparator();
    const tree = new RandomizedTree(comparator);

    this.acceptVisitor = function(visitor) {
        visitor.visitSet(this);
    };

    this.toArray = function() {
        const array = [];
        const iterator = new TreeIterator(tree);
        while (iterator.hasNext()) array.push(iterator.getNext());
        return array;
    };

    this.getComparator = function() {
        return comparator;
    };
    
    this.getSize = function() {
        return tree.size;
    };
    
    this.getIterator = function() {
        return new TreeIterator(tree);
    };
    
    this.getIndex = function(item) {
        item = this.convert(item);
        return tree.index(item) + 1;  // convert to ordinal based indexing
    };
    
    this.getItem = function(index) {
        index = this.normalizeIndex(index) - 1;  // convert to javascript zero based indexing
        return tree.node(index).value;
    };
    
    this.addItem = function(item) {
        item = this.convert(item);
        return tree.insert(item);
    };
    
    this.removeItem = function(item) {
        item = this.convert(item);
        return tree.remove(item);
    };
    
    this.removeItems = function(items) {
        var count = 0;
        const iterator = items.getIterator();
        while (iterator.hasNext()) {
            const item = iterator.getNext();
            if (this.removeItem(item)) {
                count++;
            }
        }
        return count;
    };

    this.deleteAll = function() {
        tree.clear();
    };
    

    return this;
}
function Set(parameters, comparator) {
    parameters = parameters || new composites.Parameters(new Catalog());
    if (!parameters.getParameter('$type')) parameters.setParameter('$type', '/bali/collections/Set/v1');
    abstractions.Collection.call(this, utilities.types.SET, parameters);

    // the comparator and tree are private attributes so methods that use
    // them are defined in the constructor
    comparator = comparator || new utilities.Comparator();
    const tree = new RandomizedTree(comparator);

    this.acceptVisitor = function(visitor) {
        visitor.visitSet(this);
    };

    this.toArray = function() {
        const array = [];
        const iterator = new TreeIterator(tree);
        while (iterator.hasNext()) array.push(iterator.getNext());
        return array;
    };

    this.getComparator = function() {
        return comparator;
    };
    
    this.getSize = function() {
        return tree.size;
    };
    
    this.getIterator = function() {
        return new TreeIterator(tree);
    };
    
    this.getIndex = function(item) {
        item = this.convert(item);
        return tree.index(item) + 1;  // convert to ordinal based indexing
    };
    
    this.getItem = function(index) {
        index = this.normalizeIndex(index) - 1;  // convert to javascript zero based indexing
        return tree.node(index).value;
    };
    
    this.addItem = function(item) {
        item = this.convert(item);
        return tree.insert(item);
    };
    
    this.removeItem = function(item) {
        item = this.convert(item);
        return tree.remove(item);
    };
    
    this.removeItems = function(items) {
        var count = 0;
        const iterator = items.getIterator();
        while (iterator.hasNext()) {
            const item = iterator.getNext();
            if (this.removeItem(item)) {
                count++;
            }
        }
        return count;
    };

    this.deleteAll = function() {
        tree.clear();
    };
    

    return this;
}
function Set ( parameters , comparator ) { parameters = parameters || new composites . Parameters ( new Catalog ( ) ) ; if ( ! parameters . getParameter ( '$type' ) ) parameters . setParameter ( '$type' , '/bali/collections/Set/v1' ) ; abstractions . Collection . call ( this , utilities . types . SET , parameters ) ; // the comparator and tree are private attributes so methods that use // them are defined in the constructor comparator = comparator || new utilities . Comparator ( ) ; const tree = new RandomizedTree ( comparator ) ; this . acceptVisitor = function ( visitor ) { visitor . visitSet ( this ) ; } ; this . toArray = function ( ) { const array = [ ] ; const iterator = new TreeIterator ( tree ) ; while ( iterator . hasNext ( ) ) array . push ( iterator . getNext ( ) ) ; return array ; } ; this . getComparator = function ( ) { return comparator ; } ; this . getSize = function ( ) { return tree . size ; } ; this . getIterator = function ( ) { return new TreeIterator ( tree ) ; } ; this . getIndex = function ( item ) { item = this . convert ( item ) ; return tree . index ( item ) + 1 ; // convert to ordinal based indexing } ; this . getItem = function ( index ) { index = this . normalizeIndex ( index ) - 1 ; // convert to javascript zero based indexing return tree . node ( index ) . value ; } ; this . addItem = function ( item ) { item = this . convert ( item ) ; return tree . insert ( item ) ; } ; this . removeItem = function ( item ) { item = this . convert ( item ) ; return tree . remove ( item ) ; } ; this . removeItems = function ( items ) { var count = 0 ; const iterator = items . getIterator ( ) ; while ( iterator . hasNext ( ) ) { const item = iterator . getNext ( ) ; if ( this . removeItem ( item ) ) { count ++ ; } } return count ; } ; this . deleteAll = function ( ) { tree . clear ( ) ; } ; return this ; }
PUBLIC CONSTRUCTORS 
This constructor creates a new set component with optional parameters that are
used to parameterize its type.

@param {Parameters} parameters Optional parameters used to parameterize this set.
@param {Comparator} comparator An optional comparator.
@returns {Set} The new set.
PUBLIC CONSTRUCTORS This constructor creates a new set component with optional parameters that are used to parameterize its type .