<commit_before>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 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.jaamsim.BasicObjects;

import java.util.ArrayList;

import com.jaamsim.Thresholds.Threshold;
import com.jaamsim.Thresholds.ThresholdUser;
import com.jaamsim.input.Input;
import com.jaamsim.input.Keyword;
import com.jaamsim.input.Output;
import com.jaamsim.units.DimensionlessUnit;
import com.jaamsim.units.RateUnit;
import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.EntityListInput;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation3D.DisplayEntity;

/**
 * LinkedComponents are used to form a chain of components that process DisplayEntities that pass through the system.
 * Sub-classes for EntityGenerator, Server, and EntitySink.
 */
public abstract class LinkedComponent extends DisplayEntity implements ThresholdUser {

	@Keyword(description = "The prototype for entities that will be received by this object.\n" +
			"This input must be set if the expression 'this.obj' is used in the input to any keywords.",
	         example = "Statistics1 TestEntity { Proto }")
	protected final EntityInput<DisplayEntity> testEntity;

	@Keyword(description = "The next object to which the processed DisplayEntity is passed.",
			example = "EntityGenerator1 NextComponent { Server1 }")
	protected final EntityInput<LinkedComponent> nextComponentInput;

	@Keyword(description = "A list of thresholds that must be satisified for the entity to operate.",
			example = "EntityGenerator1 OperatingThresholdList { Server1 }")
	protected final EntityListInput<Threshold> operatingThresholdList;

	private int numberAdded;     // Number of entities added to this component from upstream
	private int numberProcessed; // Number of entities processed by this component
	private DisplayEntity receivedEntity; // Entity most recently received by this component

	{
		testEntity = new EntityInput<DisplayEntity>( DisplayEntity.class, "TestEntity", "Key Inputs", null);
		this.addInput( testEntity);

		nextComponentInput = new EntityInput<LinkedComponent>( LinkedComponent.class, "NextComponent", "Key Inputs", null);
		this.addInput( nextComponentInput);

		operatingThresholdList = new EntityListInput<Threshold>(Threshold.class, "OperatingThresholdList", "Key Inputs", new ArrayList<Threshold>());
		this.addInput( operatingThresholdList);
	}

	@Override
	public void updateForInput(Input<?> in) {
		super.updateForInput(in);

		if (in == testEntity) {
			receivedEntity = testEntity.getValue();
			return;
		}
	}

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

		// Confirm that the next entity in the chain has been specified
		if( ! nextComponentInput.getHidden() &&	nextComponentInput.getValue() == null ) {
			throw new InputErrorException( "The keyword NextComponent must be set." );
		}
	}

	@Override
	public void earlyInit() {
		super.earlyInit();
		numberAdded = 0;
		numberProcessed = 0;
	}

	@Override
	public ArrayList<Threshold> getThresholds() {
		return operatingThresholdList.getValue();
	}

	@Override
	public void thresholdChanged() {}

	public void addDisplayEntity( DisplayEntity ent ) {
		receivedEntity = ent;
		numberAdded++;
	}

	public void sendToNextComponent(DisplayEntity ent) {
		if( nextComponentInput.getValue() != null )
			nextComponentInput.getValue().addDisplayEntity(ent);

		numberProcessed++;
	}

	/**
	 * Tests whether all the thresholds are open.
	 * @return true if all the thresholds are open.
	 */
	public boolean isOpen() {
		for (Threshold thr : operatingThresholdList.getValue()) {
			if (thr.isClosed())
				return false;
		}
		return true;
	}
<commit_msg>JS: Add Javadocs for LinkedComponent<commit_after>/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2013 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.jaamsim.BasicObjects;

import java.util.ArrayList;

import com.jaamsim.Thresholds.Threshold;
import com.jaamsim.Thresholds.ThresholdUser;
import com.jaamsim.input.Input;
import com.jaamsim.input.Keyword;
import com.jaamsim.input.Output;
import com.jaamsim.units.DimensionlessUnit;
import com.jaamsim.units.RateUnit;
import com.sandwell.JavaSimulation.EntityInput;
import com.sandwell.JavaSimulation.EntityListInput;
import com.sandwell.JavaSimulation.InputErrorException;
import com.sandwell.JavaSimulation3D.DisplayEntity;

/**
 * LinkedComponents are used to form a chain of components that process DisplayEntities that pass through the system.
 * Sub-classes for EntityGenerator, Server, and EntitySink.
 */
public abstract class LinkedComponent extends DisplayEntity implements ThresholdUser {

	@Keyword(description = "The prototype for entities that will be received by this object.\n" +
			"This input must be set if the expression 'this.obj' is used in the input to any keywords.",
	         example = "Statistics1 TestEntity { Proto }")
	protected final EntityInput<DisplayEntity> testEntity;

	@Keyword(description = "The next object to which the processed DisplayEntity is passed.",
			example = "EntityGenerator1 NextComponent { Server1 }")
	protected final EntityInput<LinkedComponent> nextComponentInput;

	@Keyword(description = "A list of thresholds that must be satisified for the entity to operate.",
			example = "EntityGenerator1 OperatingThresholdList { Server1 }")
	protected final EntityListInput<Threshold> operatingThresholdList;

	private int numberAdded;     // Number of entities added to this component from upstream
	private int numberProcessed; // Number of entities processed by this component
	private DisplayEntity receivedEntity; // Entity most recently received by this component

	{
		testEntity = new EntityInput<DisplayEntity>( DisplayEntity.class, "TestEntity", "Key Inputs", null);
		this.addInput( testEntity);

		nextComponentInput = new EntityInput<LinkedComponent>( LinkedComponent.class, "NextComponent", "Key Inputs", null);
		this.addInput( nextComponentInput);

		operatingThresholdList = new EntityListInput<Threshold>(Threshold.class, "OperatingThresholdList", "Key Inputs", new ArrayList<Threshold>());
		this.addInput( operatingThresholdList);
	}

	@Override
	public void updateForInput(Input<?> in) {
		super.updateForInput(in);

		if (in == testEntity) {
			receivedEntity = testEntity.getValue();
			return;
		}
	}

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

		// Confirm that the next entity in the chain has been specified
		if( ! nextComponentInput.getHidden() &&	nextComponentInput.getValue() == null ) {
			throw new InputErrorException( "The keyword NextComponent must be set." );
		}
	}

	@Override
	public void earlyInit() {
		super.earlyInit();
		numberAdded = 0;
		numberProcessed = 0;
	}

	@Override
	public ArrayList<Threshold> getThresholds() {
		return operatingThresholdList.getValue();
	}

	@Override
	public void thresholdChanged() {}

	/**
	 * Receives the specified entity from an upstream component.
	 * @param ent - the entity received from upstream.
	 */
	public void addDisplayEntity(DisplayEntity ent ) {
		receivedEntity = ent;
		numberAdded++;
	}

	/**
	 * Sends the specified entity to the next component downstream.
	 * @param ent - the entity to be sent downstream.
	 */
	public void sendToNextComponent(DisplayEntity ent) {
		if( nextComponentInput.getValue() != null )
			nextComponentInput.getValue().addDisplayEntity(ent);

		numberProcessed++;
	}

	/**
	 * Tests whether all the thresholds are open.
	 * @return true if all the thresholds are open.
	 */
	public boolean isOpen() {
		for (Threshold thr : operatingThresholdList.getValue()) {
			if (thr.isClosed())
				return false;
		}
		return true;
	}

{'fraction_non_alphanumeric': 0.0868111597878718, 'fraction_numerical': 0.0029974636845745907, 'mean_word_length': 4.7147562582345195, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2401868', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2286, 'n_words': 821}