import List from "../../../../../../core/collection/list/List.js";
import { ParameterTrack } from "./ParameterTrack.js";

export class ParameterTrackSet {


    /**
     * @private
     * @type List.<ParameterTrack>
     */
    tracks = new List();

    /**
     *
     * @param {ParameterTrack} track
     */
    add(track) {
        this.tracks.add(track);
    }

    /**
     *
     * @param {function(ParameterTrack)} visitor
     */
    forEach(visitor) {
        this.tracks.forEach(visitor);
    }

    /**
     *
     * @param {string} name
     * @returns {ParameterTrack|undefined}
     */
    getTrackByName(name) {
        const tracks = this.tracks;

        const tracks_array = tracks.asArray();

        const nTracks = tracks_array.length;

        for (let i = 0; i < nTracks; i++) {
            const parameterTrack = tracks_array[i];

            if (parameterTrack.name === name) {
                return parameterTrack;
            }
        }

        return undefined;
    }

    clear() {
        this.tracks.reset();
    }

    fromJSON(json) {
        this.tracks.fromJSON(json, ParameterTrack);
    }

    toJSON() {
        return this.tracks.toJSON();
    }

    /**
     *
     * @param {BinaryBuffer} buffer
     */
    toBinaryBuffer(buffer) {
        this.tracks.toBinaryBuffer(buffer);
    }

    /**
     *
     * @param {BinaryBuffer} buffer
     */
    fromBinaryBuffer(buffer) {
        this.tracks.fromBinaryBuffer(buffer, ParameterTrack);
    }

    hash() {
        return this.tracks.hash();
    }

    /**
     *
     * @param {ParameterTrackSet} other
     * @returns {boolean}
     */
    equals(other) {
        return this.tracks.equals(other.tracks);
    }
}

