<commit_before>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2003-2011 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.sandwell.JavaSimulation3D;

import java.util.ArrayList;

import com.jaamsim.input.ValueInput;
import com.jaamsim.math.Vec3d;
import com.jaamsim.units.DistanceUnit;
import com.sandwell.JavaSimulation.Entity;
import com.sandwell.JavaSimulation.ErrorException;
import com.sandwell.JavaSimulation.FileEntity;
import com.sandwell.JavaSimulation.IntegerInput;
import com.sandwell.JavaSimulation.Keyword;

public class Queue extends DisplayEntity {

	@Keyword(description = "The amount of graphical space shown between DisplayEntity objects in the queue.",
	         example = "Queue-1 Spacing { 1 }")
	private final ValueInput spacingInput;

	@Keyword(description = "The number of queuing entities in each row.",
			example = "Queue-1 MaxPerLine { 4 }")
	protected final IntegerInput maxPerLineInput; // maximum items per sub line-up of queue

	protected ArrayList<DisplayEntity> itemList;

//	Statistics
	protected double minElements;
	protected int maxElements;
	protected double avgElements;
	protected ArrayList<QueueRecorder> recorderList;

	{
		spacingInput = new ValueInput("Spacing", "Key Inputs", 0.0d);
		spacingInput.setUnitType(DistanceUnit.class);
		spacingInput.setValidRange(0.0d, Double.POSITIVE_INFINITY);
		this.addInput(spacingInput, true);

		maxPerLineInput = new IntegerInput("MaxPerLine", "Key Inputs", Integer.MAX_VALUE);
		maxPerLineInput.setValidRange( 1, Integer.MAX_VALUE);
		this.addInput(maxPerLineInput, true);
	}

	public Queue() {
		itemList = new ArrayList<DisplayEntity>();
	}

	@Override
	public void earlyInit() {
		super.earlyInit();

		// Clear the entries in the queue
		itemList.clear();

		// Clear statistics
		this.clearStatistics();

		recorderList = new ArrayList<QueueRecorder>();
		for( QueueRecorder rec : Entity.getClonesOf( QueueRecorder.class ) ) {
			if( rec.getQueueList().contains( this ) ) {
				recorderList.add( rec );
			}
		}
	}

	// ******************************************************************************************************
	// QUEUE HANDLING METHODS
	// ******************************************************************************************************

	/**
	 * Inserts the specified element at the specified position in this Queue.
	 * Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
	 */
	public void add( int i, DisplayEntity perf ) {
		itemList.add( i, perf );
		setGraphicsDataDirty();

		for( QueueRecorder rec : recorderList ) {
			rec.add( perf, this );
		}
	}

	/**
	 * Add an entity to the end of the queue
	 */
	public void addLast( DisplayEntity perf ) {
		this.add(itemList.size(), perf);
	}

	/**
	 * Removes the entity at the specified position in the queue
	 */
	public DisplayEntity remove(int i) {
		if( i < itemList.size() && i >= 0 ) {
			DisplayEntity out = itemList.remove(i);
			setGraphicsDataDirty();

			for( QueueRecorder rec : recorderList ) {
				rec.remove( out, this );<commit_msg>JS: Collect statistics in the "add" and "remove" methods for Queue<commit_after>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2003-2011 Ausenco Engineering Canada Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
package com.sandwell.JavaSimulation3D;

import java.util.ArrayList;

import com.jaamsim.input.ValueInput;
import com.jaamsim.math.Vec3d;
import com.jaamsim.units.DistanceUnit;
import com.sandwell.JavaSimulation.Entity;
import com.sandwell.JavaSimulation.ErrorException;
import com.sandwell.JavaSimulation.FileEntity;
import com.sandwell.JavaSimulation.IntegerInput;
import com.sandwell.JavaSimulation.Keyword;

public class Queue extends DisplayEntity {

	@Keyword(description = "The amount of graphical space shown between DisplayEntity objects in the queue.",
	         example = "Queue-1 Spacing { 1 }")
	private final ValueInput spacingInput;

	@Keyword(description = "The number of queuing entities in each row.",
			example = "Queue-1 MaxPerLine { 4 }")
	protected final IntegerInput maxPerLineInput; // maximum items per sub line-up of queue

	protected ArrayList<DisplayEntity> itemList;

//	Statistics
	protected double minElements;
	protected int maxElements;
	protected double avgElements;
	protected ArrayList<QueueRecorder> recorderList;

	{
		spacingInput = new ValueInput("Spacing", "Key Inputs", 0.0d);
		spacingInput.setUnitType(DistanceUnit.class);
		spacingInput.setValidRange(0.0d, Double.POSITIVE_INFINITY);
		this.addInput(spacingInput, true);

		maxPerLineInput = new IntegerInput("MaxPerLine", "Key Inputs", Integer.MAX_VALUE);
		maxPerLineInput.setValidRange( 1, Integer.MAX_VALUE);
		this.addInput(maxPerLineInput, true);
	}

	public Queue() {
		itemList = new ArrayList<DisplayEntity>();
	}

	@Override
	public void earlyInit() {
		super.earlyInit();

		// Clear the entries in the queue
		itemList.clear();

		// Clear statistics
		this.clearStatistics();

		recorderList = new ArrayList<QueueRecorder>();
		for( QueueRecorder rec : Entity.getClonesOf( QueueRecorder.class ) ) {
			if( rec.getQueueList().contains( this ) ) {
				recorderList.add( rec );
			}
		}
	}

	// ******************************************************************************************************
	// QUEUE HANDLING METHODS
	// ******************************************************************************************************

	/**
	 * Inserts the specified element at the specified position in this Queue.
	 * Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
	 */
	public void add( int i, DisplayEntity perf ) {
		this.updateStatistics();
		itemList.add( i, perf );
		this.updateStatistics();
		setGraphicsDataDirty();

		for( QueueRecorder rec : recorderList ) {
			rec.add( perf, this );
		}
	}

	/**
	 * Add an entity to the end of the queue
	 */
	public void addLast( DisplayEntity perf ) {
		this.add(itemList.size(), perf);
	}

	/**
	 * Removes the entity at the specified position in the queue
	 */
	public DisplayEntity remove(int i) {
		if( i < itemList.size() && i >= 0 ) {
			this.updateStatistics();
			DisplayEntity out = itemList.remove(i);
			this.updateStatistics();
			setGraphicsDataDirty();

			for( QueueRecorder rec : recorderList ) {
				rec.remove( out, this );
{'fraction_non_alphanumeric': 0.146974847042828, 'fraction_numerical': 0.005710401087695445, 'mean_word_length': 4.444855662472243, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2556086', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2028, 'n_words': 676}